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

Commit

Permalink
Ticket #31796 : make maxima output parseable.
Browse files Browse the repository at this point in the history
- maxima.py : replace all whitespace sequences by a single space.
- maxima_lib : a single space joins the strings tepresenting the elements.
- Check and update the doctests and docstrings in various places :
    * src/doc/de/tutorial/tour_algebra.rst
    * src/doc/en/constructions/linear_algebra.rst
    * src/doc/en/tutorial/tour_algebra.rst
    * src/doc/es/tutorial/tour_algebra.rst
    * src/doc/fr/tutorial/tour_algebra.rst
    * src/doc/ja/tutorial/tour_algebra.rst
    * src/doc/pt/tutorial/tour_algebra.rst
    * src/doc/ru/tutorial/tour_algebra.rst
    * src/sage/calculus/calculus.py
    * src/sage/functions/bessel.py
    * src/sage/functions/orthogonal_polys.py
    * src/sage/interfaces/maxima.py
    * src/sage/interfaces/maxima_abstract.py
    * src/sage/interfaces/maxima_lib.py
    * src/sage/symbolic/assumptions.py
    * src/sage/symbolic/expression_conversions.py
- Document that output is parseable, doctests.

Note : space placement of MaximaElement conversions appears to be semi-random.
Thefore : src/sage/symbolic/assumptions.py : reformat the assumptions list.
To be seen in a followup ticket.
  • Loading branch information
EmmanuelCharpentier committed May 8, 2021
1 parent c27d4d6 commit 5f31eeb
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 60 deletions.
8 changes: 4 additions & 4 deletions src/doc/de/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Lösung: Berechnen Sie die Laplace-Transformierte der ersten Gleichung

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

Das ist schwierig zu lesen, es besagt jedoch, dass

Expand All @@ -225,9 +225,9 @@ Laplace-Transformierte der zweiten Gleichung:

::

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

Dies besagt

Expand Down
2 changes: 1 addition & 1 deletion src/doc/en/constructions/linear_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ Another approach is to use the interface with Maxima:
sage: A = maxima("matrix ([1, -4], [1, -1])")
sage: eig = A.eigenvectors()
sage: eig
[[[-sqrt(3)*%i,sqrt(3)*%i],[1,1]],[[[1,(sqrt(3)*%i+1)/4]],[[1,-(sqrt(3)*%i-1)/4]]]]
[[[-sqrt(3)*%i,sqrt(3)*%i],[1,1]], [[[1,(sqrt(3)*%i+1)/4]],[[1,-(sqrt(3)*%i-1)/4]]]]

This tells us that :math:`\vec{v}_1 = [1,(\sqrt{3}i + 1)/4]` is
an eigenvector of :math:`\lambda_1 = - \sqrt{3}i` (which occurs
Expand Down
4 changes: 2 additions & 2 deletions src/doc/en/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ the notation :math:`x=x_{1}`, :math:`y=x_{2}`):

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

This is hard to read, but it says that

Expand All @@ -233,7 +233,7 @@ Laplace transform of the second equation:

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
(-%at('diff(y(t),t,1),t = 0))+s^2*'laplace(y(t),t,s) +2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s) -y(0)*s

This says

Expand Down
4 changes: 2 additions & 2 deletions src/doc/es/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ la notación :math:`x=x_{1}`, :math:`y=x_{2}`):

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

El resultado puede ser difícil de leer, pero significa que

