# Ticket #9880: trac_9880-fix_doctests-be.rebased-5.5.rc0.patch

File trac_9880-fix_doctests-be.rebased-5.5.rc0.patch, 54.4 KB (added by burcin, 8 years ago)
• ## sage/calculus/calculus.py

# HG changeset patch
# User Burcin Erocal <burcin@erocal.org>
# Date 1322237282 -3600
# Node ID f74c5d35564ec5cacafd9f1dfc1309218cd64c34
# Parent  a2c98344304083277ed8b550baf9a74988f3fbdb
[mq]: trac_9880-fix_doctests-be.patch

diff --git a/sage/calculus/calculus.py b/sage/calculus/calculus.py
 a [   (r, theta) |--> cos(theta) (r, theta) |--> -r*sin(theta)] [   (r, theta) |--> sin(theta)  (r, theta) |--> r*cos(theta)] sage: T.diff().det() # Jacobian (r, theta) |--> r*sin(theta)^2 + r*cos(theta)^2 (r, theta) |--> r*cos(theta)^2 + r*sin(theta)^2 When the order of variables is ambiguous, Sage will raise an exception when differentiating:: :: sage: f(x,y) = log(x)*cos(y); f (x, y) |--> log(x)*cos(y) (x, y) |--> cos(y)*log(x) Then we have fixed an order of variables and there is no ambiguity substituting or evaluating:: sage: ComplexField(200)(sin(I)) 1.1752011936438014568823818505956008151557179813340958702296*I sage: f = sin(I) + cos(I/2); f sin(I) + cos(1/2*I) cos(1/2*I) + sin(I) sage: CC(f) 1.12762596520638 + 1.17520119364380*I sage: ComplexField(200)(f) Check that the problem with Taylor expansions of the gamma function (Trac #9217) is fixed:: sage: taylor(gamma(1/3+x),x,0,3)      # random output - remove this in trac #9880 sage: taylor(gamma(1/3+x),x,0,3) -1/432*((36*(pi*sqrt(3) + 9*log(3))*euler_gamma^2 + 27*pi^2*log(3) + 72*euler_gamma^3 + 243*log(3)^3 + 18*(6*pi*sqrt(3)*log(3) + pi^2 + 27*log(3)^2 + 12*psi(1, 1/3))*euler_gamma + 324*psi(1, 1/3)*log(3) + (pi^3 + 9*(9*log(3)^2 + 4*psi(1, 1/3))*pi)*sqrt(3))*gamma(1/3) - 72*gamma(1/3)*psi(2, 1/3))*x^3 + 1/24*(6*pi*sqrt(3)*log(3) + 4*(pi*sqrt(3) + 9*log(3))*euler_gamma + pi^2 + 12*euler_gamma^2 + 27*log(3)^2 + 12*psi(1, 1/3))*x^2*gamma(1/3) - 1/6*(6*euler_gamma + pi*sqrt(3) + 9*log(3))*x*gamma(1/3) + gamma(1/3) sage: map(lambda f:f[0].n(), _.coeffs())  # numerical coefficients to make comparison easier; Maple 12 gives same answer [2.6789385347..., -8.3905259853..., 26.662447494..., -80.683148377...] sage: k = var("k") sage: sum(1/(1+k^2), k, -oo, oo) -1/2*I*psi(I + 1) - 1/2*I*psi(I) + 1/2*I*psi(-I) + 1/2*I*psi(-I + 1) -1/2*I*psi(I + 1) + 1/2*I*psi(-I + 1) - 1/2*I*psi(I) + 1/2*I*psi(-I) Ensure that ticket #8624 is fixed:: :: sage: symbolic_sum(k * binomial(n, k), k, 1, n) n*2^(n - 1) 2^(n - 1)*n :: Trac #8459 fixed:: sage: maxima('3*li[2](u)+8*li[33](exp(u))').sage() 3*polylog(2, u) + 8*polylog(33, e^u) 8*polylog(33, e^u) + 3*polylog(2, u) Check if #8345 is fixed::
• ## sage/calculus/desolvers.py

diff --git a/sage/calculus/desolvers.py b/sage/calculus/desolvers.py
 a sage: y = function('y', x) sage: de = diff(y,x,2) - y == x sage: desolve(de, y) k1*e^x + k2*e^(-x) - x k2*e^(-x) + k1*e^x - x :: sage: f = desolve(de, y, [10,2,1]); f -x + 5*e^(-x + 10) + 7*e^(x - 10) -x + 7*e^(x - 10) + 5*e^(-x + 10) :: sage: de = diff(y,x,2) + y == 0 sage: desolve(de, y) k1*sin(x) + k2*cos(x) k2*cos(x) + k1*sin(x) :: sage: desolve(de, y, [0,1,pi/2,4]) 4*sin(x) + cos(x) cos(x) + 4*sin(x) :: :: sage: desolve(diff(y,x)*sin(y) == cos(x),y,[pi/2,1]) -cos(y(x)) == sin(x) - cos(1) - 1 -cos(y(x)) == -cos(1) + sin(x) - 1 Linear equation - Sage returns the expression on the right hand side only:: sage: desolve(diff(y,x)+(y) == cos(x),y) 1/2*((sin(x) + cos(x))*e^x + 2*c)*e^(-x) 1/2*((cos(x) + sin(x))*e^x + 2*c)*e^(-x) :: sage: desolve(diff(y,x)+(y) == cos(x),y,show_method=True) [1/2*((sin(x) + cos(x))*e^x + 2*c)*e^(-x), 'linear'] [1/2*((cos(x) + sin(x))*e^x + 2*c)*e^(-x), 'linear'] :: sage: desolve(diff(y,x)+(y) == cos(x),y,[0,1]) 1/2*(e^x*sin(x) + e^x*cos(x) + 1)*e^(-x) 1/2*(cos(x)*e^x + e^x*sin(x) + 1)*e^(-x) This ODE with separated variables is solved as exact. Explanation - factor does not split e^{x-y} in Maxima :: sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2]) 3*((e^(1/2*pi) - 2)*x/pi + 1)*e^(-x) + 1/2*sin(x) 3*(x*(e^(1/2*pi) - 2)/pi + 1)*e^(-x) + 1/2*sin(x) :: sage: desolve(diff(y,x,2)+2*diff(y,x)+y == cos(x),y,[0,3,pi/2,2],show_method=True) [3*((e^(1/2*pi) - 2)*x/pi + 1)*e^(-x) + 1/2*sin(x), 'variationofparameters'] [3*(x*(e^(1/2*pi) - 2)/pi + 1)*e^(-x) + 1/2*sin(x), 'variationofparameters'] :: :: sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2]) (2*(2*e^(1/2*pi) - 3)*x/pi + 3)*e^(-x) (2*x*(2*e^(1/2*pi) - 3)/pi + 3)*e^(-x) :: sage: desolve(diff(y,x,2)+2*diff(y,x)+y == 0,y,[0,3,pi/2,2],show_method=True) [(2*(2*e^(1/2*pi) - 3)*x/pi + 3)*e^(-x), 'constcoeff'] [(2*x*(2*e^(1/2*pi) - 3)/pi + 3)*e^(-x), 'constcoeff'] TESTS: sage: de2 = diff(y,t) - x + 1 == 0 sage: desolve_system([de1, de2], [x,y]) [x(t) == (x(0) - 1)*cos(t) - (y(0) - 1)*sin(t) + 1, y(t) == (x(0) - 1)*sin(t) + (y(0) - 1)*cos(t) + 1] y(t) == (y(0) - 1)*cos(t) + (x(0) - 1)*sin(t) + 1] Now we give some initial conditions::
• ## sage/calculus/functional.py

