Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
#18282 Improve pol(expr) for expr in SR
Browse files Browse the repository at this point in the history
In particular, it should not return an expression in Horner form.
  • Loading branch information
mezzarobba committed May 30, 2015
1 parent 5ffd321 commit 4a519fd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/sage/calculus/calculus.py
Expand Up @@ -889,7 +889,7 @@ def minpoly(ex, var='x', algorithm=None, bits=None, degree=None, epsilon=0):
sage: f = a.minpoly(); f
x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576
sage: f(a)
((((sqrt(5) + sqrt(3) + sqrt(2))^2 - 40)*(sqrt(5) + sqrt(3) + sqrt(2))^2 + 352)*(sqrt(5) + sqrt(3) + sqrt(2))^2 - 960)*(sqrt(5) + sqrt(3) + sqrt(2))^2 + 576
(sqrt(5) + sqrt(3) + sqrt(2))^8 - 40*(sqrt(5) + sqrt(3) + sqrt(2))^6 + 352*(sqrt(5) + sqrt(3) + sqrt(2))^4 - 960*(sqrt(5) + sqrt(3) + sqrt(2))^2 + 576
sage: f(a).expand()
0
Expand All @@ -906,7 +906,7 @@ def minpoly(ex, var='x', algorithm=None, bits=None, degree=None, epsilon=0):
NotImplementedError: Could not prove minimal polynomial x^4 - 5/4*x^2 + 5/16 (epsilon 0.00000000000000e-1)
sage: f = a.minpoly(algorithm='numerical', epsilon=1e-100); f
x^4 - 5/4*x^2 + 5/16
sage: f(a).numerical_approx(100)
sage: f(a).horner(a).numerical_approx(100)
0.00000000000000000000000000000
The degree must be high enough (default tops out at 24).
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/orthogonal_polys.py
Expand Up @@ -1225,7 +1225,7 @@ def gen_legendre_P(n,m,x):
sage: gen_legendre_P(3, 1, t)
-3/2*(5*t^2 - 1)*sqrt(-t^2 + 1)
sage: gen_legendre_P(4, 3, t)
105*(t^2 - 1)*sqrt(-t^2 + 1)*t
105*(t^3 - t)*sqrt(-t^2 + 1)
sage: gen_legendre_P(7, 3, I).expand()
-16695*sqrt(2)
sage: gen_legendre_P(4, 1, 2.5)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/number_field/number_field_element.pyx
Expand Up @@ -2293,7 +2293,7 @@ cdef class NumberFieldElement(FieldElement):
sage: SR(b.minpoly()).solve(SR('x'), explicit_solutions=True)
[]
sage: SR(b)
1/8*((sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5)^2 + 4)*(sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5)
1/8*(sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5)^3 + 1/2*sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5/2
"""
K = self._parent.fraction_field()
Expand Down
11 changes: 10 additions & 1 deletion src/sage/rings/polynomial/polynomial_element.pyx
Expand Up @@ -715,6 +715,15 @@ cdef class Polynomial(CommutativeAlgebraElement):
return self.reverse()(a_inverse) / a_inverse**self.degree()
except AttributeError:
pass
from sage.symbolic.ring import SR
if parent(a) is SR:
if len(x) == 1:
try:
return SR(self(a.pyobject()))
except TypeError:
return SR.zero().add(*(self[i]*a**i for i in xrange(d + 1)))
else:
return SR.zero().add(*(self[i](other_args)*a**i for i in xrange(d + 1)))

i = d - 1
if len(x) > 1:
Expand Down Expand Up @@ -1072,7 +1081,7 @@ cdef class Polynomial(CommutativeAlgebraElement):
sage: R.<x> = QQ[]
sage: f = x^3 + x
sage: g = f._symbolic_(SR); g
(x^2 + 1)*x
x^3 + x
sage: g(x=2)
10
Expand Down
2 changes: 1 addition & 1 deletion src/sage/rings/polynomial/polynomial_zz_pex.pyx
Expand Up @@ -251,7 +251,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template):
sage: P.<y> = F[]
sage: p = y^4 + x*y^3 + y^2 + (x + 1)*y + x + 1
sage: SR(p) #indirect doctest
(((y + x)*y + 1)*y + x + 1)*y + x + 1
y^4 + x*y^3 + y^2 + (x + 1)*y + x + 1
sage: p(2)
x + 1
sage: p(y=2)
Expand Down

0 comments on commit 4a519fd

Please sign in to comment.