From 62b5825544b467e481c7a752604b8d45c64d9752 Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Fri, 28 Oct 2016 05:05:53 +0000 Subject: [PATCH] some more easy doctest fixes --- src/sage/combinat/combinat.py | 2 +- src/sage/functions/trig.py | 2 +- src/sage/interfaces/interface.py | 4 ++-- src/sage/interfaces/maxima.py | 32 ++++++++++++++++---------------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/sage/combinat/combinat.py b/src/sage/combinat/combinat.py index 6aa16f206f2..e3c6a55b183 100644 --- a/src/sage/combinat/combinat.py +++ b/src/sage/combinat/combinat.py @@ -486,7 +486,7 @@ def euler_number(n, algorithm='flint'): sage: [euler_number(i) for i in range(10)] [1, 0, -1, 0, 5, 0, -61, 0, 1385, 0] sage: maxima.eval("taylor (2/(exp(x)+exp(-x)), x, 0, 10)") - '1-x^2/2+5*x^4/24-61*x^6/720+277*x^8/8064-50521*x^10/3628800' + '1-x^2/2+(5*x^4)/24-(61*x^6)/720+(277*x^8)/8064-(50521*x^10)/3628800' sage: [euler_number(i)/factorial(i) for i in range(11)] [1, 0, -1/2, 0, 5/24, 0, -61/720, 0, 277/8064, 0, -50521/3628800] sage: euler_number(-1) diff --git a/src/sage/functions/trig.py b/src/sage/functions/trig.py index 9305b0fa1ad..217bbb4da33 100644 --- a/src/sage/functions/trig.py +++ b/src/sage/functions/trig.py @@ -828,7 +828,7 @@ def __init__(self): This is consistent with Python and Maxima:: sage: maxima.atan2(1,-1) - 3*%pi/4 + (3*%pi)/4 sage: math.atan2(1,-1) 2.356194490192345 diff --git a/src/sage/interfaces/interface.py b/src/sage/interfaces/interface.py index 95b4a91a7b1..1cad3bda570 100644 --- a/src/sage/interfaces/interface.py +++ b/src/sage/interfaces/interface.py @@ -1290,9 +1290,9 @@ def _add_(self, right): The Maxima variable ``x`` is different from the Sage symbolic variable:: sage: (f+maxima.cos(x)) - cos(_SAGE_VAR_x)+sin(x) + sin(x)+cos(_SAGE_VAR_x) sage: (f+maxima.cos(y)) - cos(_SAGE_VAR_y)+sin(x) + sin(x)+cos(_SAGE_VAR_y) Note that you may get unexpected results when calling symbolic expressions and not explicitly giving the variables:: diff --git a/src/sage/interfaces/maxima.py b/src/sage/interfaces/maxima.py index cda8532b7b0..c7ff8f8798c 100644 --- a/src/sage/interfaces/maxima.py +++ b/src/sage/interfaces/maxima.py @@ -150,7 +150,7 @@ sage: f.expand() x^6*y^3+9*x^4*y^3+27*x^2*y^3+27*y^3+3*x^5*y^2+18*x^3*y^2+27*x*y^2+3*x^4*y+9*x^2*y+x^3 sage: f.subst('x=5/z') - (5/z+25*y/z^2+3*y)^3 + (5/z+(25*y)/z^2+3*y)^3 sage: g = f.subst('x=5/z') sage: h = g.ratsimp(); h (27*y^3*z^6+135*y^2*z^5+(675*y^3+225*y)*z^4+(2250*y^2+125)*z^3+(5625*y^3+1875*y)*z^2+9375*y^2*z+15625*y^3)/z^6 @@ -161,19 +161,19 @@ sage: eqn = maxima(['a+b*c=1', 'b-a*c=0', 'a+b=5']) sage: s = eqn.solve('[a,b,c]'); s - [[a=(25*sqrt(79)*%i+25)/(6*sqrt(79)*%i-34),b=(5*sqrt(79)*%i+5)/(sqrt(79)*%i+11),c=(sqrt(79)*%i+1)/10],[a=(25*sqrt(79)*%i-25)/(6*sqrt(79)*%i+34),b=(5*sqrt(79)*%i-5)/(sqrt(79)*%i-11),c=-(sqrt(79)*%i-1)/10]] + [[a=50/(sqrt(79)*%i+11),b=(5*sqrt(79)*%i+5)/(sqrt(79)*%i+11),c=(sqrt(79)*%i+1)/10],[a=-50/(sqrt(79)*%i-11),b=(5*sqrt(79)*%i-5)/(sqrt(79)*%i-11),c=-(sqrt(79)*%i-1)/10]] Here is an example of solving an algebraic equation:: sage: maxima('x^2+y^2=1').solve('y') [y=-sqrt(1-x^2),y=sqrt(1-x^2)] sage: maxima('x^2 + y^2 = (x^2 - y^2)/sqrt(x^2 + y^2)').solve('y') - [y=-sqrt((-y^2-x^2)*sqrt(y^2+x^2)+x^2),y=sqrt((-y^2-x^2)*sqrt(y^2+x^2)+x^2)] + [y=-sqrt(((-y^2)-x^2)*sqrt(y^2+x^2)+x^2),y=sqrt(((-y^2)-x^2)*sqrt(y^2+x^2)+x^2)] You can even nicely typeset the solution in latex:: sage: latex(s) - \left[ \left[ a={{25\,\sqrt{79}\,i+25}\over{6\,\sqrt{79}\,i-34}} , b={{5\,\sqrt{79}\,i+5}\over{\sqrt{79}\,i+11}} , c={{\sqrt{79}\,i+1 }\over{10}} \right] , \left[ a={{25\,\sqrt{79}\,i-25}\over{6\, \sqrt{79}\,i+34}} , b={{5\,\sqrt{79}\,i-5}\over{\sqrt{79}\,i-11}} , c=-{{\sqrt{79}\,i-1}\over{10}} \right] \right] + \left[ \left[ a={{50}\over{\sqrt{79}\,i+11}} , b={{5\,\sqrt{79}\,i+ 5}\over{\sqrt{79}\,i+11}} , c={{\sqrt{79}\,i+1}\over{10}} \right] , \left[ a=-{{50}\over{\sqrt{79}\,i-11}} , b={{5\,\sqrt{79}\,i-5 }\over{\sqrt{79}\,i-11}} , c=-{{\sqrt{79}\,i-1}\over{10}} \right] \right] To have the above appear onscreen via ``xdvi``, type ``view(s)``. (TODO: For OS X should create pdf output @@ -199,7 +199,7 @@ sage: f.diff('x') k*x^3*%e^(k*x)*sin(w*x)+3*x^2*%e^(k*x)*sin(w*x)+w*x^3*%e^(k*x)*cos(w*x) sage: f.integrate('x') - (((k*w^6+3*k^3*w^4+3*k^5*w^2+k^7)*x^3+(3*w^6+3*k^2*w^4-3*k^4*w^2-3*k^6)*x^2+(-18*k*w^4-12*k^3*w^2+6*k^5)*x-6*w^4+36*k^2*w^2-6*k^4)*%e^(k*x)*sin(w*x)+((-w^7-3*k^2*w^5-3*k^4*w^3-k^6*w)*x^3+(6*k*w^5+12*k^3*w^3+6*k^5*w)*x^2+(6*w^5-12*k^2*w^3-18*k^4*w)*x-24*k*w^3+24*k^3*w)*%e^(k*x)*cos(w*x))/(w^8+4*k^2*w^6+6*k^4*w^4+4*k^6*w^2+k^8) + (((k*w^6+3*k^3*w^4+3*k^5*w^2+k^7)*x^3+(3*w^6+3*k^2*w^4-3*k^4*w^2-3*k^6)*x^2+((-18*k*w^4)-12*k^3*w^2+6*k^5)*x-6*w^4+36*k^2*w^2-6*k^4)*%e^(k*x)*sin(w*x)+(((-w^7)-3*k^2*w^5-3*k^4*w^3-k^6*w)*x^3+(6*k*w^5+12*k^3*w^3+6*k^5*w)*x^2+(6*w^5-12*k^2*w^3-18*k^4*w)*x-24*k*w^3+24*k^3*w)*%e^(k*x)*cos(w*x))/(w^8+4*k^2*w^6+6*k^4*w^4+4*k^6*w^2+k^8) :: @@ -208,12 +208,12 @@ 1 sage: g = maxima('f/sinh(k*x)^4') sage: g.taylor('x', 0, 3) - f/(k^4*x^4)-2*f/(3*k^2*x^2)+11*f/45-62*k^2*f*x^2/945 + x+x^3/6+(3*x^5)/40+(5*x^7)/112+(35*x^9)/1152 :: sage: maxima.taylor('asin(x)','x',0, 10) - x+x^3/6+3*x^5/40+5*x^7/112+35*x^9/1152 + x+x^3/6+(3*x^5)/40+(5*x^7)/112+(35*x^9)/1152 Examples involving matrices --------------------------- @@ -253,7 +253,7 @@ sage: _ = maxima.eval("f(t) := t*sin(t)") sage: maxima("laplace(f(t),t,s)") - 2*s/(s^2+1)^2 + (2*s)/(s^2+1)^2 :: @@ -270,7 +270,7 @@ sage: _ = maxima.eval("f(t) := t^5*exp(t)*sin(t)") sage: maxima("laplace(f(t),t,s)") - 360*(2*s-2)/(s^2-2*s+2)^4-480*(2*s-2)^3/(s^2-2*s+2)^5+120*(2*s-2)^5/(s^2-2*s+2)^6 + (360*(2*s-2))/(s^2-2*s+2)^4-(480*(2*s-2)^3)/(s^2-2*s+2)^5+(120*(2*s-2)^5)/(s^2-2*s+2)^6 sage: print(maxima("laplace(f(t),t,s)")) 3 5 360 (2 s - 2) 480 (2 s - 2) 120 (2 s - 2) @@ -286,17 +286,17 @@ :: sage: maxima("laplace(diff(x(t),t,2),t,s)") - -%at('diff(x(t),t,1),t=0)+s^2*'laplace(x(t),t,s)-x(0)*s + (-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s It is difficult to read some of these without the 2d representation:: sage: print(maxima("laplace(diff(x(t),t,2),t,s)")) - ! - d ! 2 - - -- (x(t))! + s laplace(x(t), t, s) - x(0) s - dt ! - !t = 0 + ! + d ! 2 + (- -- (x(t))! ) + s laplace(x(t), t, s) - x(0) s + dt ! + !t = 0 Even better, use ``view(maxima("laplace(diff(x(t),t,2),t,s)"))`` to see @@ -679,7 +679,7 @@ def _expect_expr(self, expr=None, timeout=None): sage: maxima.assume('a>0') [a>0] sage: maxima('integrate(1/(x^3*(a+b*x)^(1/3)),x)') - -b^2*log((b*x+a)^(2/3)+a^(1/3)*(b*x+a)^(1/3)+a^(2/3))/(9*a^(7/3))+2*b^2*atan((2*(b*x+a)^(1/3)+a^(1/3))/(sqrt(3)*a^(1/3)))/(3^(3/2)*a^(7/3))+2*b^2*log((b*x+a)^(1/3)-a^(1/3))/(9*a^(7/3))+(4*b^2*(b*x+a)^(5/3)-7*a*b^2*(b*x+a)^(2/3))/(6*a^2*(b*x+a)^2-12*a^3*(b*x+a)+6*a^4) + (-(b^2*log((b*x+a)^(2/3)+a^(1/3)*(b*x+a)^(1/3)+a^(2/3)))/(9*a^(7/3)))+(2*b^2*atan((2*(b*x+a)^(1/3)+a^(1/3))/(sqrt(3)*a^(1/3))))/(3^(3/2)*a^(7/3))+(2*b^2*log((b*x+a)^(1/3)-a^(1/3)))/(9*a^(7/3))+(4*b^2*(b*x+a)^(5/3)-7*a*b^2*(b*x+a)^(2/3))/(6*a^2*(b*x+a)^2-12*a^3*(b*x+a)+6*a^4) sage: maxima('integrate(x^n,x)') Traceback (most recent call last): ...