Abstract interface to Maxima - Interpreter Interfaces

Skip to content
Back to top
View this page
Edit this page

# Abstract interface to Maxima

Maxima is a free GPL’d general purpose computer algebra system whose development started in 1968 at MIT. It contains symbolic manipulation algorithms, as well as implementations of special functions, including elliptic functions and generalized hypergeometric functions. Moreover, Maxima has implementations of many functions relating to the invariant theory of the symmetric group \(S_n\). (However, the commands for group invariants, and the corresponding Maxima documentation, are in French.) For many links to Maxima documentation see http://maxima.sourceforge.net/docs.shtml/.

AUTHORS:

- William Stein (2005-12): Initial version

- David Joyner: Improved documentation

- William Stein (2006-01-08): Fixed bug in parsing

- William Stein (2006-02-22): comparisons (following suggestion of David Joyner)

- William Stein (2006-02-24): greatly improved robustness by adding sequence numbers to IO bracketing in _eval_line

- Robert Bradshaw, Nils Bruin, Jean-Pierre Flori (2010,2011): Binary library interface

This is an abstract class implementing the functions shared between the Pexpect and library interfaces to Maxima.

class sage.interfaces.maxima_abstract.MaximaAbstract(name='maxima_abstract')

  Bases: `ExtraTabCompletion`, `Interface`

  Abstract interface to Maxima.

  INPUT:

  - `name` – string

  OUTPUT: the interface

  EXAMPLES:

  This class should not be instantiated directly, but should be used through its subclass MaximaLib (which is a singleton), or through the Pexpect interface Maxima.

  > sage: from sage.interfaces.maxima_abstract import MaximaAbstract sage: from sage.interfaces.maxima_lib import maxima sage: isinstance(maxima, MaximaAbstract) True

  completions(s, verbose=True)

    Return all commands that complete the command starting with the string `s`. This is like typing s[tab] in the Maxima interpreter.

    INPUT:

    - `s` – string

    - `verbose` – boolean (default: `True`)

    OUTPUT: array of strings

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: sorted(maxima.completions('gc', verbose=False))
        ['gc', 'gcd', 'gcdex', 'gcfactor', 'gctime']

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> sorted(maxima.completions('gc', verbose=False))
        ['gc', 'gcd', 'gcdex', 'gcfactor', 'gctime']

  console()

    Start the interactive Maxima console. This is a completely separate maxima session from this interface. To interact with this session, you should instead use `maxima.interact()`.

    OUTPUT: none

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.console()             # not tested (since we can't)
        Maxima 5.46.0 https://maxima.sourceforge.io
        using Lisp ECL 21.2.1
        Distributed under the GNU Public License. See the file COPYING.
        Dedicated to the memory of William Schelter.
        This is a development version of Maxima. The function bug_report()
        provides bug reporting information.
        (%i1)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.console()             # not tested (since we can't)
        Maxima 5.46.0 https://maxima.sourceforge.io
        using Lisp ECL 21.2.1
        Distributed under the GNU Public License. See the file COPYING.
        Dedicated to the memory of William Schelter.
        This is a development version of Maxima. The function bug_report()
        provides bug reporting information.
        (%i1)

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.interact()     # not tested
          --> Switching to Maxima <--
        maxima: 2+2
        4
        maxima:
          --> Exiting back to Sage <--

    [Python]

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.interact()     # not tested
          --> Switching to Maxima <--
        maxima: 2+2
        4
        maxima:
          --> Exiting back to Sage <--

  cputime(t=None)

    Return the amount of CPU time that this Maxima session has used.

    INPUT:

    - `t` – float (default: `None`); if var{t} is not None, then it returns the difference between the current CPU time and var{t}

    OUTPUT: float

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: t = maxima.cputime()
        sage: _ = maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'], [1,1,1])
        sage: maxima.cputime(t) # output random
        0.568913

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> t = maxima.cputime()
        >>> _ = maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'], [Integer(1),Integer(1),Integer(1)])
        >>> maxima.cputime(t) # output random
        0.568913

  de_solve(de, vars, ics=None)

    Solve a 1st or 2nd order ordinary differential equation (ODE) in two variables, possibly with initial conditions.

    INPUT:

    - `de` – string representing the ODE

    - `vars` – list of strings representing the two variables

    - `ics` – a triple of numbers [a,b1,b2] representing y(a)=b1, y’(a)=b2

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'], [1,1,1])
        y = 3*x-2*%e^(x-1)
        sage: maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'])
        y = 3*x+%e^-x*%k2+%e^x*%k1
        sage: maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'])
        y = %e^x*(%c-3*%e^-x*(-x-1))
        sage: maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'],[1,1])
        y = %e^-1*(3*%e*x-5*%e^x+3*%e)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'], [Integer(1),Integer(1),Integer(1)])
        y = 3*x-2*%e^(x-1)
        >>> maxima.de_solve('diff(y,x,2) + 3*x = y', ['x','y'])
        y = 3*x+%e^-x*%k2+%e^x*%k1
        >>> maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'])
        y = %e^x*(%c-3*%e^-x*(-x-1))
        >>> maxima.de_solve('diff(y,x) + 3*x = y', ['x','y'],[Integer(1),Integer(1)])
        y = %e^-1*(3*%e*x-5*%e^x+3*%e)

  de_solve_laplace(de, vars, ics=None)

    Solve an ordinary differential equation (ODE) using Laplace transforms.

    INPUT:

    - `de` – string representing the ODE (e.g., de = “diff(f(x),x,2)=diff(f(x),x)+sin(x)”)

    - `vars` – list of strings representing the variables (e.g., `vars = ["x","f"]`)

    - `ics` – list of numbers representing initial conditions, with symbols allowed which are represented by strings (eg, f(0)=1, f’(0)=2 is ics = [0,1,2])

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        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) = %e^x*x+%e^x

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.clear('x'); maxima.clear('f')
        >>> maxima.de_solve_laplace("diff(f(x),x,2) = 2*diff(f(x),x)-f(x)", ["x","f"], [Integer(0),Integer(1),Integer(2)])
        f(x) = %e^x*x+%e^x

    Sage

        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) = %e^x*x*('at('diff(f(x),x,1),x = 0))-%e^x*f(0)*x+%e^x*f(0)
        sage: print(f)
                                                                  │
                                                    x    d        │           x            x
                                           f(x) = %e  x (── (f(x))│     ) - %e  f(0) x + %e  f(0)
                                                         dx       │
                                                                  │x = 0

    [Python]

        >>> from sage.all import *
        >>> maxima.clear('x'); maxima.clear('f')
        >>> f = maxima.de_solve_laplace("diff(f(x),x,2) = 2*diff(f(x),x)-f(x)", ["x","f"])
        >>> f
        f(x) = %e^x*x*('at('diff(f(x),x,1),x = 0))-%e^x*f(0)*x+%e^x*f(0)
        >>> print(f)
                                                                  │
                                                    x    d        │           x            x
                                           f(x) = %e  x (── (f(x))│     ) - %e  f(0) x + %e  f(0)
                                                         dx       │
                                                                  │x = 0

    Note

    The second equation sets the values of \(f(0)\) and \(f'(0)\) in Maxima, so subsequent ODEs involving these variables will have these initial conditions automatically imposed.

  demo(s)

    Run Maxima’s demo for `s`.

    INPUT:

    - `s` – string

    OUTPUT: none

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.demo('cf') # not tested
        read and interpret file: .../share/maxima/5.34.1/demo/cf.dem

        At the '_' prompt, type ';' and <enter> to get next demonstration.
        frac1:cf([1,2,3,4])
        ...

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.demo('cf') # not tested
        read and interpret file: .../share/maxima/5.34.1/demo/cf.dem

        At the '_' prompt, type ';' and <enter> to get next demonstration.
        frac1:cf([1,2,3,4])
        ...

  describe(s)

    alias of `help()`.

  example(s)

    Return Maxima’s examples for `s`.

    INPUT:

    - `s` – string

    OUTPUT: Maxima’s examples for `s`

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.example('arrays')
        a[n]:=n*a[n-1]
                                        a  := n a
                                         n       n - 1
        a[0]:1
        a[5]
                                              120
        a[n]:=n
        a[6]
                                               6
        a[4]
                                              24
                                             done

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.example('arrays')
        a[n]:=n*a[n-1]
                                        a  := n a
                                         n       n - 1
        a[0]:1
        a[5]
                                              120
        a[n]:=n
        a[6]
                                               6
        a[4]
                                              24
                                             done

  function(args, defn, rep=None, latex=None)

    Return the Maxima function with given arguments and definition.

    INPUT:

    - `args` – string with variable names separated by commas

    - `defn` – string (or Maxima expression) that defines a function of the arguments in Maxima

    - `rep` – an optional string; if given, this is how the function will print

    OUTPUT: Maxima function

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: f = maxima.function('x', 'sin(x)')
        sage: f(3.2)  # abs tol 2e-16
        -0.058374143427579909
        sage: f = maxima.function('x,y', 'sin(x)+cos(y)')
        sage: f(2, 3.5)  # abs tol 2e-16
        sin(2)-0.9364566872907963
        sage: f
        sin(x)+cos(y)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> f = maxima.function('x', 'sin(x)')
        >>> f(RealNumber('3.2'))  # abs tol 2e-16
        -0.058374143427579909
        >>> f = maxima.function('x,y', 'sin(x)+cos(y)')
        >>> f(Integer(2), RealNumber('3.5'))  # abs tol 2e-16
        sin(2)-0.9364566872907963
        >>> f
        sin(x)+cos(y)

    Sage

        sage: g = f.integrate('z')
        sage: g
        (cos(y)+sin(x))*z
        sage: g(1,2,3)
        3*(cos(2)+sin(1))

    [Python]

        >>> from sage.all import *
        >>> g = f.integrate('z')
        >>> g
        (cos(y)+sin(x))*z
        >>> g(Integer(1),Integer(2),Integer(3))
        3*(cos(2)+sin(1))

    The function definition can be a Maxima object:

    Sage

        sage: an_expr = maxima('sin(x)*gamma(x)')
        sage: t = maxima.function('x', an_expr)
        sage: t
        gamma(x)*sin(x)
        sage: t(2)
         sin(2)
        sage: float(t(2))
        0.9092974268256817
        sage: loads(t.dumps())
        gamma(x)*sin(x)

    Python

        >>> from sage.all import *
        >>> an_expr = maxima('sin(x)*gamma(x)')
        >>> t = maxima.function('x', an_expr)
        >>> t
        gamma(x)*sin(x)
        >>> t(Integer(2))
         sin(2)
        >>> float(t(Integer(2)))
        0.9092974268256817
        >>> loads(t.dumps())
        gamma(x)*sin(x)

  help(s)

    Return Maxima’s help for `s`.

    INPUT:

    - `s` – string

    OUTPUT: Maxima’s help for `s`

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.help('gcd')
        -- Function: gcd (<p_1>, <p_2>, <x_1>, ...)
        ...

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.help('gcd')
        -- Function: gcd (<p_1>, <p_2>, <x_1>, ...)
        ...

  plot2d(*args)

    Plot a 2d graph using Maxima / gnuplot.

    maxima.plot2d(f, ‘[var, min, max]’, options)

    INPUT:

    - `f` – string representing a function (such as f=”sin(x)”) [var, xmin, xmax]

    - `options` – an optional string representing plot2d options in gnuplot format

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.plot2d('sin(x)','[x,-5,5]')   # not tested
        sage: opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-plot.eps"]'
        sage: maxima.plot2d('sin(x)','[x,-5,5]',opts)    # not tested

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.plot2d('sin(x)','[x,-5,5]')   # not tested
        >>> opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-plot.eps"]'
        >>> maxima.plot2d('sin(x)','[x,-5,5]',opts)    # not tested

    The eps file is saved in the current directory.

  plot2d_parametric(r, var, trange, nticks=50, options=None)

    Plot r = [x(t), y(t)] for t = tmin…tmax using gnuplot with options.

    INPUT:

    - `r` – string representing a function (such as r=”[x(t),y(t)]”)

    - `var` – string representing the variable (such as var = “t”)

    - `trange` – [tmin, tmax] are numbers with tmintmax

    - `nticks` – integer (default: 50)

    - `options` – an optional string representing plot2d options in gnuplot format

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.plot2d_parametric(["sin(t)","cos(t)"], "t",[-3.1,3.1])   # not tested

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.plot2d_parametric(["sin(t)","cos(t)"], "t",[-RealNumber('3.1'),RealNumber('3.1')])   # not tested

    Sage

        sage: opts = '[gnuplot_preamble, "set nokey"], [gnuplot_term, ps], [gnuplot_out_file, "circle-plot.eps"]'
        sage: maxima.plot2d_parametric(["sin(t)","cos(t)"], "t", [-3.1,3.1], options=opts)   # not tested

    [Python]

        >>> from sage.all import *
        >>> opts = '[gnuplot_preamble, "set nokey"], [gnuplot_term, ps], [gnuplot_out_file, "circle-plot.eps"]'
        >>> maxima.plot2d_parametric(["sin(t)","cos(t)"], "t", [-RealNumber('3.1'),RealNumber('3.1')], options=opts)   # not tested

    The eps file is saved to the current working directory.

    Here is another fun plot:

    Sage

        sage: maxima.plot2d_parametric(["sin(5*t)","cos(11*t)"], "t", [0,2*pi()], nticks=400)    # not tested

    Python

        >>> from sage.all import *
        >>> maxima.plot2d_parametric(["sin(5*t)","cos(11*t)"], "t", [Integer(0),Integer(2)*pi()], nticks=Integer(400))    # not tested

  plot3d(*args)

    Plot a 3d graph using Maxima / gnuplot.

    maxima.plot3d(f, ‘[x, xmin, xmax]’, ‘[y, ymin, ymax]’, ‘[grid, nx, ny]’, options)

    INPUT:

    - `f` – string representing a function (such as f=”sin(x)”) [var, min, max]

    - `args` should be of the form ‘[x, xmin, xmax]’, ‘[y, ymin, ymax]’, ‘[grid, nx, ny]’, options

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.plot3d('1 + x^3 - y^2', '[x,-2,2]', '[y,-2,2]', '[grid,12,12]')    # not tested
        sage: maxima.plot3d('sin(x)*cos(y)', '[x,-2,2]', '[y,-2,2]', '[grid,30,30]')   # not tested
        sage: opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-plot.eps"]'
        sage: maxima.plot3d('sin(x+y)', '[x,-5,5]', '[y,-1,1]', opts)    # not tested

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.plot3d('1 + x^3 - y^2', '[x,-2,2]', '[y,-2,2]', '[grid,12,12]')    # not tested
        >>> maxima.plot3d('sin(x)*cos(y)', '[x,-2,2]', '[y,-2,2]', '[grid,30,30]')   # not tested
        >>> opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-plot.eps"]'
        >>> maxima.plot3d('sin(x+y)', '[x,-5,5]', '[y,-1,1]', opts)    # not tested

    The eps file is saved in the current working directory.

  plot3d_parametric(r, vars, urange, vrange, options=None)

    Plot a 3d parametric graph with r=(x,y,z), x = x(u,v), y = y(u,v), z = z(u,v), for u = umin…umax, v = vmin…vmax using gnuplot with options.

    INPUT:

    - `x`, `y`, `z` – string representing a function (such as `x="u2+v2"`, …) vars is a list or two strings representing variables (such as vars = [“u”,”v”])

    - `urange` – [umin, umax]

    - `vrange` – [vmin, vmax] are lists of numbers with umin umax, vmin vmax

    - `options` – (optional) string representing plot2d options in gnuplot format

    OUTPUT: displays a plot on screen or saves to a file

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.plot3d_parametric(["v*sin(u)","v*cos(u)","v"], ["u","v"],[-3.2,3.2],[0,3])     # not tested
        sage: opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-cos-plot.eps"]'
        sage: maxima.plot3d_parametric(["v*sin(u)","v*cos(u)","v"], ["u","v"],[-3.2,3.2],[0,3],opts)      # not tested

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.plot3d_parametric(["v*sin(u)","v*cos(u)","v"], ["u","v"],[-RealNumber('3.2'),RealNumber('3.2')],[Integer(0),Integer(3)])     # not tested
        >>> opts = '[gnuplot_term, ps], [gnuplot_out_file, "sin-cos-plot.eps"]'
        >>> maxima.plot3d_parametric(["v*sin(u)","v*cos(u)","v"], ["u","v"],[-RealNumber('3.2'),RealNumber('3.2')],[Integer(0),Integer(3)],opts)      # not tested

    The eps file is saved in the current working directory.

    Here is a torus:

    Sage

        sage: _ = maxima.eval("expr_1: cos(y)*(10.0+6*cos(x)); expr_2: sin(y)*(10.0+6*cos(x)); expr_3: -6*sin(x);")
        sage: maxima.plot3d_parametric(["expr_1","expr_2","expr_3"], ["x","y"],[0,6],[0,6])  # not tested

    [Python]

        >>> from sage.all import *
        >>> _ = maxima.eval("expr_1: cos(y)*(10.0+6*cos(x)); expr_2: sin(y)*(10.0+6*cos(x)); expr_3: -6*sin(x);")
        >>> maxima.plot3d_parametric(["expr_1","expr_2","expr_3"], ["x","y"],[Integer(0),Integer(6)],[Integer(0),Integer(6)])  # not tested

    Here is a Möbius strip:

    Sage

        sage: x = "cos(u)*(3 + v*cos(u/2))"
        sage: y = "sin(u)*(3 + v*cos(u/2))"
        sage: z = "v*sin(u/2)"
        sage: maxima.plot3d_parametric([x,y,z],["u","v"],[-3.1,3.2],[-1/10,1/10])   # not tested

    Python

        >>> from sage.all import *
        >>> x = "cos(u)*(3 + v*cos(u/2))"
        >>> y = "sin(u)*(3 + v*cos(u/2))"
        >>> z = "v*sin(u/2)"
        >>> maxima.plot3d_parametric([x,y,z],["u","v"],[-RealNumber('3.1'),RealNumber('3.2')],[-Integer(1)/Integer(10),Integer(1)/Integer(10)])   # not tested

  plot_list(ptsx, ptsy, options=None)

    Plots a curve determined by a sequence of points.

    INPUT:

    - `ptsx` – [x1,…,xn], where the xi and yi are real,

    - `ptsy` – [y1,…,yn]

    - `options` – string representing maxima plot2d options

    The points are (x1,y1), (x2,y2), etc.

    This function requires maxima 5.9.2 or newer.

    Note

    More that 150 points can sometimes lead to the program hanging. Why?

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: zeta_ptsx = [(pari(1/2 + i*I/10).zeta().real()).precision(1)          # needs sage.libs.pari
        ....:              for i in range(70,150)]
        sage: zeta_ptsy = [(pari(1/2 + i*I/10).zeta().imag()).precision(1)          # needs sage.libs.pari
        ....:              for i in range(70,150)]
        sage: maxima.plot_list(zeta_ptsx, zeta_ptsy)        # not tested            # needs sage.libs.pari
        sage: opts='[gnuplot_preamble, "set nokey"], [gnuplot_term, ps], [gnuplot_out_file, "zeta.eps"]'
        sage: maxima.plot_list(zeta_ptsx, zeta_ptsy, opts)  # not tested            # needs sage.libs.pari

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> zeta_ptsx = [(pari(Integer(1)/Integer(2) + i*I/Integer(10)).zeta().real()).precision(Integer(1))          # needs sage.libs.pari
        ...              for i in range(Integer(70),Integer(150))]
        >>> zeta_ptsy = [(pari(Integer(1)/Integer(2) + i*I/Integer(10)).zeta().imag()).precision(Integer(1))          # needs sage.libs.pari
        ...              for i in range(Integer(70),Integer(150))]
        >>> maxima.plot_list(zeta_ptsx, zeta_ptsy)        # not tested            # needs sage.libs.pari
        >>> opts='[gnuplot_preamble, "set nokey"], [gnuplot_term, ps], [gnuplot_out_file, "zeta.eps"]'
        >>> maxima.plot_list(zeta_ptsx, zeta_ptsy, opts)  # not tested            # needs sage.libs.pari

  plot_multilist(pts_list, options=None)

    Plots a list of list of points pts_list=[pts1,pts2,…,ptsn], where each ptsi is of the form [[x1,y1],…,[xn,yn]] x’s must be integers and y’s reals options is a string representing maxima plot2d options.

    INPUT:

    - `pts_lst` – list of points; each point must be of the form [x,y] where `x` is an integer and `y` is a real

    - `var` – string; representing Maxima’s plot2d options

    Requires maxima 5.9.2 at least.

    Note

    More that 150 points can sometimes lead to the program hanging.

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: xx = [i/10.0 for i in range(-10,10)]
        sage: yy = [i/10.0 for i in range(-10,10)]
        sage: x0 = [0 for i in range(-10,10)]
        sage: y0 = [0 for i in range(-10,10)]
        sage: zeta_ptsx1 = [(pari(1/2+i*I/10).zeta().real()).precision(1)           # needs sage.libs.pari
        ....:               for i in range(10)]
        sage: zeta_ptsy1 = [(pari(1/2+i*I/10).zeta().imag()).precision(1)           # needs sage.libs.pari
        ....:               for i in range(10)]
        sage: maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1], [xx,y0], [x0,yy]])    # not tested
        sage: zeta_ptsx1 = [(pari(1/2+i*I/10).zeta().real()).precision(1)           # needs sage.libs.pari
        ....:               for i in range(10,150)]
        sage: zeta_ptsy1 = [(pari(1/2+i*I/10).zeta().imag()).precision(1)           # needs sage.libs.pari
        ....:               for i in range(10,150)]
        sage: maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1], [xx,y0], [x0,yy]])    # not tested
        sage: opts='[gnuplot_preamble, "set nokey"]'
        sage: maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1], [xx,y0], [x0,yy]],    # not tested
        ....:                       opts)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> xx = [i/RealNumber('10.0') for i in range(-Integer(10),Integer(10))]
        >>> yy = [i/RealNumber('10.0') for i in range(-Integer(10),Integer(10))]
        >>> x0 = [Integer(0) for i in range(-Integer(10),Integer(10))]
        >>> y0 = [Integer(0) for i in range(-Integer(10),Integer(10))]
        >>> zeta_ptsx1 = [(pari(Integer(1)/Integer(2)+i*I/Integer(10)).zeta().real()).precision(Integer(1))           # needs sage.libs.pari
        ...               for i in range(Integer(10))]
        >>> zeta_ptsy1 = [(pari(Integer(1)/Integer(2)+i*I/Integer(10)).zeta().imag()).precision(Integer(1))           # needs sage.libs.pari
        ...               for i in range(Integer(10))]
        >>> maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1], [xx,y0], [x0,yy]])    # not tested
        >>> zeta_ptsx1 = [(pari(Integer(1)/Integer(2)+i*I/Integer(10)).zeta().real()).precision(Integer(1))           # needs sage.libs.pari
        ...               for i in range(Integer(10),Integer(150))]
        >>> zeta_ptsy1 = [(pari(Integer(1)/Integer(2)+i*I/Integer(10)).zeta().imag()).precision(Integer(1))           # needs sage.libs.pari
        ...               for i in range(Integer(10),Integer(150))]
        >>> maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1], [xx,y0], [x0,yy]])    # not tested
        >>> opts='[gnuplot_preamble, "set nokey"]'
        >>> maxima.plot_multilist([[zeta_ptsx1,zeta_ptsy1], [xx,y0], [x0,yy]],    # not tested
        ...                       opts)

  solve_linear(eqns, vars)

    Wraps maxima’s linsolve.

    INPUT:

    - `eqns` – list of m strings; each representing a linear question in m = n variables

    - `vars` – list of n strings; each representing a variable

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        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]

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> eqns = ["x + z = y","2*a*x - y = 2*a^2","y - 2*z = 2"]
        >>> vars = ["x","y","z"]
        >>> maxima.solve_linear(eqns, vars)
        [x = a+1,y = 2*a,z = a-1]

  unit_quadratic_integer(n)

    Finds a unit of the ring of integers of the quadratic number field \(\QQ(\sqrt{n})\), \(n>1\), using the qunit maxima command.

    INPUT:

    - `n` – integer

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: u = maxima.unit_quadratic_integer(101); u
        a + 10
        sage: u.parent()
        Number Field in a with defining polynomial x^2 - 101 with a = 10.04987562112089?
        sage: u = maxima.unit_quadratic_integer(13)
        sage: u
        5*a + 18
        sage: u.parent()
        Number Field in a with defining polynomial x^2 - 13 with a = 3.605551275463990?

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> u = maxima.unit_quadratic_integer(Integer(101)); u
        a + 10
        >>> u.parent()
        Number Field in a with defining polynomial x^2 - 101 with a = 10.04987562112089?
        >>> u = maxima.unit_quadratic_integer(Integer(13))
        >>> u
        5*a + 18
        >>> u.parent()
        Number Field in a with defining polynomial x^2 - 13 with a = 3.605551275463990?

  version()

    Return the version of Maxima that Sage includes.

    OUTPUT: none

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima.version()  # random
        '5.41.0'

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima.version()  # random
        '5.41.0'