diff --git a/sage/calculus/functional.py b/sage/calculus/functional.py
 a (a, x) sage: f = exp(sin(a - x^2))/x sage: derivative(f, x) -2*e^(sin(-x^2 + a))*cos(-x^2 + a) - e^(sin(-x^2 + a))/x^2 -2*cos(-x^2 + a)*e^(sin(-x^2 + a)) - e^(sin(-x^2 + a))/x^2 sage: derivative(f, a) e^(sin(-x^2 + a))*cos(-x^2 + a)/x cos(-x^2 + a)*e^(sin(-x^2 + a))/x Syntax for repeated differentiation:: :: sage: integral(x/(x^3-1), x) 1/3*sqrt(3)*arctan(1/3*(2*x + 1)*sqrt(3)) + 1/3*log(x - 1) - 1/6*log(x^2 + x + 1) 1/3*sqrt(3)*arctan(1/3*sqrt(3)*(2*x + 1)) - 1/6*log(x^2 + x + 1) + 1/3*log(x - 1) :: Note, however, that:: sage: integral( exp(-x^2)*ln(x), x, 0, oo) -1/4*(euler_gamma + 2*log(2))*sqrt(pi) -1/4*sqrt(pi)*(euler_gamma + 2*log(2)) This definite integral is easy:: Taylor polynomial in two variables:: sage: x,y=var('x y'); taylor(x*y^3,(x,1),(y,-1),4) (y + 1)^3*(x - 1) + (y + 1)^3 - 3*(y + 1)^2*(x - 1) - 3*(y + 1)^2 + 3*(y + 1)*(x - 1) - x + 3*y + 3 (x - 1)*(y + 1)^3 - 3*(x - 1)*(y + 1)^2 + (y + 1)^3 + 3*(x - 1)*(y + 1) - 3*(y + 1)^2 - x + 3*y + 3 """ if not isinstance(f, Expression): f = SR(f) EXAMPLES:: sage: a = (x-1)*(x^2 - 1); a (x - 1)*(x^2 - 1) (x^2 - 1)*(x - 1) sage: expand(a) x^3 - x^2 - x + 1
• ## sage/calculus/functions.py

diff --git a/sage/calculus/functions.py b/sage/calculus/functions.py
 a Two-by-two Wronskian of sin(x) and e^x:: sage: wronskian(sin(x), e^x, x) e^x*sin(x) - e^x*cos(x) -cos(x)*e^x + e^x*sin(x) Or don't put x last:: sage: wronskian(x, sin(x), e^x) (e^x*sin(x) + e^x*cos(x))*x - 2*e^x*sin(x) (cos(x)*e^x + e^x*sin(x))*x - 2*e^x*sin(x) Example where one of the functions is constant::
• ## sage/calculus/test_sympy.py

diff --git a/sage/calculus/test_sympy.py b/sage/calculus/test_sympy.py
 a sage: type(e) sage: e sin(y) + cos(x) cos(x) + sin(y) sage: e = sage.all.cos(var("y")**3)**4+var("x")**2 sage: e = e._sympy_() sage: e
• ## sage/calculus/tests.py

diff --git a/sage/calculus/tests.py b/sage/calculus/tests.py
 a :: sage: christoffel(3,3,2, [t,r,theta,phi], m) -sin(theta)*cos(theta) -cos(theta)*sin(theta) sage: X = christoffel(1,1,1,[t,r,theta,phi],m) sage: X 1/2/((1/r - 1)*r^2) 1/2/(r^2*(1/r - 1)) sage: X.rational_simplify() -1/2/(r^2 - r) sage: g(x) = cos(x) + x^3 sage: u = f(x+t) + g(x-t) sage: u -(t - x)^3 + sin((t + x)^2) + cos(-t + x) -(t - x)^3 + cos(-t + x) + sin((t + x)^2) sage: u.diff(t,2) - u.diff(x,2) 0 sage: derivative(arctan(x), x) 1/(x^2 + 1) sage: derivative(x^n, x, 3) (n - 2)*(n - 1)*n*x^(n - 3) (n - 1)*(n - 2)*n*x^(n - 3) sage: derivative( function('f')(x), x) D[0](f)(x) sage: diff( 2*x*f(x^2), x) 4*x^2*D[0](f)(x^2) + 2*f(x^2) sage: integrate( 1/(x^4 - a^4), x) 1/4*log(-a + x)/a^3 - 1/4*log(a + x)/a^3 - 1/2*arctan(x/a)/a^3 -1/2*arctan(x/a)/a^3 - 1/4*log(a + x)/a^3 + 1/4*log(-a + x)/a^3 sage: expand(integrate(log(1-x^2), x)) x*log(-x^2 + 1) - 2*x - log(x - 1) + log(x + 1) x*log(-x^2 + 1) - 2*x + log(x + 1) - log(x - 1) sage: integrate(log(1-x^2)/x, x) 1/2*log(-x^2 + 1)*log(x^2) + 1/2*polylog(2, -x^2 + 1) 1/2*log(x^2)*log(-x^2 + 1) + 1/2*polylog(2, -x^2 + 1) sage: integrate(exp(1-x^2),x) 1/2*sqrt(pi)*e*erf(x) 1/2*sqrt(pi)*erf(x)*e sage: integrate(sin(x^2),x) 1/8*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x))*sqrt(pi) 1/8*sqrt(pi)*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x)) sage: integrate((1-x^2)^n,x) integrate((-x^2 + 1)^n, x) sage: integrate(x^x,x) integrate(x^x, x) sage: integrate(1/(x^3+1),x) 1/3*sqrt(3)*arctan(1/3*(2*x - 1)*sqrt(3)) + 1/3*log(x + 1) - 1/6*log(x^2 - x + 1) 1/3*sqrt(3)*arctan(1/3*sqrt(3)*(2*x - 1)) - 1/6*log(x^2 - x + 1) + 1/3*log(x + 1) sage: integrate(1/(x^3+1), x, 0, 1) 1/9*pi*sqrt(3) + 1/3*log(2) 1/9*sqrt(3)*pi + 1/3*log(2) :: sage: diff(sin(x), x, 3) -cos(x) sage: diff(x*sin(cos(x)), x) -x*sin(x)*cos(cos(x)) + sin(cos(x)) -x*cos(cos(x))*sin(x) + sin(cos(x)) sage: diff(tan(x), x) tan(x)^2 + 1 sage: f = function('f'); f :: sage: integrate( x/(x^3-1), x) 1/3*sqrt(3)*arctan(1/3*(2*x + 1)*sqrt(3)) + 1/3*log(x - 1) - 1/6*log(x^2 + x + 1) 1/3*sqrt(3)*arctan(1/3*sqrt(3)*(2*x + 1)) - 1/6*log(x^2 + x + 1) + 1/3*log(x - 1) sage: integrate(exp(-x^2), x) 1/2*sqrt(pi)*erf(x) sage: integrate(exp(-x^2)*log(x), x)       # todo: maple can compute this exactly. sage: function('f, g') (f, g) sage: diff(f(t)*g(t),t) f(t)*D[0](g)(t) + g(t)*D[0](f)(t) g(t)*D[0](f)(t) + f(t)*D[0](g)(t) sage: diff(f(t)/g(t), t) -f(t)*D[0](g)(t)/g(t)^2 + D[0](f)(t)/g(t) D[0](f)(t)/g(t) - f(t)*D[0](g)(t)/g(t)^2 sage: diff(f(t) + g(t), t) D[0](f)(t) + D[0](g)(t) sage: diff(c*f(t), t)
• ## sage/calculus/var.pyx

diff --git a/sage/calculus/var.pyx b/sage/calculus/var.pyx
 a method to replace functions:: sage: k.substitute_function(supersin, sin) 2*sin(x)*cos(x) 2*cos(x)*sin(x) """ if len(args) > 0: return function(s, **kwds)(*args) ... NameError: name 'x' is not defined sage: expand((e + i)^2) 2*I*e + e^2 - 1 e^2 + 2*I*e - 1 sage: k 15 """
• ## sage/calculus/wester.py

diff --git a/sage/calculus/wester.py b/sage/calculus/wester.py
 a sage: # (YES) Evaluate  e^(Pi*Sqrt(163)) to 50 decimal digits sage: a = e^(pi*sqrt(163)); a e^(pi*sqrt(163)) e^(sqrt(163)*pi) sage: print RealField(150)(a) 2.6253741264076874399999999999925007259719820e17 sage: # (YES) Factorize x^100-1. sage: factor(x^100-1) (x - 1)*(x + 1)*(x^2 + 1)*(x^4 - x^3 + x^2 - x + 1)*(x^4 + x^3 + x^2 + x + 1)*(x^8 - x^6 + x^4 - x^2 + 1)*(x^20 - x^15 + x^10 - x^5 + 1)*(x^20 + x^15 + x^10 + x^5 + 1)*(x^40 - x^30 + x^20 - x^10 + 1) (x^40 - x^30 + x^20 - x^10 + 1)*(x^20 + x^15 + x^10 + x^5 + 1)*(x^20 - x^15 + x^10 - x^5 + 1)*(x^8 - x^6 + x^4 - x^2 + 1)*(x^4 + x^3 + x^2 + x + 1)*(x^4 - x^3 + x^2 - x + 1)*(x^2 + 1)*(x + 1)*(x - 1) sage: # Also, algebraically sage: x = polygen(QQ) sage: factor(x^100 - 1) sage: f = (x^2+2*x+3)/(x^3+4*x^2+5*x+2); f (x^2 + 2*x + 3)/(x^3 + 4*x^2 + 5*x + 2) sage: f.partial_fraction() -2/(x + 1) + 2/(x + 1)^2 + 3/(x + 2) 3/(x + 2) - 2/(x + 1) + 2/(x + 1)^2 :: sage: eqn = prod(x-i for i in range(1,5 +1)) < 0 sage: # but don't know how to solve sage: eqn (x - 5)*(x - 4)*(x - 3)*(x - 2)*(x - 1) < 0 (x - 1)*(x - 2)*(x - 3)*(x - 4)*(x - 5) < 0 :: sage: # (YES) (2^(1/3) + 4^(1/3))^3 - 6*(2^(1/3) + 4^(1/3))-6 = 0 sage: a = (2^(1/3) + 4^(1/3))^3 - 6*(2^(1/3) + 4^(1/3)) - 6; a (2^(1/3) + 4^(1/3))^3 - 6*2^(1/3) - 6*4^(1/3) - 6 (4^(1/3) + 2^(1/3))^3 - 6*4^(1/3) - 6*2^(1/3) - 6 sage: bool(a==0) True sage: abs(float(a)) < 1e-10 sage: assume(r>0) sage: f = (4*r+4*sqrt(r)+1)^(sqrt(r)/(2*sqrt(r)+1))*(2*sqrt(r)+1)^(2*sqrt(r)+1)^(-1)-2*sqrt(r)-1 sage: f (2*sqrt(r) + 1)^(1/(2*sqrt(r) + 1))*(4*r + 4*sqrt(r) + 1)^(sqrt(r)/(2*sqrt(r) + 1)) - 2*sqrt(r) - 1 (4*r + 4*sqrt(r) + 1)^(sqrt(r)/(2*sqrt(r) + 1))*(2*sqrt(r) + 1)^(1/(2*sqrt(r) + 1)) - 2*sqrt(r) - 1 sage: bool(f == 0) False sage: [abs(float(f(r=i))) < 1e-10 for i in [0.1,0.3,0.5]] sage: a = tan(z); a tan(z) sage: a.real() tan(real_part(z))/(tan(real_part(z))^2*tan(imag_part(z))^2 + 1) tan(real_part(z))/(tan(imag_part(z))^2*tan(real_part(z))^2 + 1) sage: a.imag() tanh(imag_part(z))/(tan(real_part(z))^2*tan(imag_part(z))^2 + 1) tanh(imag_part(z))/(tan(imag_part(z))^2*tan(real_part(z))^2 + 1) :: [  1   d d^2 d^3] sage: d = m.determinant() sage: d.factor() (c - d)*(b - d)*(b - c)*(a - d)*(a - c)*(a - b) (a - b)*(a - c)*(a - d)*(b - c)*(b - d)*(c - d) :: sage: # (YES) Taylor expansion of Ln(x)^a*Exp(-b*x) at x=1. sage: a,b = var('a,b') sage: taylor(log(x)^a*exp(-b*x), x, 1, 3) -1/48*(x - 1)^3*((6*b + 5)*(x - 1)^a*a^2 + (x - 1)^a*a^3 + 8*(x - 1)^a*b^3 + 2*(6*b^2 + 5*b + 3)*(x - 1)^a*a)*e^(-b) + 1/24*(x - 1)^2*((12*b + 5)*(x - 1)^a*a + 3*(x - 1)^a*a^2 + 12*(x - 1)^a*b^2)*e^(-b) - 1/2*(x - 1)*((x - 1)^a*a + 2*(x - 1)^a*b)*e^(-b) + (x - 1)^a*e^(-b) -1/48*(a^3*(x - 1)^a + a^2*(6*b + 5)*(x - 1)^a + 8*b^3*(x - 1)^a + 2*(6*b^2 + 5*b + 3)*a*(x - 1)^a)*(x - 1)^3*e^(-b) + 1/24*(3*a^2*(x - 1)^a + a*(12*b + 5)*(x - 1)^a + 12*b^2*(x - 1)^a)*(x - 1)^2*e^(-b) - 1/2*(a*(x - 1)^a + 2*b*(x - 1)^a)*(x - 1)*e^(-b) + (x - 1)^a*e^(-b) ::
• ## sage/functions/hyperbolic.py

diff --git a/sage/functions/hyperbolic.py b/sage/functions/hyperbolic.py
 a :meth:sage.symbolic.expression.Expression.simplify:: sage: sinh(arccosh(x),hold=True).simplify() sqrt(x - 1)*sqrt(x + 1) sqrt(x + 1)*sqrt(x - 1) """ GinacFunction.__init__(self, "sinh", latex_name=r"\sinh") sage: bool(diff(sech(x), x) == diff(1/cosh(x), x)) True sage: diff(sech(x), x) -tanh(x)*sech(x) -sech(x)*tanh(x) """ x = args[0] return -sech(x)*tanh(x) EXAMPLES:: sage: diff(acsch(x), x) -1/(sqrt(1/x^2 + 1)*x^2) -1/(x^2*sqrt(1/x^2 + 1)) """ x = args[0] return -1/(x**2 * (1 + x**(-2)).sqrt())