Expand All @@ -213,7 +213,7 @@ Toma la transformada de Laplace de la segunda ecuación:

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
(-%at('diff(y(t),t,1),t = 0))+s^2*'laplace(y(t),t,s) +2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s) -y(0)*s

Esto dice

Expand Down
4 changes: 2 additions & 2 deletions src/doc/fr/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Solution : Considérons la transformée de Laplace de la première équation

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

La réponse n'est pas très lisible, mais elle signifie que

Expand All @@ -198,7 +198,7 @@ la seconde équation :

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
(-%at('diff(y(t),t,1),t = 0))+s^2*'laplace(y(t),t,s) +2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s) -y(0)*s

Ceci signifie

Expand Down
8 changes: 4 additions & 4 deletions src/doc/ja/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Sageを使って常微分方程式を研究することもできる. :math:`x'

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

この出力は読みにくいけれども,意味しているのは

Expand All @@ -226,9 +226,9 @@ Sageを使って常微分方程式を研究することもできる. :math:`x'

::

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

意味するところは

Expand Down
4 changes: 2 additions & 2 deletions src/doc/pt/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ equação (usando a notação :math:`x=x_{1}`, :math:`y=x_{2}`):

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

O resultado é um pouco difícil de ler, mas diz que

Expand All @@ -221,7 +221,7 @@ calcule a transformada de Laplace da segunda equação:

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
(-%at('diff(y(t),t,1),t = 0))+s^2*'laplace(y(t),t,s) +2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s) -y(0)*s

O resultado significa que

Expand Down
4 changes: 2 additions & 2 deletions src/doc/ru/tutorial/tour_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Sage может использоваться для решения диффер

sage: de1 = maxima("2*diff(x(t),t, 2) + 6*x(t) - 2*y(t)")
sage: lde1 = de1.laplace("t","s"); lde1
2*((-%at('diff(x(t),t,1),t=0))+s^2*'laplace(x(t),t,s)-x(0)*s)-2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)
2*((-%at('diff(x(t),t,1),t = 0))+s^2*'laplace(x(t),t,s)-x(0)*s) -2*'laplace(y(t),t,s)+6*'laplace(x(t),t,s)

Данный результат тяжело читаем, однако должен быть понят как

Expand All @@ -212,7 +212,7 @@ Sage может использоваться для решения диффер

sage: de2 = maxima("diff(y(t),t, 2) + 2*y(t) - 2*x(t)")
sage: lde2 = de2.laplace("t","s"); lde2
(-%at('diff(y(t),t,1),t=0))+s^2*'laplace(y(t),t,s)+2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s)-y(0)*s
(-%at('diff(y(t),t,1),t = 0))+s^2*'laplace(y(t),t,s) +2*'laplace(y(t),t,s)-2*'laplace(x(t),t,s) -y(0)*s

Результат:

Expand Down
2 changes: 1 addition & 1 deletion src/sage/calculus/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,7 +2081,7 @@ def symbolic_expression_from_maxima_string(x, equals_sub=False, maxima=maxima):
sage: sefms('?%at(f(x),x=2)#1')
f(2) != 1
sage: a = sage.calculus.calculus.maxima("x#0"); a
x#0
x # 0
sage: a.sage()
x != 0
Expand Down
4 changes: 2 additions & 2 deletions src/sage/functions/bessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,9 @@ def Bessel(*args, **kwds):
sage: x,y = var('x,y')
sage: f = maxima(Bessel(typ='K')(x,y))
sage: f.derivative('_SAGE_VAR_x')
(%pi*csc(%pi*_SAGE_VAR_x)*('diff(bessel_i(-_SAGE_VAR_x,_SAGE_VAR_y),_SAGE_VAR_x,1)-'diff(bessel_i(_SAGE_VAR_x,_SAGE_VAR_y),_SAGE_VAR_x,1)))/2-%pi*bessel_k(_SAGE_VAR_x,_SAGE_VAR_y)*cot(%pi*_SAGE_VAR_x)
(%pi*csc(%pi*_SAGE_VAR_x) *('diff(bessel_i(-_SAGE_VAR_x,_SAGE_VAR_y),_SAGE_VAR_x,1) -'diff(bessel_i(_SAGE_VAR_x,_SAGE_VAR_y),_SAGE_VAR_x,1))) /2 -%pi*bessel_k(_SAGE_VAR_x,_SAGE_VAR_y)*cot(%pi*_SAGE_VAR_x)
sage: f.derivative('_SAGE_VAR_y')
-(bessel_k(_SAGE_VAR_x+1,_SAGE_VAR_y)+bessel_k(_SAGE_VAR_x-1,_SAGE_VAR_y))/2
-(bessel_k(_SAGE_VAR_x+1,_SAGE_VAR_y)+bessel_k(_SAGE_VAR_x-1, _SAGE_VAR_y))/2
Compute the particular solution to Bessel's Differential Equation that
satisfies `y(1) = 1` and `y'(1) = 1`, then verify the initial conditions
Expand Down
2 changes: 1 addition & 1 deletion src/sage/functions/orthogonal_polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ def __init__(self):
sage: maxima(gen_laguerre(1,2,x, hold=True))
3*(1-_SAGE_VAR_x/3)
sage: maxima(gen_laguerre(n, a, gen_laguerre(n, a, x)))
gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,_SAGE_VAR_x))
gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a, gen_laguerre(_SAGE_VAR_n,_SAGE_VAR_a,_SAGE_VAR_x))
"""
OrthogonalFunction.__init__(self, "gen_laguerre", nargs=3, latex_name=r"L",
conversions={'maxima':'gen_laguerre', 'mathematica':'LaguerreL',
Expand Down
41 changes: 26 additions & 15 deletions src/sage/interfaces/maxima.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,28 @@
sage: f = maxima('(x + 3*y + x^2*y)^3')
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
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
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
(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
sage: h.factor()
(3*y*z^2+5*z+25*y)^3/z^6
::
sage: eqn = maxima(['a+b*c=1', 'b-a*c=0', 'a+b=5'])
sage: s = eqn.solve('[a,b,c]'); s
[[a=-(sqrt(79)*%i-11)/4,b=(sqrt(79)*%i+9)/4,c=(sqrt(79)*%i+1)/10],[a=(sqrt(79)*%i+11)/4,b=-(sqrt(79)*%i-9)/4,c=-(sqrt(79)*%i-1)/10]]
[[a = -(sqrt(79)*%i-11)/4,b = (sqrt(79)*%i+9)/4, c = (sqrt(79)*%i+1)/10], [a = (sqrt(79)*%i+11)/4,b = -(sqrt(79)*%i-9)/4, 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=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::
Expand Down Expand Up @@ -197,9 +198,9 @@
sage: f = maxima('x^3 * %e^(k*x) * sin(w*x)'); f
x^3*%e^(k*x)*sin(w*x)
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)
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)
::
Expand Down Expand Up @@ -270,7 +271,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)
Expand All @@ -286,7 +287,7 @@
::
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::
Expand Down Expand Up @@ -460,6 +461,16 @@
sage: test.operator()._latex_() == 'C_+'
True
Test that the output is parseable (:trac:`31796`)::
sage: foo = maxima('a and (b or c)') ; foo
a and (b or c)
sage: bar = maxima(foo) ; bar
a and (b or c)
sage: bar == foo
True
"""

#*****************************************************************************
Expand Down Expand Up @@ -681,9 +692,9 @@ def _expect_expr(self, expr=None, timeout=None):
before integral or limit evaluation, for example):
Is a positive or negative?
sage: maxima.assume('a>0')
[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):
...
Expand All @@ -692,11 +703,11 @@ def _expect_expr(self, expr=None, timeout=None):
integral or limit evaluation, for example):
Is n equal to -1?
sage: maxima.assume('n+1>0')
[n>-1]
[n > -1]
sage: maxima('integrate(x^n,x)')
x^(n+1)/(n+1)
sage: maxima.forget([fact for fact in maxima.facts()])
[[a>0,n>-1]]
[[a > 0,n > -1]]
sage: maxima.facts()
[]
sage: var('a')
Expand Down Expand Up @@ -814,7 +825,7 @@ def _eval_line(self, line, allow_use_file=False,
m = r.search(out)
if m is not None:
out = out[m.end():]
return re.sub(r'\s+', '', out)
return re.sub(r'\s+', ' ', out).rstrip()

def _synchronize(self):
"""
Expand Down
18 changes: 9 additions & 9 deletions src/sage/interfaces/maxima_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def _equality_symbol(self):
sage: var('x y')
(x, y)
sage: maxima(x == y)
_SAGE_VAR_x=_SAGE_VAR_y
_SAGE_VAR_x = _SAGE_VAR_y
"""
return '='

Expand All @@ -533,7 +533,7 @@ def _inequality_symbol(self):
sage: maxima._inequality_symbol()
'#'
sage: maxima((x != 1))
_SAGE_VAR_x#1
_SAGE_VAR_x # 1
"""
return '#'

Expand Down Expand Up @@ -855,13 +855,13 @@ def de_solve(self, de, vars, ics=None):
EXAMPLES::
sage: maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'], [1,1,1])
y=3*x-2*%e^(x-1)
y = 3*x-2*%e^(x-1)
sage: maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'])
y=%k1*%e^x+%k2*%e^-x+3*x
y = %k1*%e^x+%k2*%e^-x+3*x
sage: maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'])
y=(%c-3*((-x)-1)*%e^-x)*%e^x
y = (%c-3*((-x)-1)*%e^-x)*%e^x
sage: maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'],[1,1])
y=-%e^-1*(5*%e^x-3*%e*x-3*%e)
y = -%e^-1*(5*%e^x-3*%e*x-3*%e)
"""
if not isinstance(vars, str):
str_vars = '%s, %s'%(vars[1], vars[0])
Expand Down Expand Up @@ -899,14 +899,14 @@ def de_solve_laplace(self, de, vars, ics=None):
sage: maxima.clear('x'); maxima.clear('f')
sage: maxima.de_solve_laplace("diff(f(x),x,2) = 2*diff(f(x),x)-f(x)", ["x","f"], [0,1,2])
f(x)=x*%e^x+%e^x
f(x) = x*%e^x+%e^x
::
sage: maxima.clear('x'); maxima.clear('f')
sage: f = maxima.de_solve_laplace("diff(f(x),x,2) = 2*diff(f(x),x)-f(x)", ["x","f"])
sage: f
f(x)=x*%e^x*('at('diff(f(x),x,1),x=0))-f(0)*x*%e^x+f(0)*%e^x
f(x) = x*%e^x*('at('diff(f(x),x,1),x = 0))-f(0)*x*%e^x+f(0)*%e^x
sage: print(f)
!
x d ! x x
Expand Down Expand Up @@ -946,7 +946,7 @@ def solve_linear(self, eqns,vars):
sage: eqns = ["x + z = y","2*a*x - y = 2*a^2","y - 2*z = 2"]
sage: vars = ["x","y","z"]
sage: maxima.solve_linear(eqns, vars)
[x=a+1,y=2*a,z=a-1]
[x = a+1,y = 2*a,z = a-1]
"""
eqs = "["
for i in range(len(eqns)):
Expand Down
15 changes: 12 additions & 3 deletions src/sage/interfaces/maxima_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
sage: maxima_calculus("besselexpand:true")
true
The output is parseable (i. e. :trac:`31796` is fixed)::
sage: foo = maxima_calculus('a and (b or c)') ; foo
a and (b or c)
sage: bar = maxima_calculus(foo) ; bar
a and (b or c)
sage: bar == foo
True
"""

# ****************************************************************************
Expand Down Expand Up @@ -458,7 +467,7 @@ def _eval_line(self, line, locals=None, reformat=True, **kwds):
maxima_eval("#$%s$" % statement)
if not reformat:
return result
return ''.join([x.strip() for x in result.split()])
return ' '.join([x.strip() for x in result.split()])

eval = _eval_line

Expand Down Expand Up @@ -1394,12 +1403,12 @@ def max_at_to_sage(expr):
sage: from sage.interfaces.maxima_lib import maxima_lib, max_at_to_sage
sage: a=maxima_lib("'at(f(x,y,z),[x=1,y=2,z=3])")
sage: a
'at(f(x,y,z),[x=1,y=2,z=3])
'at(f(x,y,z),[x = 1,y = 2,z = 3])
sage: max_at_to_sage(a.ecl())
f(1, 2, 3)
sage: a=maxima_lib("'at(f(x,y,z),x=1)")
sage: a
'at(f(x,y,z),x=1)
'at(f(x,y,z),x = 1)
sage: max_at_to_sage(a.ecl())
f(1, y, z)
"""
Expand Down

0 comments on commit 5f31eeb

Please sign in to comment.