class sage.interfaces.maxima_abstract.MaximaAbstractElement(parent, value, is_name=False, name=None)

  Bases: `ExtraTabCompletion`, `InterfaceElement`

  Element of Maxima through an abstract interface.

  EXAMPLES:

  Elements of this class should not be created directly. The targeted parent of a concrete inherited class should be used instead:

  Sage

      sage: from sage.interfaces.maxima_lib import maxima
      sage: xp = maxima(x)
      sage: type(xp)
      <class 'sage.interfaces.maxima_lib.MaximaLibElement'>

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.maxima_lib import maxima
      >>> xp = maxima(x)
      >>> type(xp)
      <class 'sage.interfaces.maxima_lib.MaximaLibElement'>

  comma(args)

    Form the expression that would be written ‘self, args’ in Maxima.

    INPUT:

    - `args` – string

    OUTPUT: Maxima object

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('sqrt(2) + I').comma('numer')
        I+1.41421356237309...
        sage: maxima('sqrt(2) + I*a').comma('a=5')
        5*I+sqrt(2)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('sqrt(2) + I').comma('numer')
        I+1.41421356237309...
        >>> maxima('sqrt(2) + I*a').comma('a=5')
        5*I+sqrt(2)

  derivative(var='x', n=1)

    alias of `diff()`.

  diff(var='x', n=1)

    Return the \(n\)-th derivative of `self`.

    INPUT:

    - `var` – variable (default: `'x'`)

    - `n` – integer (default: 1)

    OUTPUT: \(n\)-th derivative of `self` with respect to the variable var

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: f = maxima('x^2')
        sage: f.diff()
        2*x
        sage: f.diff('x')
        2*x
        sage: f.diff('x', 2)
        2
        sage: maxima('sin(x^2)').diff('x',4)
        16*x^4*sin(x^2)-12*sin(x^2)-48*x^2*cos(x^2)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> f = maxima('x^2')
        >>> f.diff()
        2*x
        >>> f.diff('x')
        2*x
        >>> f.diff('x', Integer(2))
        2
        >>> maxima('sin(x^2)').diff('x',Integer(4))
        16*x^4*sin(x^2)-12*sin(x^2)-48*x^2*cos(x^2)

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: f = maxima('x^3 + 17*y^2')
        sage: f.diff('x')
        3*x^2
        sage: f.diff('y')
        34*y

    [Python]

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> f = maxima('x^3 + 17*y^2')
        >>> f.diff('x')
        3*x^2
        >>> f.diff('y')
        34*y

  dot(other)

    Implement the notation `self . other`.

    INPUT:

    - `other` – matrix; argument to dot

    OUTPUT: Maxima matrix

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: A = maxima('matrix ([a1],[a2])')
        sage: B = maxima('matrix ([b1, b2])')
        sage: A.dot(B)
        matrix([a1*b1,a1*b2],[a2*b1,a2*b2])

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> A = maxima('matrix ([a1],[a2])')
        >>> B = maxima('matrix ([b1, b2])')
        >>> A.dot(B)
        matrix([a1*b1,a1*b2],[a2*b1,a2*b2])

  imag()

    Return the imaginary part of this Maxima element.

    OUTPUT: Maxima real

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('2 + (2/3)*%i').imag()
        2/3

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('2 + (2/3)*%i').imag()
        2/3

  integral(var='x', min=None, max=None)

    Return the integral of `self` with respect to the variable \(x\).

    INPUT:

    - `var` – variable

    - `min` – (default: `None`)

    - `max` – (default: `None`)

    OUTPUT: the definite integral if xmin is not `None`

    - an indefinite integral otherwise

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('x^2+1').integral()
        x^3/3+x
        sage: maxima('x^2+ 1 + y^2').integral('y')
        y^3/3+x^2*y+y
        sage: maxima('x / (x^2+1)').integral()
        log(x^2+1)/2
        sage: maxima('1/(x^2+1)').integral()
        atan(x)
        sage: maxima('1/(x^2+1)').integral('x', 0, infinity)
        %pi/2
        sage: maxima('x/(x^2+1)').integral('x', -1, 1)
        0

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('x^2+1').integral()
        x^3/3+x
        >>> maxima('x^2+ 1 + y^2').integral('y')
        y^3/3+x^2*y+y
        >>> maxima('x / (x^2+1)').integral()
        log(x^2+1)/2
        >>> maxima('1/(x^2+1)').integral()
        atan(x)
        >>> maxima('1/(x^2+1)').integral('x', Integer(0), infinity)
        %pi/2
        >>> maxima('x/(x^2+1)').integral('x', -Integer(1), Integer(1))
        0

    Sage

        sage: f = maxima('exp(x^2)').integral('x',0,1)
        sage: f.sage()
        -1/2*I*sqrt(pi)*erf(I)
        sage: f.numer()
        1.46265174590718...

    [Python]

        >>> from sage.all import *
        >>> f = maxima('exp(x^2)').integral('x',Integer(0),Integer(1))
        >>> f.sage()
        -1/2*I*sqrt(pi)*erf(I)
        >>> f.numer()
        1.46265174590718...

  integrate(var='x', min=None, max=None)

    alias of `integral()`.

  nintegral(var='x', a=0, b=1, desired_relative_error='1e-8', maximum_num_subintervals=200)

    Return a numerical approximation to the integral of `self` from \(a\) to \(b\).

    INPUT:

    - `var` – variable to integrate with respect to

    - `a` – lower endpoint of integration

    - `b` – upper endpoint of integration

    - `desired_relative_error` – (default: `'1e-8'`) the desired relative error

    - `maximum_num_subintervals` – (default: 200) maxima number of subintervals

    OUTPUT: approximation to the integral

    - estimated absolute error of the approximation

    - the number of integrand evaluations

    - an error code:

      > - `0` – no problems were encountered

      > - `1` – too many subintervals were done

      > - `2` – excessive roundoff error

      > - `3` – extremely bad integrand behavior

      > - `4` – failed to converge

      > - `5` – integral is probably divergent or slowly convergent

      > - `6` – the input is invalid

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('exp(-sqrt(x))').nintegral('x',0,1)
        (0.5284822353142306, 4.163...e-11, 231, 0)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('exp(-sqrt(x))').nintegral('x',Integer(0),Integer(1))
        (0.5284822353142306, 4.163...e-11, 231, 0)

    Note that GP also does numerical integration, and can do so to very high precision very quickly:

    Sage

        sage: gp('intnum(x=0,1,exp(-sqrt(x)))')
        0.52848223531423071361790491935415653022
        sage: _ = gp.set_precision(80)
        sage: gp('intnum(x=0,1,exp(-sqrt(x)))')
        0.52848223531423071361790491935415653021675547587292866196865279321015401702040079

    [Python]

        >>> from sage.all import *
        >>> gp('intnum(x=0,1,exp(-sqrt(x)))')
        0.52848223531423071361790491935415653022
        >>> _ = gp.set_precision(Integer(80))
        >>> gp('intnum(x=0,1,exp(-sqrt(x)))')
        0.52848223531423071361790491935415653021675547587292866196865279321015401702040079

  numer()

    Return numerical approximation to `self` as a Maxima object.

    OUTPUT: Maxima object

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: a = maxima('sqrt(2)').numer(); a
        1.41421356237309...
        sage: type(a)
        <class 'sage.interfaces.maxima_lib.MaximaLibElement'>

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> a = maxima('sqrt(2)').numer(); a
        1.41421356237309...
        >>> type(a)
        <class 'sage.interfaces.maxima_lib.MaximaLibElement'>

  partial_fraction_decomposition(var='x')

    Return the partial fraction decomposition of `self` with respect to the variable var.

    INPUT:

    - `var` – string

    OUTPUT: Maxima object

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: f = maxima('1/((1+x)*(x-1))')
        sage: f.partial_fraction_decomposition('x')
        1/(2*(x-1))-1/(2*(x+1))
        sage: print(f.partial_fraction_decomposition('x'))
                                 1           1
                             ───────── - ─────────
                             2 (x - 1)   2 (x + 1)

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> f = maxima('1/((1+x)*(x-1))')
        >>> f.partial_fraction_decomposition('x')
        1/(2*(x-1))-1/(2*(x+1))
        >>> print(f.partial_fraction_decomposition('x'))
                                 1           1
                             ───────── - ─────────
                             2 (x - 1)   2 (x + 1)

  real()

    Return the real part of this Maxima element.

    OUTPUT: Maxima real

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('2 + (2/3)*%i').real()
        2

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('2 + (2/3)*%i').real()
        2

  str()

    Return string representation of this Maxima object.

    OUTPUT: string

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('sqrt(2) + 1/3').str()
        'sqrt(2)+1/3'

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('sqrt(2) + 1/3').str()
        'sqrt(2)+1/3'

  subst(val)

    Substitute a value or several values into this Maxima object.

    INPUT:

    - `val` – string representing substitution(s) to perform

    OUTPUT: Maxima object

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: maxima('a^2 + 3*a + b').subst('b=2')
        a^2+3*a+2
        sage: maxima('a^2 + 3*a + b').subst('a=17')
        b+340
        sage: maxima('a^2 + 3*a + b').subst('a=17, b=2')
        342

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> maxima('a^2 + 3*a + b').subst('b=2')
        a^2+3*a+2
        >>> maxima('a^2 + 3*a + b').subst('a=17')
        b+340
        >>> maxima('a^2 + 3*a + b').subst('a=17, b=2')
        342