• ## sage/functions/orthogonal_polys.py

diff --git a/sage/functions/orthogonal_polys.py b/sage/functions/orthogonal_polys.py
 a sage: gen_legendre_P(2, 0, t) == legendre_P(2, t) True sage: gen_legendre_P(3, 1, t) -3/2*sqrt(-t^2 + 1)*(5*t^2 - 1) -3/2*(5*t^2 - 1)*sqrt(-t^2 + 1) sage: gen_legendre_P(4, 3, t) 105*sqrt(-t^2 + 1)*(t^2 - 1)*t 105*(t^2 - 1)*sqrt(-t^2 + 1)*t sage: gen_legendre_P(7, 3, I).expand() -16695*sqrt(2) sage: gen_legendre_P(4, 1, 2.5)
• ## sage/functions/other.py

diff --git a/sage/functions/other.py b/sage/functions/other.py
 a sage: gamma_inc(2,0) 1 sage: gamma_inc(1/2,2) -(erf(sqrt(2)) - 1)*sqrt(pi) -sqrt(pi)*(erf(sqrt(2)) - 1) sage: gamma_inc(1/2,1) -(erf(1) - 1)*sqrt(pi) -sqrt(pi)*(erf(1) - 1) sage: gamma_inc(1/2,0) sqrt(pi) sage: gamma_inc(x,0) sage: var('a') a sage: conjugate(a*sqrt(-2)*sqrt(-3)) conjugate(a)*conjugate(sqrt(-3))*conjugate(sqrt(-2)) conjugate(sqrt(-2))*conjugate(sqrt(-3))*conjugate(a) Test pickling::
• ## sage/functions/piecewise.py

