# Ticket #9880: trac_9880-fix_doctests-sage_5_10_beta2.patch

File trac_9880-fix_doctests-sage_5_10_beta2.patch, 76.1 KB (added by burcin, 8 years ago)
• ## sage/calculus/calculus.py

# HG changeset patch
# User Burcin Erocal <burcin@erocal.org>
# Date 1368203409 -7200
# Node ID 68741d5e87401796c63262dd9f4bcd6fc602544b
# Parent  8f5149eaebf5469d4d1f5142c536f2774b875664
Trac #9880: Fix doctests after order changes in Pynac.

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 -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: taylor(gamma(1/3+x),x,0,3) -1/432*((72*euler_gamma^3 + 36*euler_gamma^2*(sqrt(3)*pi + 9*log(3)) + 27*pi^2*log(3) + 243*log(3)^3 + 18*euler_gamma*(6*sqrt(3)*pi*log(3) + pi^2 + 27*log(3)^2 + 12*psi(1, 1/3)) + 324*log(3)*psi(1, 1/3) + sqrt(3)*(pi^3 + 9*pi*(9*log(3)^2 + 4*psi(1, 1/3))))*gamma(1/3) - 72*psi(2, 1/3)*gamma(1/3))*x^3 + 1/24*(6*sqrt(3)*pi*log(3) + 12*euler_gamma^2 + pi^2 + 4*euler_gamma*(sqrt(3)*pi + 9*log(3)) + 27*log(3)^2 + 12*psi(1, 1/3))*x^2*gamma(1/3) - 1/6*(6*euler_gamma + sqrt(3)*pi + 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/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) - 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 :: sage: f = x^3 - x + 1 sage: a = f.solve(x)[0].rhs(); a -1/2*(I*sqrt(3) + 1)*(1/18*sqrt(3)*sqrt(23) - 1/2)^(1/3) - 1/6*(-I*sqrt(3) + 1)/(1/18*sqrt(3)*sqrt(23) - 1/2)^(1/3) -1/2*(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3)*(I*sqrt(3) + 1) - 1/6*(-I*sqrt(3) + 1)/(1/18*sqrt(23)*sqrt(3) - 1/2)^(1/3) sage: a.minpoly() x^3 - x + 1 sage: f = a.minpoly(); f x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576 sage: f(a) ((((sqrt(2) + sqrt(3) + sqrt(5))^2 - 40)*(sqrt(2) + sqrt(3) + sqrt(5))^2 + 352)*(sqrt(2) + sqrt(3) + sqrt(5))^2 - 960)*(sqrt(2) + sqrt(3) + sqrt(5))^2 + 576 ((((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 sage: f(a).expand() 0 sage: xt = E[0,2].inverse_laplace(s,t) sage: yt = E[1,2].inverse_laplace(s,t) sage: xt 629/2*e^(-4*t) - 91/2*e^(4*t) + 1 -91/2*e^(4*t) + 629/2*e^(-4*t) + 1 sage: yt 629/8*e^(-4*t) + 91/8*e^(4*t) 91/8*e^(4*t) + 629/8*e^(-4*t) sage: p1 = plot(xt,0,1/2,rgbcolor=(1,0,0)) sage: p2 = plot(yt,0,1/2,rgbcolor=(0,1,0)) sage: (p1+p2).save(os.path.join(SAGE_TMP, "de_plot.png")) 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: sage.calculus.calculus.maxima('domain:complex')  # back to the default complex domain complex sage: desolve(x*diff(y,x)-x*sqrt(y^2+x^2)-y == 0, y, contrib_ode=True) [1/2*(2*x^2*sqrt(x^(-2)) - 2*x*sqrt(x^(-2))*arcsinh(y(x)/sqrt(x^2)) - 2*x*sqrt(x^(-2))*arcsinh(y(x)^2/(sqrt(y(x)^2)*x)) + log(4*(2*x^2*sqrt((x^2*y(x)^2 + y(x)^4)/x^2)*sqrt(x^(-2)) + x^2 + 2*y(x)^2)/x^2))/(x*sqrt(x^(-2))) == c] [1/2*(2*x^2*sqrt(x^(-2)) - 2*x*sqrt(x^(-2))*arcsinh(y(x)/sqrt(x^2)) - 2*x*sqrt(x^(-2))*arcsinh(y(x)^2/(x*sqrt(y(x)^2))) + log(4*(2*x^2*sqrt((x^2*y(x)^2 + y(x)^4)/x^2)*sqrt(x^(-2)) + x^2 + 2*y(x)^2)/x^2))/(x*sqrt(x^(-2))) == c] Trac #6479 fixed:: 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/exp_integral.py

diff --git a/sage/functions/exp_integral.py b/sage/functions/exp_integral.py
 a EXAMPLES:: sage: log_integral_offset(3) -log_integral(2) + log_integral(3) log_integral(3) - log_integral(2) """ BuiltinFunction.__init__(self, "log_integral_offset", nargs=1, x*sin_integral(x) + cos(x) sage: integrate(sin(x)/x, x) 1/2*I*Ei(-I*x) - 1/2*I*Ei(I*x) -1/2*I*Ei(I*x) + 1/2*I*Ei(-I*x) Compare values of the functions \operatorname{Si}(x) and
• ## 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: gen_legendre_Q(0, 1, x) -1/sqrt(-x^2 + 1) sage: gen_legendre_Q(2, 4, x).factor() 48*x/((x - 1)^2*(x + 1)^2) 48*x/((x + 1)^2*(x - 1)^2) """ from sage.functions.all import sqrt if m <= n:
• ## 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: beta(-1/2,-1/2) 0 sage: beta(x/2,3) beta(1/2*x, 3) beta(3, 1/2*x) sage: beta(.5,.5) 3.14159265358979 sage: beta(1,2.0+I) 0.400000000000000 - 0.200000000000000*I sage: beta(3,x+I) beta(x + I, 3) beta(3, x + I) Note that the order of arguments does not matter:: sage: beta(1/2,3*x) beta(3*x, 1/2) beta(1/2, 3*x) The result is symbolic if exact input is given:: sage: beta(2,1+5*I) beta(5*I + 1, 2) beta(2, 5*I + 1) sage: beta(2, 2.) 0.166666666666667 sage: beta(I, 2.) 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: x,y = var('x,y') sage: spherical_harmonic(3,2,x,y) 15/4*sqrt(7/30)*e^(2*I*y)*sin(x)^2*cos(x)/sqrt(pi) 15/4*sqrt(7/30)*cos(x)*e^(2*I*y)*sin(x)^2/sqrt(pi) sage: spherical_harmonic(3,2,1,2) 15/4*sqrt(7/30)*e^(4*I)*sin(1)^2*cos(1)/sqrt(pi) 15/4*sqrt(7/30)*cos(1)*e^(4*I)*sin(1)^2/sqrt(pi) """ _init() return meval("spherical_harmonic(%s,%s,%s,%s)"%(ZZ(m),ZZ(n),x,y)) sage: z = var("z") sage: # this is still wrong: must be abs(sin(z)) + 2*round(z/pi) sage: elliptic_e(z, 1) sin(z) + 2*round(z/pi) 2*round(z/pi) + sin(z) sage: elliptic_e(z, 0) z sage: elliptic_e(0.5, 0.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: RR(a) #abstol 1e11 13.2713479401972 sage: RealField(212)(a) 13.2713479401972493100988191995758139408711068200030748178329712 sage: RealField(230)(a) 13.271347940197249310098819199575813940871106820003074817832971189555 sage: CC(a) sage: CC(a) #abstol 1e11 13.2713479401972 sage: CDF(a) 13.2713479402
• ## 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 + 2*a*b + 2*a*c + 2*a*u + 2*a*v + b^2 + 2*b*c + 2*b*u + 2*b*v + c^2 + 2*c*u + 2*c*v + u^2 + 2*u*v + v^2 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: t*u 1 sage: t + u e^sqrt(x) + e^(-sqrt(x)) e^(-sqrt(x)) + e^sqrt(x) sage: t e^sqrt(x) 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: t = 2*x*y^z+3 sage: u = loads(dumps(t)) # indirect doctest sage: u 2*y^z*x + 3 2*x*y^z + 3 sage: bool(t == u) True sage: u.subs(x=z) EXAMPLES:: sage: gap(e + pi^2 + x^3) pi^2 + x^3 + e x^3 + pi^2 + e """ return '"%s"'%repr(self) EXAMPLES:: sage: singular(e + pi^2 + x^3) pi^2 + x^3 + e x^3 + pi^2 + e """ return '"%s"'%repr(self) sage: x = var('x') sage: f = sin(cos(x^2) + log(x)) sage: f._magma_init_(magma) '"sin(log(x) + cos(x^2))"' '"sin(cos(x^2) + log(x))"' sage: magma(f)                         # optional - magma sin(log(x) + cos(x^2)) sage: magma(f).Type()                  # optional - magma sage: latex(y + 3*(x^(-1))) y + \frac{3}{x} sage: latex(x^(y+z^(1/y))) x^{z^{\left(\frac{1}{y}\right)} + y} x^{y + z^{\left(\frac{1}{y}\right)}} sage: latex(1/sqrt(x+y)) \frac{1}{\sqrt{x + y}} sage: latex(sin(x*(z+y)^x)) \sin\left({\left(y + z\right)}^{x} x\right) \sin\left(x {\left(y + z\right)}^{x}\right) sage: latex(3/2*(x+y)/z/y) \frac{3 \, {\left(x + y\right)}}{2 \, y z} sage: latex((2^(x^y))) sage: latex((x*y).conjugate()) \overline{x} \overline{y} sage: latex(x*(1/(x^2)+sqrt(x^7))) {\left(\sqrt{x^{7}} + \frac{1}{x^{2}}\right)} x x {\left(\sqrt{x^{7}} + \frac{1}{x^{2}}\right)} Check spacing of coefficients of mul expressions (#3202):: 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 + 1\right)} {\left(x^{3} + 1\right)}} \frac{x + 2}{{\left(x^{3} + 1\right)} {\left(x + 1\right)}} Check that the sign is correct (#9086):: sage: x^3 -y == y + x x^3 - y == x + y sage: x^3 - y^10 >= y + x^10 x^3 - y^10 >= x^10 + y -y^10 + x^3 >= x^10 + y sage: x^2 > x x^2 > x sage: v,c = var('v,c') sage: assume(c != 0) sage: integral((1+v^2/c^2)^3/(1-v^2/c^2)^(3/2),v) -17/8*v^3/(sqrt(-v^2/c^2 + 1)*c^2) - 1/4*v^5/(sqrt(-v^2/c^2 + 1)*c^4) + 83/8*v/sqrt(-v^2/c^2 + 1) - 75/8*arcsin(v/(c^2*sqrt(c^(-2))))/sqrt(c^(-2)) 83/8*v/sqrt(-v^2/c^2 + 1) - 17/8*v^3/(c^2*sqrt(-v^2/c^2 + 1)) - 1/4*v^5/(c^4*sqrt(-v^2/c^2 + 1)) - 75/8*arcsin(v/(c^2*sqrt(c^(-2))))/sqrt(c^(-2)) sage: forget() """ from sage.symbolic.assumptions import _assumptions # 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: 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 :: (x, y) sage: u = (sin(x) + cos(y))*(cos(x) - sin(y)) sage: derivative(u,x,y) sin(x)*sin(y) - cos(x)*cos(y) -cos(x)*cos(y) + sin(x)*sin(y) sage: f = ((x^2+1)/(x^2-1))^(1/4) sage: g = derivative(f, x); g # this is a complex expression 1/2*(x/(x^2 - 1) - (x^2 + 1)*x/(x^2 - 1)^2)/((x^2 + 1)/(x^2 - 1))^(3/4) -1/2*((x^2 + 1)*x/(x^2 - 1)^2 - x/(x^2 - 1))/((x^2 + 1)/(x^2 - 1))^(3/4) sage: g.factor() -x/((x - 1)^2*(x + 1)^2*((x^2 + 1)/(x^2 - 1))^(3/4)) -x/((x + 1)^2*(x - 1)^2*((x^2 + 1)/(x^2 - 1))^(3/4)) :: sage: y = var('y') sage: f = y^(sin(x)) sage: derivative(f, x) y^sin(x)*log(y)*cos(x) y^sin(x)*cos(x)*log(y) :: sage: g = 1/(sqrt((x^2-1)*(x+5)^6)) sage: derivative(g, x) -((x + 5)^6*x + 3*(x + 5)^5*(x^2 - 1))/((x + 5)^6*(x^2 - 1))^(3/2) -((x + 5)^6*x + 3*(x^2 - 1)*(x + 5)^5)/((x^2 - 1)*(x + 5)^6)^(3/2) TESTS:: 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 -(sin(y) - 3)*(x - 1)^2 + (x - 1)^3 - 2*(sin(y) + 1)*(x - 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 sage: f.series(x,7) 1*x^(-1) + (-1/6)*x + 1/120*x^3 + (-1/5040)*x^5 + Order(x^7) sage: f.series(x==1,3) (sin(1)) + (-2*sin(1) + cos(1))*(x - 1) + (5/2*sin(1) - 2*cos(1))*(x - 1)^2 + Order((x - 1)^3) (sin(1)) + (cos(1) - 2*sin(1))*(x - 1) + (-2*cos(1) + 5/2*sin(1))*(x - 1)^2 + Order((x - 1)^3) sage: f.series(x==1,3).truncate().expand() 5/2*x^2*sin(1) - 2*x^2*cos(1) - 7*x*sin(1) + 5*x*cos(1) + 11/2*sin(1) - 3*cos(1) -2*x^2*cos(1) + 5/2*x^2*sin(1) + 5*x*cos(1) - 7*x*sin(1) - 3*cos(1) + 11/2*sin(1) Following the GiNaC tutorial, we use John Machin's amazing formula \pi = 16 \tan^{-1}(1/5) - 4 \tan^{-1}(1/239) to compute sage: var('a, x, z') (a, x, z) sage: taylor(a*log(z), z, 2, 3) 1/24*(z - 2)^3*a - 1/8*(z - 2)^2*a + 1/2*(z - 2)*a + a*log(2) 1/24*a*(z - 2)^3 - 1/8*a*(z - 2)^2 + 1/2*a*(z - 2) + a*log(2) :: 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) (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 sage: expand(_) x*y^3 sage: f.series(x,7).truncate() -1/5040*x^5 + 1/120*x^3 - 1/6*x + 1/x sage: f.series(x==1,3).truncate().expand() 5/2*x^2*sin(1) - 2*x^2*cos(1) - 7*x*sin(1) + 5*x*cos(1) + 11/2*sin(1) - 3*cos(1) -2*x^2*cos(1) + 5/2*x^2*sin(1) + 5*x*cos(1) - 7*x*sin(1) - 3*cos(1) + 11/2*sin(1) """ if not is_a_series(self._gobj): return self sage: ((x + (2/3)*y)^3).expand() 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*sin(x)*cos(y) + cos(y)^2/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*sin(x)^3*cos(x)^2 + 5*sin(x)*cos(x)^4 5*cos(x)^4*sin(x) - 10*cos(x)^2*sin(x)^3 + sin(x)^5 sage: cos(2*x + var('y')).expand_trig() -sin(2*x)*sin(y) + cos(2*x)*cos(y) cos(2*x)*cos(y) - sin(2*x)*sin(y) We illustrate various options to this function:: sage: f = sin(sin(3*cos(2*x))*x) sage: f.expand_trig() sin(-(sin(cos(2*x))^3 - 3*sin(cos(2*x))*cos(cos(2*x))^2)*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(((sin(sin(x)^2)*cos(cos(x)^2) - sin(cos(x)^2)*cos(sin(x)^2))^3 - 3*(sin(sin(x)^2)*cos(cos(x)^2) - sin(cos(x)^2)*cos(sin(x)^2))*(sin(sin(x)^2)*sin(cos(x)^2) + cos(sin(x)^2)*cos(cos(x)^2))^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) 2*sin(x)*cos(x) 2*cos(x)*sin(x) sage: sin(2 + x).expand_trig(plus=False) sin(x + 2) sage: sin(2 + x).expand_trig(plus=True) sin(2)*cos(x) + sin(x)*cos(2) cos(x)*sin(2) + cos(2)*sin(x) sage: sin(x/2).expand_trig(half_angles=False) sin(1/2*x) sage: sin(x/2).expand_trig(half_angles=True) sqrt(-1/2*cos(x) + 1/2)*(-1)^floor(1/2*x/pi) (-1)^floor(1/2*x/pi)*sqrt(-1/2*cos(x) + 1/2) ALIASES: sage: y=var('y') sage: f=sin(x)*cos(x)^3+sin(y)^2 sage: f.reduce_trig() 1/4*sin(2*x) + 1/8*sin(4*x) - 1/2*cos(2*y) + 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 """ {$0: x + y} sage: t = ((a+b)*(a+c)).match((a+w0)*(a+w1)) sage: t[w0], t[w1] (b, c) (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))    # surprising? 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] sage: w0 = SR.wild(0); w1 = SR.wild(1) sage: (sin(x)*sin(y)).find(sin(w0)) [sin(x), sin(y)] [sin(y), sin(x)] sage: ((sin(x)+sin(y))*(a+b)).expand().find(sin(w0)) [sin(x), sin(y)] [sin(y), sin(x)] 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(cmp) return res def has(self, pattern): (x + y)^3 + b^2 + c sage: t.subs({w0^2: w0^3}) (x + y)^3 + a^3 + b^3 a^3 + b^3 + (x + y)^3 # substitute with a relational expression sage: t.subs(w0^2 == w0^3) (x + y)^3 + a^3 + b^3 a^3 + b^3 + (x + y)^3 sage: t.subs(w0==w0^2) (x^2 + y^2)^18 + a^16 + b^16 (x, y, z, a, b, c, d, f) sage: w0 = SR.wild(0); w1 = SR.wild(1) sage: (a^2 + b^2 + (x+y)^2)._subs_expr(w0^2 == w0^3) (x + y)^3 + a^3 + b^3 a^3 + b^3 + (x + y)^3 sage: (a^4 + b^4 + (x+y)^4)._subs_expr(w0^2 == w0^3) (x + y)^4 + a^4 + b^4 a^4 + b^4 + (x + y)^4 sage: (a^2 + b^4 + (x+y)^4)._subs_expr(w0^2 == w0^3) (x + y)^4 + a^3 + b^4 b^4 + (x + y)^4 + a^3 sage: ((a+b+c)^2)._subs_expr(a+b == x) (a + b + c)^2 sage: ((a+b+c)^2)._subs_expr(a+b+w0 == x+w0) sage: (sin(x)^2 + cos(x)^2)._subs_expr(sin(w0)^2+cos(w0)^2==1) 1 sage: (1 + sin(x)^2 + cos(x)^2)._subs_expr(sin(w0)^2+cos(w0)^2==1) sin(x)^2 + cos(x)^2 + 1 cos(x)^2 + sin(x)^2 + 1 sage: (17*x + sin(x)^2 + cos(x)^2)._subs_expr(w1 + sin(w0)^2+cos(w0)^2 == w1 + 1) 17*x + 1 sage: ((x-1)*(sin(x)^2 + cos(x)^2)^2)._subs_expr(sin(w0)^2+cos(w0)^2 == 1) x^4 + x sage: f = cos(x^2) + sin(x^2) sage: f.subs_expr(x^2 == x) sin(x) + cos(x) cos(x) + sin(x) :: sage: f(x,y,t) = cos(x) + sin(y) + x^2 + y^2 + t sage: f.subs_expr(y^2 == t) (x, y, t) |--> x^2 + 2*t + sin(y) + cos(x) (x, y, t) |--> x^2 + 2*t + cos(x) + sin(y) The following seems really weird, but it *is* what Maple does:: sage: f.subs_expr(x^2 + y^2 == t) (x, y, t) |--> x^2 + y^2 + t + sin(y) + cos(x) (x, y, t) |--> x^2 + y^2 + t + cos(x) + sin(y) sage: maple.eval('subs(x^2 + y^2 = t, cos(x) + sin(y) + x^2 + y^2 + t)')          # optional - maple 'cos(x)+sin(y)+x^2+y^2+t' sage: maxima.quit() sage: var('x,y,z') (x, y, z) sage: (x+y)(x=z^2, y=x^y) x^y + z^2 z^2 + x^y """ return self._parent._call_element_(self, *args, **kwds) sage: var('a,b,c,x,y') (a, b, c, x, y) sage: (a^2 + b^2 + (x+y)^2).operands() [(x + y)^2, a^2, b^2] [a^2, b^2, (x + y)^2] sage: (a^2).operands() [a, 2] sage: (a*b^2*c).operands() 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: x.add(x, hold=True) x + x sage: x.add(x, (2+x), hold=True) x + x + (x + 2) (x + 2) + x + x sage: x.add(x, (2+x), x, hold=True) x + x + (x + 2) + x (x + 2) + x + x + x sage: x.add(x, (2+x), x, 2*x, hold=True) x + x + (x + 2) + x + 2*x (x + 2) + 2*x + x + x + x To then evaluate again, we currently must use Maxima via :meth:simplify:: sage: x.mul(x, hold=True) x*x sage: x.mul(x, (2+x), hold=True) x*x*(x + 2) (x + 2)*x*x sage: x.mul(x, (2+x), x, hold=True) x*x*(x + 2)*x (x + 2)*x*x*x sage: x.mul(x, (2+x), x, 2*x, hold=True) x*x*(x + 2)*x*(2*x) (2*x)*(x + 2)*x*x*x To then evaluate again, we currently must use Maxima via :meth:simplify:: sage: f.coefficient(sin(x*y)) x^3 + 2/x sage: f.collect(sin(x*y)) (x^3 + 2/x)*sin(x*y) + a*x + x*y + x/y + 100 a*x + x*y + (x^3 + 2/x)*sin(x*y) + x/y + 100 sage: var('a, x, y, z') (a, x, y, z) sage: bool(p.poly(a) == (x-a*sqrt(2))^2 + x + 1) True sage: p.poly(x) -(2*sqrt(2)*a - 1)*x + 2*a^2 + x^2 + 1 2*a^2 - (2*sqrt(2)*a - 1)*x + x^2 + 1 """ from sage.symbolic.ring import SR f = self._maxima_() sage: R = SR[x] sage: a = R(sqrt(2) + x^3 + y) sage: a y + sqrt(2) + x^3 x^3 + y + sqrt(2) sage: type(a) sage: a.degree() sage: lcm(x^100-y^100, x^10-y^10) -x^100 + y^100 sage: lcm(expand( (x^2+17*x+3/7*y)*(x^5 - 17*y + 2/3) ), expand((x^13+17*x+3/7*y)*(x^5 - 17*y + 2/3)) ) 1/21*(21*x^7 + 357*x^6 + 9*x^5*y - 357*x^2*y + 14*x^2 - 6069*x*y - 153*y^2 + 238*x + 6*y)*(21*x^18 - 357*x^13*y + 14*x^13 + 357*x^6 + 9*x^5*y - 6069*x*y - 153*y^2 + 238*x + 6*y)/(3*x^5 - 51*y + 2) 1/21*(21*x^18 - 357*x^13*y + 14*x^13 + 357*x^6 + 9*x^5*y - 6069*x*y - 153*y^2 + 238*x + 6*y)*(21*x^7 + 357*x^6 + 9*x^5*y - 357*x^2*y + 14*x^2 - 6069*x*y - 153*y^2 + 238*x + 6*y)/(3*x^5 - 51*y + 2) TESTS: sage: x,y,z = var('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 + (4*y + z)*x + 20*y^2 + 21*y*z + 4*z^2 x^2*y^2*z^2 + x*(4*y + z) + 20*y^2 + 21*y*z + 4*z^2 Here we do the same thing for y and z; however, note that we don't factor the y^{2} and z^{2} terms before sage: f.collect(y) (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 + (x + 21*y)*z + 4*x*y + 20*y^2 (x^2*y^2 + 4)*z^2 + 4*x*y + 20*y^2 + (x + 21*y)*z Sometimes, we do have to call :meth:expand() on the expression first to achieve the desired result:: sage: f.collect(x) x^2 + x*y - x*z - y*z sage: f.expand().collect(x) (y - z)*x + x^2 - y*z x^2 + x*(y - z) - y*z TESTS: (a, b) sage: f = log(a + b*I) sage: f.imag_part() arctan2(real_part(b) + imag_part(a), real_part(a) - imag_part(b)) arctan2(imag_part(a) + real_part(b), -imag_part(b) + real_part(a)) Using the hold parameter it is possible to prevent automatic evaluation:: 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: x.factorial() factorial(x) sage: (x^2+y^3).factorial() factorial(x^2 + y^3) factorial(y^3 + x^2) To prevent automatic evaluation use the hold argument:: sage: f = x*(x-1)/(x^2 - 7) + y^2/(x^2-7) + 1/(x+1) + b/a + c/a sage: f.normalize() (a*x^3 + a*x*y^2 + b*x^3 + c*x^3 + a*x^2 + a*y^2 + b*x^2 + c*x^2 - a*x - 7*b*x - 7*c*x - 7*a - 7*b - 7*c)/((x + 1)*(x^2 - 7)*a) (a*x^3 + b*x^3 + c*x^3 + a*x*y^2 + a*x^2 + b*x^2 + c*x^2 + a*y^2 - a*x - 7*b*x - 7*c*x - 7*a - 7*b - 7*c)/((x^2 - 7)*a*(x + 1)) ALGORITHM: Uses GiNaC. 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 = e^(I*x) sage: f.rectform() I*sin(x) + cos(x) cos(x) + I*sin(x) TESTS: EXAMPLES:: sage: f = sin(x)^2 + cos(x)^2; f sin(x)^2 + cos(x)^2 cos(x)^2 + sin(x)^2 sage: f.simplify() sin(x)^2 + cos(x)^2 cos(x)^2 + sin(x)^2 sage: f.simplify_trig() 1 sage: h = sin(x)*csc(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) sage: y = var('y') sage: g = (x^(y/2) + 1)^2*(x^(y/2) - 1)^2/(x^y - 1) sage: g.simplify_rational(algorithm='simple') -(2*x^y - x^(2*y) - 1)/(x^y - 1) (x^(2*y) - 2*x^y + 1)/(x^y - 1) sage: g.simplify_rational() x^y - 1 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 + 1)*x + (x + 2)^2)/((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 factorial(-k + n)*factorial(k)*binomial(n, 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: f = log(x)+log(y)-1/3*log((x+1)) sage: f.simplify_log() -1/3*log(x + 1) + log(x*y) log(x*y) - 1/3*log(x + 1) sage: f.simplify_log('ratios') log(x*y/(x + 1)^(1/3)) 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 - y)*(x^2 + x*y + y^2) (x^2 + x*y + y^2)*(x - y) sage: factor(-8*y - 4*x + z^2*(2*y + x)) (z - 2)*(z + 2)*(x + 2*y) (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*(y - 1)*(x^2 + 2*x + 1)/(y + 1) 1/36*(x^2 + 2*x + 1)*(y - 1)/(y + 1) If you are factoring a polynomial with rational coefficients (and dontfactor is empty) the factorization is done using Singular sage: var('x,y') (x, y) sage: (x^99 + y^99).factor() (x + y)*(x^2 - x*y + y^2)*(x^6 - x^3*y^3 + y^6)*... (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 - y)*(x^2 + x*y + y^2) (x^2 + x*y + y^2)*(x - y) Notice that the -1 factor is separated out:: sage: f.factor_list() [(x - y, 1), (x^2 + x*y + y^2, 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() [(z - 2, 1), (z + 2, 1), (x + 2*y, 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() -(x - sin(x))^3*(4*u^3 - 2*u*v^2 + v^2)^2*u^3 -(4*u^3 - 2*u*v^2 + v^2)^2*u^3*(x - sin(x))^3 sage: g = f.factor_list(); g [(x - sin(x), 3), (4*u^3 - 2*u*v^2 + v^2, 2), (u, 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 = f/(36*(1 + 2*y + y^2)); g 1/36*(x^2*y^2 + 2*x*y^2 - x^2 + y^2 - 2*x - 1)/(y^2 + 2*y + 1) sage: g.factor(dontfactor=[x]) 1/36*(y - 1)*(x^2 + 2*x + 1)/(y + 1) 1/36*(x^2 + 2*x + 1)*(y - 1)/(y + 1) sage: g.factor_list(dontfactor=[x]) [(y - 1, 1), (y + 1, -1), (x^2 + 2*x + 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:: EXAMPLES:: sage: g = factor(x^3 - 1); g (x - 1)*(x^2 + x + 1) (x^2 + x + 1)*(x - 1) sage: v = g._factor_list(); v [(x - 1, 1), (x^2 + x + 1, 1)] [(x^2 + x + 1, 1), (x - 1, 1)] sage: type(v) """ sage: var('a,b,c,x') (a, b, c, x) sage: (a*x^2 + b*x + c).roots(x) [(-1/2*(b + sqrt(-4*a*c + b^2))/a, 1), (-1/2*(b - sqrt(-4*a*c + b^2))/a, 1)] [(-1/2*(b + sqrt(b^2 - 4*a*c))/a, 1), (-1/2*(b - sqrt(b^2 - 4*a*c))/a, 1)] By default, all the roots are required to be explicit rather than implicit. To get implicit roots, pass explicit_solutions=False ... RuntimeError: no explicit roots found sage: f.roots(explicit_solutions=False) [((2^(8/9) - 2^(1/9) + x^(8/9) - x^(1/9))/(2^(8/9) - 2^(1/9)), 1)] [((2^(8/9) + x^(8/9) - 2^(1/9) - x^(1/9))/(2^(8/9) - 2^(1/9)), 1)] Another example, but involving a degree 5 poly whose roots don't get computed explicitly:: (f6, f5, f4, x) sage: e=15*f6*x^2 + 5*f5*x + f4 sage: res = e.roots(x); res [(-1/30*(5*f5 + sqrt(-60*f4*f6 + 25*f5^2))/f6, 1), (-1/30*(5*f5 - sqrt(-60*f4*f6 + 25*f5^2))/f6, 1)] [(-1/30*(5*f5 + sqrt(25*f5^2 - 60*f4*f6))/f6, 1), (-1/30*(5*f5 - sqrt(25*f5^2 - 60*f4*f6))/f6, 1)] sage: e.subs(x=res[0][0]).is_zero() True """ 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: (k * binomial(n, k)).sum(k, 1, n) n*2^(n - 1) 2^(n - 1)*n :: sage: f*(-2/3) -2/3*x - 2 < -2/3*y + 4/3 sage: f*(-pi) -(x + 3)*pi < -(y - 2)*pi -pi*(x + 3) < -pi*(y - 2) Since the direction of the inequality never changes when doing arithmetic with equations, you can multiply or divide the
• ## 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/36*Ei(-9*I*x) - 1/36*Ei(9*I*x) + 1/44*Ei(11*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(t*cos(-theta*t),(t,-oo,oo)) integrate(t*cos(t*theta), t, -Infinity, +Infinity) Check if #6189 is fixed (which, by the way, also demonstrates it's not always good to expand):: Check if #6189 is fixed:: sage: n = N; n 0.000000000000000 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 sage: integrate( (F(x)-G(x))^2, x, -infinity, infinity).n()# abstol 1e-6 0 This was broken before Maxima 5.20:: sage: actual_result = integral(e^(-1/x^2), x, 0, 1) sage: actual_result.full_simplify() ((e*erf(1) - e)*sqrt(pi) + 1)*e^(-1) (sqrt(pi)*(erf(1)*e - e) + 1)*e^(-1) sage: ideal_result = 1/2*gamma(-1/2, 1) sage: error = actual_result - ideal_result sage: error.numerical_approx() # abs tol 1e-10
• ## 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/random_tests.py

diff --git a/sage/symbolic/random_tests.py b/sage/symbolic/random_tests.py
 a sage: for i,j in CartesianProduct(range(0,3),range(0,3)): ...       cmp[i,j] = x[i].__cmp__(x[j]) sage: cmp [ 0  1  1] [-1  0 -1] [-1  1  0] [ 0 -1 -1] [ 1  0 -1] [ 1  1  0] """ from sage.matrix.constructor import matrix from sage.combinat.cartesian_product import CartesianProduct
• ## 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)
• ## sage/symbolic/units.py

diff --git a/sage/symbolic/units.py b/sage/symbolic/units.py
 a You can also convert quantities of units:: sage: sage.symbolic.units.convert(cos(50) * units.angles.radian, units.angles.degree) (180*cos(50)/pi)*degree degree*(180*cos(50)/pi) sage: sage.symbolic.units.convert(cos(30) * units.angles.radian, units.angles.degree).polynomial(RR) 8.83795706233228*degree sage: sage.symbolic.units.convert(50 * units.length.light_year / units.time.year, units.length.foot / units.time.second) Quantities may contain variables (not for temperature conversion, though):: sage: sage.symbolic.units.convert(50 * x * units.area.square_meter, units.area.acre) (1953125/158080329*x)*acre acre*(1953125/158080329*x) """ base_target = target z = {}