class sage.interfaces.maxima_abstract.MaximaAbstractElementFunction(parent, name, defn, args, latex)

  Bases: `MaximaAbstractElement`

  Create a Maxima function with the parent `parent`, name `name`, definition `defn`, arguments `args` and latex representation `latex`.

  INPUT:

  - `parent` – an instance of a concrete Maxima interface

  - `name` – string

  - `defn` – string

  - `args` – string; comma separated names of arguments

  - `latex` – string

  OUTPUT: Maxima function

  EXAMPLES:

  Sage

      sage: from sage.interfaces.maxima_lib import maxima
      sage: maxima.function('x,y','e^cos(x)')
      e^cos(x)

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.maxima_lib import maxima
      >>> maxima.function('x,y','e^cos(x)')
      e^cos(x)

  arguments(split=True)

    Return the arguments of this Maxima function.

    INPUT:

    - `split` – boolean; if `True` return a tuple of strings, otherwise return a string of comma-separated arguments

    OUTPUT: string if `split` is False

    - a list of strings if `split` is True

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: f = maxima.function('x,y','sin(x+y)')
        sage: f.arguments()
        ['x', 'y']
        sage: f.arguments(split=False)
        'x,y'
        sage: f = maxima.function('', 'sin(x)')
        sage: f.arguments()
        []

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> f = maxima.function('x,y','sin(x+y)')
        >>> f.arguments()
        ['x', 'y']
        >>> f.arguments(split=False)
        'x,y'
        >>> f = maxima.function('', 'sin(x)')
        >>> f.arguments()
        []

  definition()

    Return the definition of this Maxima function as a string.

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: f = maxima.function('x,y','sin(x+y)')
        sage: f.definition()
        'sin(x+y)'

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> f = maxima.function('x,y','sin(x+y)')
        >>> f.definition()
        'sin(x+y)'

  integral(var)

    Return the integral of `self` with respect to the variable var.

    INPUT:

    - `var` – a variable

    OUTPUT: Maxima function

    Note that integrate is an alias of integral.

    EXAMPLES:

    Sage

        sage: from sage.interfaces.maxima_lib import maxima
        sage: x,y = var('x,y')
        sage: f = maxima.function('x','sin(x)')
        sage: f.integral(x)
        -cos(x)
        sage: f.integral(y)
        sin(x)*y

    Python

        >>> from sage.all import *
        >>> from sage.interfaces.maxima_lib import maxima
        >>> x,y = var('x,y')
        >>> f = maxima.function('x','sin(x)')
        >>> f.integral(x)
        -cos(x)
        >>> f.integral(y)
        sin(x)*y

  integrate(var)

    alias of `integral()`.