diff --git a/sage/functions/piecewise.py b/sage/functions/piecewise.py
 a sage: f(x) = x^2 sage: f = Piecewise([[(-1,1),f]]) sage: f._fourier_series_helper(3, 1, lambda n: 1) -4*cos(pi*x)/pi^2 + cos(2*pi*x)/pi^2 + 1/3 cos(2*pi*x)/pi^2 - 4*cos(pi*x)/pi^2 + 1/3 """ from sage.all import pi, sin, cos, srange x = var('x') sage: f(x) = x^2 sage: f = Piecewise([[(-1,1),f]]) sage: f.fourier_series_partial_sum(3,1) -4*cos(pi*x)/pi^2 + cos(2*pi*x)/pi^2 + 1/3 cos(2*pi*x)/pi^2 - 4*cos(pi*x)/pi^2 + 1/3 sage: f1(x) = -1 sage: f2(x) = 2 sage: f = Piecewise([[(-pi,pi/2),f1],[(pi/2,pi),f2]]) sage: f.fourier_series_partial_sum(3,pi) -3*sin(2*x)/pi + 3*sin(x)/pi - 3*cos(x)/pi - 1/4 -3*cos(x)/pi - 3*sin(2*x)/pi + 3*sin(x)/pi - 1/4 """ return self._fourier_series_helper(N, L, lambda n: 1) sage: f(x) = x^2 sage: f = Piecewise([[(-1,1),f]]) sage: f.fourier_series_partial_sum_cesaro(3,1) -8/3*cos(pi*x)/pi^2 + 1/3*cos(2*pi*x)/pi^2 + 1/3 1/3*cos(2*pi*x)/pi^2 - 8/3*cos(pi*x)/pi^2 + 1/3 sage: f1(x) = -1 sage: f2(x) = 2 sage: f = Piecewise([[(-pi,pi/2),f1],[(pi/2,pi),f2]]) sage: f.fourier_series_partial_sum_cesaro(3,pi) -sin(2*x)/pi + 2*sin(x)/pi - 2*cos(x)/pi - 1/4 -2*cos(x)/pi - sin(2*x)/pi + 2*sin(x)/pi - 1/4 """ return self._fourier_series_helper(N, L, lambda n: 1-n/N) sage: f(x) = x^2 sage: f = Piecewise([[(-1,1),f]]) sage: f.fourier_series_partial_sum_hann(3,1) -3*cos(pi*x)/pi^2 + 1/4*cos(2*pi*x)/pi^2 + 1/3 1/4*cos(2*pi*x)/pi^2 - 3*cos(pi*x)/pi^2 + 1/3 sage: f1(x) = -1 sage: f2(x) = 2 sage: f = Piecewise([[(-pi,pi/2),f1],[(pi/2,pi),f2]]) sage: f.fourier_series_partial_sum_hann(3,pi) -3/4*sin(2*x)/pi + 9/4*sin(x)/pi - 9/4*cos(x)/pi - 1/4 -9/4*cos(x)/pi - 3/4*sin(2*x)/pi + 9/4*sin(x)/pi - 1/4 """ from sage.all import cos, pi return self._fourier_series_helper(N, L, lambda n: (1+cos(pi*n/N))/2) sage: f(x) = x^2 sage: f = Piecewise([[(-1,1),f]]) sage: f.fourier_series_partial_sum_filtered(3,1,[1,1,1]) -4*cos(pi*x)/pi^2 + cos(2*pi*x)/pi^2 + 1/3 cos(2*pi*x)/pi^2 - 4*cos(pi*x)/pi^2 + 1/3 sage: f1(x) = -1 sage: f2(x) = 2 sage: f = Piecewise([[(-pi,pi/2),f1],[(pi/2,pi),f2]]) sage: f.fourier_series_partial_sum_filtered(3,pi,[1,1,1]) -3*sin(2*x)/pi + 3*sin(x)/pi - 3*cos(x)/pi - 1/4 -3*cos(x)/pi - 3*sin(2*x)/pi + 3*sin(x)/pi - 1/4 """ return self._fourier_series_helper(N, L, lambda n: F[n]) sage: x, s, w = var('x, s, w') sage: f = Piecewise([[(0,1),1],[(1,2), 1-x]]) sage: f.laplace(x, s) (s + 1)*e^(-2*s)/s^2 - e^(-s)/s + 1/s - e^(-s)/s^2 -e^(-s)/s + (s + 1)*e^(-2*s)/s^2 + 1/s - e^(-s)/s^2 sage: f.laplace(x, w) (w + 1)*e^(-2*w)/w^2 - e^(-w)/w + 1/w - e^(-w)/w^2 -e^(-w)/w + (w + 1)*e^(-2*w)/w^2 + 1/w - e^(-w)/w^2 ::
• ## sage/functions/special.py

diff --git a/sage/functions/special.py b/sage/functions/special.py
 a sage: n(bessel_J(3,10,"maxima")) 0.0583793793051... sage: spherical_hankel2(2,x) (-I*x^2 - 3*x + 3*I)*e^(-I*x)/x^3 -(I*x^2 + 3*x - 3*I)*e^(-I*x)/x^3 """ MaximaFunction.__init__(self, name) EXAMPLES:: sage: spherical_hankel2(2, x) (-I*x^2 - 3*x + 3*I)*e^(-I*x)/x^3 -(I*x^2 + 3*x - 3*I)*e^(-I*x)/x^3 Here I = sqrt(-1). """
• ## sage/functions/trig.py

diff --git a/sage/functions/trig.py b/sage/functions/trig.py
 a sage: bool(diff(sec(x), x) == diff(1/cos(x), x)) True sage: diff(sec(x), x) tan(x)*sec(x) sec(x)*tan(x) """ return sec(x)*tan(x) sage: bool(diff(csc(x), x) == diff(1/sin(x), x)) True sage: diff(csc(x), x) -csc(x)*cot(x) -cot(x)*csc(x) """ return -csc(x)*cot(x) EXAMPLES:: sage: diff(acsc(x), x) -1/(sqrt(-1/x^2 + 1)*x^2) -1/(x^2*sqrt(-1/x^2 + 1)) """ return -1/(x**2 * (1 - x**(-2)).sqrt()) EXAMPLES:: sage: diff(asec(x), x) 1/(sqrt(-1/x^2 + 1)*x^2) 1/(x^2*sqrt(-1/x^2 + 1)) """ return 1/(x**2 * (1 - x**(-2)).sqrt())
• ## sage/functions/wigner.py

diff --git a/sage/functions/wigner.py b/sage/functions/wigner.py
 a sage: clebsch_gordan(1.5,0.5,1, 1.5,-0.5,1) 1/2*sqrt(3) sage: clebsch_gordan(3/2,1/2,1, -1/2,1/2,0) -sqrt(1/6)*sqrt(3) -sqrt(3)*sqrt(1/6) NOTES:
• ## sage/misc/functional.py

diff --git a/sage/misc/functional.py b/sage/misc/functional.py
 a :: sage: sum(k * binomial(n, k), k, 1, n) n*2^(n - 1) 2^(n - 1)*n :: sage: integral(sin(x)^2, x, algorithm='maxima') 1/2*x - 1/4*sin(2*x) sage: integral(sin(x)^2, x, algorithm='sympy') -1/2*sin(x)*cos(x) + 1/2*x -1/2*cos(x)*sin(x) + 1/2*x TESTS:
• ## sage/rings/qqbar.py

diff --git a/sage/rings/qqbar.py b/sage/rings/qqbar.py
 a sage: x = polygen(SR) sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p x^2 + (-sqrt(-5) - sqrt(3))*x + sqrt(-5)*sqrt(3) x^2 + (-sqrt(3) - sqrt(-5))*x + sqrt(3)*sqrt(-5) sage: p = QQbar.common_polynomial(p) sage: a = QQbar.polynomial_root(p, CIF(RIF(-0.1, 0.1), RIF(2, 3))); a 0.?e-18 + 2.236067977499790?*I
• ## sage/symbolic/callable.py

diff --git a/sage/symbolic/callable.py b/sage/symbolic/callable.py
 a sage: f(x, y, z) = sin(x+y+z) sage: g(w, t) = cos(w - t) sage: f + g (t, w, x, y, z) |--> sin(x + y + z) + cos(-t + w) (t, w, x, y, z) |--> cos(-t + w) + sin(x + y + z) ::
• ## sage/symbolic/constants.py

diff --git a/sage/symbolic/constants.py b/sage/symbolic/constants.py
 a sage: f^2 (I*e + I)^2 sage: _.expand() -2*e - e^2 - 1 -e^2 - 2*e - 1 :: floating point rings:: sage: a = pi + e + golden_ratio + log2 + euler_gamma + catalan + khinchin + twinprime + mertens; a pi + euler_gamma + catalan + golden_ratio + log2 + khinchin + twinprime + mertens + e mertens + twinprime + khinchin + log2 + golden_ratio + catalan + euler_gamma + pi + e sage: parent(a) Symbolic Ring sage: RR(a)
• ## sage/symbolic/expression.pyx

diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
 a sage: var('a,b,c') (a, b, c) sage: expand((u + v + a + b + c)^2) a^2 + b^2 + 2*a*b + c^2 + 2*a*c + 2*b*c + u^2 + 2*a*u + 2*b*u + 2*c*u + v^2 + 2*a*v + 2*b*v + 2*c*v + 2*u*v a^2 + 2*a*b + b^2 + 2*a*c + 2*b*c + c^2 + 2*a*u + 2*b*u + 2*c*u + u^2 + 2*a*v + 2*b*v + 2*c*v + 2*u*v + v^2 TESTS: sage: a.real_part() 4*sqrt(3)/(sqrt(3) + 5) sage: a.imag_part() sqrt(abs(4*(sqrt(3) - 5)*(sqrt(3) + 5) + 48))/(sqrt(3) + 5) sqrt(abs(4*(sqrt(3) + 5)*(sqrt(3) - 5) + 48))/(sqrt(3) + 5) """ ############################################################################### sage: latex((x+2)/(x^3+1)) \frac{x + 2}{x^{3} + 1} sage: latex((x+2)*(x+1)/(x^3+1)) \frac{{\left(x + 1\right)} {\left(x + 2\right)}}{x^{3} + 1} \frac{{\left(x + 2\right)} {\left(x + 1\right)}}{x^{3} + 1} sage: latex((x+2)/(x^3+1)/(x+1)) \frac{x + 2}{{\left(x^{3} + 1\right)} {\left(x + 1\right)}} # check if comparison of constant terms in Pynac add objects work sage: (y-1)*(y-2) (y - 2)*(y - 1) (y - 1)*(y - 2) Check if Pynac can compute inverses of Python longs (:trac:13107):: sage: x,y = var('x,y') sage: x.__cmp__(y) -1 1 sage: x < y x < y sage: cmp(x,y) -1 1 sage: cmp(SR(0.5), SR(0.7)) -1 sage: SR(0.5) < SR(0.7) sage: a = sqrt(3) sage: b = x^2+1 sage: a.__cmp__(b)   # indirect doctest 1 -1 """ return print_order_compare(left._gobj, (right)._gobj) sage: h = sin(x)/cos(x) sage: derivative(h,x,x,x) 6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2 8*sin(x)^2/cos(x)^2 + 6*sin(x)^4/cos(x)^4 + 2 sage: derivative(h,x,3) 6*sin(x)^4/cos(x)^4 + 8*sin(x)^2/cos(x)^2 + 2 8*sin(x)^2/cos(x)^2 + 6*sin(x)^4/cos(x)^4 + 2 :: sage: g = f.series(x==1, 4); g (-sin(y) - 1) + (-2*sin(y) - 2)*(x - 1) + (-sin(y) + 3)*(x - 1)^2 + 1*(x - 1)^3 sage: h = g.truncate(); h (x - 1)^3 - (x - 1)^2*(-sin(y) - 3) - 2*(x - 1)*(-2*sin(y) + 1) - sin(y) - 1 (x - 1)^3 - (x - 1)^2*(sin(y) - 3) - 2*(x - 1)*(sin(y) + 1) - sin(y) - 1 sage: h.expand() x^3 - x^2*sin(y) - 5*x + 3 Check that ticket #7472 is fixed (Taylor polynomial in more variables):: sage: x,y=var('x y'); taylor(x*y^3,(x,1),(y,1),4) (x - 1)*(y - 1)^3 + (y - 1)^3 + 3*(x - 1)*(y - 1)^2 + 3*(y - 1)^2 + 3*(x - 1)*(y - 1) + x + 3*y - 3 (x - 1)*(y - 1)^3 + 3*(x - 1)*(y - 1)^2 + (y - 1)^3 + 3*(x - 1)*(y - 1) + 3*(y - 1)^2 + x + 3*y - 3 sage: expand(_) x*y^3 sage: x,y = var('x,y') sage: a = (x-y)^5 sage: a.expand() x^5 - y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y x^5 - 5*x^4*y + 10*x^3*y^2 - 10*x^2*y^3 + 5*x*y^4 - y^5 sage: expand(a) x^5 - y^5 + 5*x*y^4 - 10*x^2*y^3 + 10*x^3*y^2 - 5*x^4*y x^5 - 5*x^4*y + 10*x^3*y^2 - 10*x^2*y^3 + 5*x*y^4 - y^5 We expand some other expressions:: sage: expand((x-1)^3/(y-1)) x^3/(y - 1) - 3*x^2/(y - 1) + 3*x/(y - 1) - 1/(y - 1) sage: expand((x+sin((x+y)^2))^2) x^2 + sin((x + y)^2)^2 + 2*x*sin((x + y)^2) x^2 + 2*x*sin((x + y)^2) + sin((x + y)^2)^2 We can expand individual sides of a relation:: sage: var('x,y') (x, y) sage: ((x + (2/3)*y)^3).expand() x^3 + 8/27*y^3 + 4/3*x*y^2 + 2*x^2*y x^3 + 2*x^2*y + 4/3*x*y^2 + 8/27*y^3 sage: expand( (x*sin(x) - cos(y)/x)^2 ) x^2*sin(x)^2 - 2*cos(y)*sin(x) + cos(y)^2/x^2 sage: f = (x-y)*(x+y); f (x - y)*(x + y) (x + y)*(x - y) sage: f.expand() x^2 - y^2 """ EXAMPLES:: sage: sin(5*x).expand_trig() sin(x)^5 - 10*cos(x)^2*sin(x)^3 + 5*cos(x)^4*sin(x) 5*cos(x)^4*sin(x) - 10*cos(x)^2*sin(x)^3 + sin(x)^5 sage: cos(2*x + var('y')).expand_trig() cos(2*x)*cos(y) - sin(2*x)*sin(y) sage: f = sin(sin(3*cos(2*x))*x) sage: f.expand_trig() sin(-(sin(cos(2*x))^3 - 3*cos(cos(2*x))^2*sin(cos(2*x)))*x) sin((3*cos(cos(2*x))^2*sin(cos(2*x)) - sin(cos(2*x))^3)*x) sage: f.expand_trig(full=True) sin(-((cos(sin(x)^2)*sin(cos(x)^2) - cos(cos(x)^2)*sin(sin(x)^2))^3 - 3*(cos(cos(x)^2)*cos(sin(x)^2) + sin(cos(x)^2)*sin(sin(x)^2))^2*(cos(sin(x)^2)*sin(cos(x)^2) - cos(cos(x)^2)*sin(sin(x)^2)))*x) sin((3*(cos(cos(x)^2)*cos(sin(x)^2) + sin(cos(x)^2)*sin(sin(x)^2))^2*(cos(sin(x)^2)*sin(cos(x)^2) - cos(cos(x)^2)*sin(sin(x)^2)) - (cos(sin(x)^2)*sin(cos(x)^2) - cos(cos(x)^2)*sin(sin(x)^2))^3)*x) sage: sin(2*x).expand_trig(times=False) sin(2*x) sage: sin(2*x).expand_trig(times=True) sage: y=var('y') sage: f=sin(x)*cos(x)^3+sin(y)^2 sage: f.reduce_trig() -1/2*cos(2*y) + 1/4*sin(2*x) + 1/8*sin(4*x) + 1/2 -1/2*cos(2*y) + 1/8*sin(4*x) + 1/4*sin(2*x) + 1/2 To reduce only the expressions involving x we use optional parameter:: sage: f.reduce_trig(x) sin(y)^2 + 1/4*sin(2*x) + 1/8*sin(4*x) sin(y)^2 + 1/8*sin(4*x) + 1/4*sin(2*x) ALIASES: :meth:trig_reduce and :meth:reduce_trig are the same """ (c, b) sage: ((a+b)*(a+c)).match((w0+b)*(w0+c)) {$0: a} sage: print ((a+b)*(a+c)).match((w0+w1)*(w0+w2)) {$2: b, $0: a,$1: c} sage: t = ((a+b)*(a+c)).match((w0+w1)*(w0+w2)) sage: t[w0], t[w1], t[w2] (a, c, b) sage: print ((a+b)*(a+c)).match((w0+w1)*(w1+w2)) None sage: t = (a*(x+y)+a*z+b).match(a*w0+w1) sage: t[w0], t[w1] (z, a*(x + y) + b) (x + y, a*z + b) sage: print (a+b+c+d+e+f).match(c) None sage: (a+b+c+d+e+f).has(c) sage: (1+x+x^2+x^3).find(x) [x] sage: (1+x+x^2+x^3).find(x^w0) [x^3, x^2] [x^2, x^3] sage: (1+x+x^2+x^3).find(y) [] while itr.is_not_equal(found.end()): res.append(new_Expression_from_GEx(self._parent, itr.obj())) itr.inc() res.sort() return res def has(self, pattern): sage: f (x, y) |--> x^n + y^n sage: f(2,3) 2^n + 3^n 3^n + 2^n """ # we override type checking in CallableSymbolicExpressionRing, # since it checks for old SymbolicVariable's sage: bool(p.poly(a) == (x-a*sqrt(2))^2 + x + 1) True sage: p.poly(x) 2*a^2 + x^2 - (-2*sqrt(2)*a - 1)*x + 1 2*a^2 - (2*sqrt(2)*a - 1)*x + x^2 + 1 """ from sage.symbolic.ring import SR f = self._maxima_() (x, y, z) sage: f = 4*x*y + x*z + 20*y^2 + 21*y*z + 4*z^2 + x^2*y^2*z^2 sage: f.collect(x) x^2*y^2*z^2 + 20*y^2 + x*(4*y + z) + 4*z^2 + 21*y*z x^2*y^2*z^2 + x*(4*y + z) + 20*y^2 + 21*y*z + 4*z^2 sage: f.collect(y) (x^2*z^2 + 20)*y^2 + (4*x + 21*z)*y + 4*z^2 + x*z (x^2*z^2 + 20)*y^2 + (4*x + 21*z)*y + x*z + 4*z^2 sage: f.collect(z) (x^2*y^2 + 4)*z^2 + 20*y^2 + 4*x*y + (x + 21*y)*z (x^2*y^2 + 4)*z^2 + 4*x*y + 20*y^2 + (x + 21*y)*z TESTS: To prevent automatic evaluation use the hold argument:: sage: arccosh(x).sinh() sqrt(x - 1)*sqrt(x + 1) sqrt(x + 1)*sqrt(x - 1) sage: arccosh(x).sinh(hold=True) sinh(arccosh(x)) sage: sinh(arccosh(x),hold=True) sinh(arccosh(x)) sage: sinh(arccosh(x)) sqrt(x - 1)*sqrt(x + 1) sqrt(x + 1)*sqrt(x - 1) To then evaluate again, we currently must use Maxima via :meth:simplify:: sage: a = arccosh(x).sinh(hold=True); a.simplify() sqrt(x - 1)*sqrt(x + 1) sqrt(x + 1)*sqrt(x - 1) TESTS:: sage: f.numerator() sqrt(x) + sqrt(y) + sqrt(z) sage: f.denominator() -sqrt(theta) + x^10 - y^10 x^10 - y^10 - sqrt(theta) sage: f.numerator(normalize=False) -(sqrt(x) + sqrt(y) + sqrt(z)) (sqrt(x) + sqrt(y) + sqrt(z)) sage: f.denominator(normalize=False) sqrt(theta) - x^10 + y^10 x^10 - y^10 - sqrt(theta) sage: y = var('y') sage: g = x + y/(x + 2); g EXAMPLES:: sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) - 1) + log(sqrt(2) + 1) log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: res = t.maxima_methods().logcontract(); res log((sqrt(2) - 1)*(sqrt(2) + 1)) log((sqrt(2) + 1)*(sqrt(2) - 1)) sage: type(res) """ sage: f=tan(3*x) sage: f.simplify_trig() -(4*cos(x)^2 - 1)*sin(x)/(-4*cos(x)^3 + 3*cos(x)) (4*cos(x)^2 - 1)*sin(x)/(4*cos(x)^3 - 3*cos(x)) sage: f.simplify_trig(False) sin(3*x)/cos(3*x) :: sage: f = ((x - 1)^(3/2) - (x + 1)*sqrt(x - 1))/sqrt((x - 1)*(x + 1)); f ((x - 1)^(3/2) - sqrt(x - 1)*(x + 1))/sqrt((x - 1)*(x + 1)) -((x + 1)*sqrt(x - 1) - (x - 1)^(3/2))/sqrt((x + 1)*(x - 1)) sage: f.simplify_rational() -2*sqrt(x - 1)/sqrt(x^2 - 1) 2*sqrt(x - 1)/sqrt(x^2 - 1) With map=True each term in a sum is simplified separately and thus the resuls are shorter for functions which are sage: f.simplify_rational() (2*x^2 + 5*x + 4)/(x^3 + 5*x^2 + 8*x + 4) sage: f.simplify_rational(algorithm='noexpand') ((x + 2)^2 + (x + 1)*x)/((x + 1)*(x + 2)^2) ((x + 2)^2 + (x + 1)*x)/((x + 2)^2*(x + 1)) """ self_m = self._maxima_() if algorithm == 'full': :: sage: f = binomial(n, k)*factorial(k)*factorial(n-k); f binomial(n, k)*factorial(-k + n)*factorial(k) binomial(n, k)*factorial(k)*factorial(-k + n) sage: f.simplify_factorial() factorial(n) A more complicated example, which needs further processing:: sage: f = factorial(x)/factorial(x-2)/2 + factorial(x+1)/factorial(x)/2; f 1/2*factorial(x)/factorial(x - 2) + 1/2*factorial(x + 1)/factorial(x) 1/2*factorial(x + 1)/factorial(x) + 1/2*factorial(x)/factorial(x - 2) sage: g = f.simplify_factorial(); g 1/2*(x - 1)*x + 1/2*x + 1/2 sage: g.simplify_rational() sage: e1 = 1/(sqrt(5)+sqrt(2)) sage: e2 = (sqrt(5)-sqrt(2))/3 sage: e1.simplify_radical() 1/(sqrt(2) + sqrt(5)) 1/(sqrt(5) + sqrt(2)) sage: e2.simplify_radical() -1/3*sqrt(2) + 1/3*sqrt(5) 1/3*sqrt(5) - 1/3*sqrt(2) sage: (e1-e2).simplify_radical() 0 """ sage: log_expr = (log(sqrt(2)-1)+log(sqrt(2)+1)) sage: log_expr.simplify_log('all') log((sqrt(2) - 1)*(sqrt(2) + 1)) log((sqrt(2) + 1)*(sqrt(2) - 1)) sage: _.simplify_rational() 0 sage: log_expr.simplify_full()   # applies both simplify_log and simplify_rational To expand also log(3/4) use algorithm='all':: sage: (log(3/4*x^pi)).log_expand('all') pi*log(x) + log(3) - log(4) pi*log(x) - log(4) + log(3) To expand only the power use algorithm='powers'.:: pi*log(x) + log(3/4) sage: (log(3/4*x^pi)).log_expand('all') pi*log(x) + log(3) - log(4) pi*log(x) - log(4) + log(3) sage: (log(3/4*x^pi)).log_expand() pi*log(x) + log(3/4) sage: x,y,z = var('x, y, z') sage: (x^3-y^3).factor() (x^2 + y^2 + x*y)*(x - y) (x^2 + x*y + y^2)*(x - y) sage: factor(-8*y - 4*x + z^2*(2*y + x)) (x + 2*y)*(z - 2)*(z + 2) (x + 2*y)*(z + 2)*(z - 2) sage: f = -1 - 2*x - x^2 + y^2 + 2*x*y^2 + x^2*y^2 sage: F = factor(f/(36*(1 + 2*y + y^2)), dontfactor=[x]); F 1/36*(x^2 + 2*x + 1)*(y - 1)/(y + 1) sage: var('x,y') (x, y) sage: (x^99 + y^99).factor() (x^60 + y^60 + x^3*y^57 - x^9*y^51 - x^12*y^48 + x^18*y^42 + x^21*y^39 - x^27*y^33 - x^30*y^30 - x^33*y^27 + x^39*y^21 + x^42*y^18 - x^48*y^12 - x^51*y^9 + x^57*y^3)*(x^20 + y^20 + x*y^19 - x^3*y^17 - x^4*y^16 + x^6*y^14 + x^7*y^13 - x^9*y^11 - x^10*y^10 - x^11*y^9 + x^13*y^7 + x^14*y^6 - x^16*y^4 - x^17*y^3 + x^19*y)*(x^10 + y^10 - x*y^9 + x^2*y^8 - x^3*y^7 + x^4*y^6 - x^5*y^5 + x^6*y^4 - x^7*y^3 + x^8*y^2 - x^9*y)*(x^6 + y^6 - x^3*y^3)*(x^2 + y^2 - x*y)*(x + y) (x^60 + x^57*y^3 - x^51*y^9 - x^48*y^12 + x^42*y^18+ x^39*y^21 - x^33*y^27 - x^30*y^30 - x^27*y^33 + x^21*y^39+ x^18*y^42 - x^12*y^48 - x^9*y^51 + x^3*y^57 + y^60)*(x^20 + x^19*y - x^17*y^3 - x^16*y^4 + x^14*y^6 + x^13*y^7 - x^11*y^9 - x^10*y^10 - x^9*y^11 + x^7*y^13 + x^6*y^14 - x^4*y^16 - x^3*y^17 + x*y^19 + y^20)*(x^10 - x^9*y + x^8*y^2 - x^7*y^3 + x^6*y^4 - x^5*y^5 + x^4*y^6 - x^3*y^7 + x^2*y^8 - x*y^9 + y^10)*(x^6 - x^3*y^3 + y^6)*(x^2 - x*y + y^2)*(x + y) """ from sage.calculus.calculus import symbolic_expression_from_maxima_string, symbolic_expression_from_string if len(dontfactor) > 0: (x, y, z) sage: f = x^3-y^3 sage: f.factor() (x^2 + y^2 + x*y)*(x - y) (x^2 + x*y + y^2)*(x - y) Notice that the -1 factor is separated out:: sage: f.factor_list() [(x^2 + y^2 + x*y, 1), (x - y, 1)] [(x^2 + x*y + y^2, 1), (x - y, 1)] We factor a fairly straightforward expression:: sage: factor(-8*y - 4*x + z^2*(2*y + x)).factor_list() [(x + 2*y, 1), (z - 2, 1), (z + 2, 1)] [(x + 2*y, 1), (z + 2, 1), (z - 2, 1)] A more complicated example:: (x, u, v) sage: f = expand((2*u*v^2-v^2-4*u^3)^2 * (-u)^3 * (x-sin(x))^3) sage: f.factor() (-4*u^3 + 2*u*v^2 - v^2)^2*u^3*(-x + sin(x))^3 -(-4*u^3 + 2*u*v^2 - v^2)^2*u^3*(x - sin(x))^3 sage: g = f.factor_list(); g [(4*u^3 - 2*u*v^2 + v^2, 2), (u, 3), (x - sin(x), 3), (-1, 1)] [(-4*u^3 + 2*u*v^2 - v^2, 2), (u, 3), (x - sin(x), 3), (-1, 1)] This function also works for quotients:: sage: g.factor(dontfactor=[x]) 1/36*(x^2 + 2*x + 1)*(y - 1)/(y + 1) sage: g.factor_list(dontfactor=[x]) [(x^2 + 2*x + 1, 1), (y - 1, 1), (y + 1, -1), (1/36, 1)] [(x^2 + 2*x + 1, 1), (y + 1, -1), (y - 1, 1), (1/36, 1)] This example also illustrates that the exponents do not have to be integers:: A complicated example:: sage: f = expand((x^2 - 1)^3*(x^2 + 1)*(x-a)); f x^9 - a*x^8 - 2*x^7 + 2*a*x^6 + 2*x^3 - 2*a*x^2 + a - x -a*x^8 + x^9 + 2*a*x^6 - 2*x^7 - 2*a*x^2 + 2*x^3 + a - x The default variable is a, since it is the first in alphabetical order:: sage: a.solve(t) [] sage: b = a.simplify_radical(); b -23040*(25.0*e^(900*t) - 2.0*e^(1800*t) - 32.0)*e^(-2400*t) 23040*(2.0*e^(1800*t) - 25.0*e^(900*t) + 32.0)*e^(-2400*t) sage: b.solve(t) [] sage: b.solve(t, to_poly_solve=True)
• ## sage/symbolic/expression_conversions.py

diff --git a/sage/symbolic/expression_conversions.py b/sage/symbolic/expression_conversions.py
 a sage: c.get_fake_div(-x) FakeExpression([x], ) sage: c.get_fake_div((2*x^3+2*x-1)/((x-2)*(x+1))) FakeExpression([2*x^3 + 2*x - 1, FakeExpression([x - 2, x + 1], )], ) FakeExpression([2*x^3 + 2*x - 1, FakeExpression([x + 1, x - 2], )], ) Check if #8056 is fixed, i.e., if numerator is 1.:: sage: f = (2*x^3+2*x-1)/((x-2)*(x+1)) sage: f._fast_callable_(etb) div(add(add(mul(ipow(v_0, 3), 2), mul(v_0, 2)), -1), mul(add(v_0, -2), add(v_0, 1))) div(add(add(mul(ipow(v_0, 3), 2), mul(v_0, 2)), -1), mul(add(v_0, 1), add(v_0, -2))) """ return FastCallableConverter(ex, etb)()
• ## sage/symbolic/function.pyx

diff --git a/sage/symbolic/function.pyx b/sage/symbolic/function.pyx
 a Test pickling expressions with symbolic functions:: sage: u = loads(dumps(foo(x)^2 + foo(y) + x^y)); u x^y + foo(x)^2 + foo(y) foo(x)^2 + x^y + foo(y) sage: u.subs(y=0) foo(x)^2 + foo(0) + 1 sage: u.subs(y=0).n()