sage.interfaces.maxima_abstract.maxima_console()

  Spawn a new Maxima command-line session.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.maxima_abstract import maxima_console
      sage: maxima_console()                    # not tested
      Maxima 5.46.0 https://maxima.sourceforge.io
      ...

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.maxima_abstract import maxima_console
      >>> maxima_console()                    # not tested
      Maxima 5.46.0 https://maxima.sourceforge.io
      ...

sage.interfaces.maxima_abstract.maxima_version()

  Return Maxima version.

  Currently this calls a new copy of Maxima.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.maxima_abstract import maxima_version
      sage: maxima_version()  # random
      '5.41.0'

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.maxima_abstract import maxima_version
      >>> maxima_version()  # random
      '5.41.0'

sage.interfaces.maxima_abstract.reduce_load_MaximaAbstract_function(parent, defn, args, latex)

  Unpickle a Maxima function.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.maxima_lib import maxima
      sage: from sage.interfaces.maxima_abstract import reduce_load_MaximaAbstract_function
      sage: f = maxima.function('x,y','sin(x+y)')
      sage: _,args = f.__reduce__()
      sage: g = reduce_load_MaximaAbstract_function(*args)
      sage: g == f
      True

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.maxima_lib import maxima
      >>> from sage.interfaces.maxima_abstract import reduce_load_MaximaAbstract_function
      >>> f = maxima.function('x,y','sin(x+y)')
      >>> _,args = f.__reduce__()
      >>> g = reduce_load_MaximaAbstract_function(*args)
      >>> g == f
      True