• ## sage/symbolic/function_factory.py

diff --git a/sage/symbolic/function_factory.py b/sage/symbolic/function_factory.py
 a -b*sin(a) sage: g.substitute_function(cr, (sin(x) + cos(x)).function(x)) -(sin(a) - cos(a))*b b*(cos(a) - sin(a)) In Sage 4.0, basic arithmetic with unevaluated functions is no longer supported::
• ## sage/symbolic/getitem.pyx

diff --git a/sage/symbolic/getitem.pyx b/sage/symbolic/getitem.pyx
 a sage: x,y,z = var('x,y,z') sage: e = x + x*y + z^y + 3*y*z; e x*y + 3*y*z + z^y + x x*y + 3*y*z + x + z^y sage: e.op[1] 3*y*z sage: e.op[1,1] z sage: e.op[-1] x z^y sage: e.op[1:] [3*y*z, z^y, x] [3*y*z, x, z^y] sage: e.op[:2] [x*y, 3*y*z] sage: e.op[-2:] [z^y, x] [x, z^y] sage: e.op[:-2] [x*y, 3*y*z] sage: e.op[-5]
• ## sage/symbolic/integration/integral.py

diff --git a/sage/symbolic/integration/integral.py b/sage/symbolic/integration/integral.py
 a x y  + Sqrt[--] FresnelS[Sqrt[--] x] 2                 Pi sage: print f.integral(x) y^z*x + 1/8*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x))*sqrt(pi) x*y^z + 1/8*sqrt(pi)*((I + 1)*sqrt(2)*erf((1/2*I + 1/2)*sqrt(2)*x) + (I - 1)*sqrt(2)*erf((1/2*I - 1/2)*sqrt(2)*x)) Alternatively, just use algorithm='mathematica_free' to integrate via Mathematica over the internet (does NOT require a Mathematica license!):: :: sage: A = integral(1/ ((x-4) * (x^3+2*x+1)), x); A 1/73*log(x - 4) - 1/73*integrate((x^2 + 4*x + 18)/(x^3 + 2*x + 1), x) -1/73*integrate((x^2 + 4*x + 18)/(x^3 + 2*x + 1), x) + 1/73*log(x - 4) We now show that floats are not converted to rationals automatically since we by default have keepfloat: true in maxima. sage: assume(a>0) sage: integrate(1/(x^3 *(a+b*x)^(1/3)), x) 2/9*sqrt(3)*b^2*arctan(1/3*(2*(b*x + a)^(1/3) + a^(1/3))*sqrt(3)/a^(1/3))/a^(7/3) + 2/9*b^2*log((b*x + a)^(1/3) - a^(1/3))/a^(7/3) - 1/9*b^2*log((b*x + a)^(2/3) + (b*x + a)^(1/3)*a^(1/3) + a^(2/3))/a^(7/3) + 1/6*(4*(b*x + a)^(5/3)*b^2 - 7*(b*x + a)^(2/3)*a*b^2)/((b*x + a)^2*a^2 - 2*(b*x + a)*a^3 + a^4) 2/9*sqrt(3)*b^2*arctan(1/3*sqrt(3)*(2*(b*x + a)^(1/3) + a^(1/3))/a^(1/3))/a^(7/3) - 1/9*b^2*log((b*x + a)^(2/3) + (b*x + a)^(1/3)*a^(1/3) + a^(2/3))/a^(7/3) + 2/9*b^2*log((b*x + a)^(1/3) - a^(1/3))/a^(7/3) + 1/6*(4*(b*x + a)^(5/3)*b^2 - 7*(b*x + a)^(2/3)*a*b^2)/((b*x + a)^2*a^2 - 2*(b*x + a)*a^3 + a^4) TESTS: see #3013:: sage: integrate(sin(x)*cos(10*x)*log(x), x) 1/198*(11*cos(9*x) - 9*cos(11*x))*log(x) + 1/44*Ei(-11*I*x) + 1/44*Ei(11*I*x) - 1/36*Ei(-9*I*x) - 1/36*Ei(9*I*x) -1/198*(9*cos(11*x) - 11*cos(9*x))*log(x) + 1/44*Ei(11*I*x) - 1/36*Ei(9*I*x) - 1/36*Ei(-9*I*x) + 1/44*Ei(-11*I*x) It is no longer possible to use certain functions without an explicit variable.  Instead, evaluate the function at a variable, Is  50015104*y^2-50015103  positive, negative, or zero? sage: assume(y>1) sage: res = integral(f,x,0.0001414, 1.); res 2*y*arctan(1/y) - 2*y*arctan(0.0001414/y) - 0.0001414*log(y^2 + 1.999396e-08) + log(y^2 + 1.0) - 1.9997172 -2*y*arctan(0.0001414/y) + 2*y*arctan(1/y) + log(y^2 + 1.0) - 0.0001414*log(y^2 + 1.999396e-08) - 1.9997172 sage: nres = numerical_integral(f.subs(y=2), 0.0001414, 1.); nres (1.4638323264144..., 1.6251803529759...e-14) sage: res.subs(y=2).n() sage: integrate( ((F(x)-G(x))^2).expand(), x, -infinity, infinity).n() -6.26376265908397e-17 sage: integrate( (F(x)-G(x))^2, x, -infinity, infinity).n() -6.26376265908397e-17 0 This was broken before Maxima 5.20::
• ## sage/symbolic/maxima_wrapper.py

diff --git a/sage/symbolic/maxima_wrapper.py b/sage/symbolic/maxima_wrapper.py
 a EXAMPLES:: sage: t = sin(x)^2 + cos(x)^2; t sin(x)^2 + cos(x)^2 cos(x)^2 + sin(x)^2 sage: res = t.maxima_methods().trigsimp(); res 1 sage: type(res) EXAMPLES:: sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) - 1) + log(sqrt(2) + 1) log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods(); u MaximaWrapper(log(sqrt(2) - 1) + log(sqrt(2) + 1)) MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1)) sage: type(u) sage: u.logcontract() log((sqrt(2) - 1)*(sqrt(2) + 1)) log((sqrt(2) + 1)*(sqrt(2) - 1)) sage: u.logcontract().parent() Symbolic Ring EXAMPLES:: sage: t = sin(x)^2 + cos(x)^2; t sin(x)^2 + cos(x)^2 cos(x)^2 + sin(x)^2 sage: u = t.maxima_methods() sage: import sagenb.misc.support as s sage: s.completions('u.airy_',globals(),system='python') sage: type(u.airy_ai) sage: u.airy_ai() airy_ai(sin(x)^2 + cos(x)^2) airy_ai(cos(x)^2 + sin(x)^2) """ if self._maxima_exp is None: self._maxima_exp = self._exp._maxima_() EXAMPLES:: sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) - 1) + log(sqrt(2) + 1) log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods().sage() sage: u is t True EXAMPLES:: sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) - 1) + log(sqrt(2) + 1) log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods() sage: SR(u) is t # indirect doctest True EXAMPLES:: sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) - 1) + log(sqrt(2) + 1) log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods(); u MaximaWrapper(log(sqrt(2) - 1) + log(sqrt(2) + 1)) MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1)) sage: loads(dumps(u)) MaximaWrapper(log(sqrt(2) - 1) + log(sqrt(2) + 1)) MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1)) """ return (MaximaWrapper, (self._exp,)) EXAMPLES:: sage: t = log(sqrt(2) - 1) + log(sqrt(2) + 1); t log(sqrt(2) - 1) + log(sqrt(2) + 1) log(sqrt(2) + 1) + log(sqrt(2) - 1) sage: u = t.maxima_methods(); u MaximaWrapper(log(sqrt(2) - 1) + log(sqrt(2) + 1)) MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1)) sage: u._repr_() 'MaximaWrapper(log(sqrt(2) - 1) + log(sqrt(2) + 1))' 'MaximaWrapper(log(sqrt(2) + 1) + log(sqrt(2) - 1))' """ return "MaximaWrapper(%s)"%(self._exp)
• ## sage/symbolic/relation.py

diff --git a/sage/symbolic/relation.py b/sage/symbolic/relation.py
 a a*x^2 + b*x + c == 0 sage: print solve(qe, x) [ x == -1/2*(b + sqrt(-4*a*c + b^2))/a, x == -1/2*(b - sqrt(-4*a*c + b^2))/a x == -1/2*(b + sqrt(b^2 - 4*a*c))/a, x == -1/2*(b - sqrt(b^2 - 4*a*c))/a ] sage: var('x,y,z,w') (x, y, z, w) sage: f =  (x+y+w) == (x^2 - y^2 - z^3);   f w + x + y == x^2 - y^2 - z^3 w + x + y == -z^3 + x^2 - y^2 sage: f.variables() (w, x, y, z) x == y - 5 sage: h =  x^3 + sqrt(2) == x*y*sin(x) sage: h sqrt(2) + x^3 == x*y*sin(x) x^3 + sqrt(2) == x*y*sin(x) sage: h - sqrt(2) x^3 == x*y*sin(x) - sqrt(2) sage: h + f x + sqrt(2) + x^3 + 3 == x*y*sin(x) + y - 2 x^3 + x + sqrt(2) + 3 == x*y*sin(x) + y - 2 sage: f = x + 3 < y - 2 sage: g = 2 < x+10 sage: f - g sage: x,y=var('x y'); c1(x,y)=(x-5)^2+y^2-16; c2(x,y)=(y-3)^2+x^2-9 sage: solve([c1(x,y),c2(x,y)],[x,y]) [[x == -9/68*sqrt(55) + 135/68, y == -15/68*sqrt(5)*sqrt(11) + 123/68], [x == 9/68*sqrt(55) + 135/68, y == 15/68*sqrt(5)*sqrt(11) + 123/68]] [[x == -9/68*sqrt(55) + 135/68, y == -15/68*sqrt(11)*sqrt(5) + 123/68], [x == 9/68*sqrt(55) + 135/68, y == 15/68*sqrt(11)*sqrt(5) + 123/68]] TESTS::
• ## sage/symbolic/ring.pyx

diff --git a/sage/symbolic/ring.pyx b/sage/symbolic/ring.pyx
 a sage: x,y = var('x,y') sage: w0 = SR.wild(0); w1 = SR.wild(1) sage: pattern = sin(x)*w0*w1^2; pattern $0*$1^2*sin(x) $1^2*$0*sin(x) sage: f = atan(sin(x)*3*x^2); f arctan(3*x^2*sin(x)) sage: f.has(pattern)