Interface to Axiom - Interpreter Interfaces

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

# Interface to Axiom

Todo

- Evaluation using a file is not done. Any input line with more than a few thousand characters would hang the system, so currently it automatically raises an exception.

- All completions of a given command.

- Interactive help.

Axiom is a free GPL-compatible (modified BSD license) general purpose computer algebra system whose development started in 1973 at IBM. It contains symbolic manipulation algorithms, as well as implementations of special functions, including elliptic functions and generalized hypergeometric functions. Moreover, Axiom has implementations of many functions relating to the invariant theory of the symmetric group \(S_n.\) For many links to Axiom documentation see http://wiki.axiom-developer.org.

AUTHORS:

- Bill Page (2006-10): Created this (based on Maxima interface)

  Note

  Bill Page put a huge amount of effort into the Sage Axiom interface over several days during the Sage Days 2 coding sprint. This is contribution is greatly appreciated.

- William Stein (2006-10): misc touchup.

- Bill Page (2007-08): Minor modifications to support axiom4sage-0.3

Note

The axiom4sage-0.3.spkg is based on an experimental version of the FriCAS fork of the Axiom project by Waldek Hebisch that uses pre-compiled cached Lisp code to build Axiom very quickly with clisp.

If the string “error” (case insensitive) occurs in the output of anything from axiom, a `RuntimeError` exception is raised.

EXAMPLES: We evaluate a very simple expression in axiom.

Sage

    sage: axiom('3 * 5')                     #optional - axiom
    15
    sage: a = axiom(3) * axiom(5); a         #optional - axiom
    15

Python

    >>> from sage.all import *
    >>> axiom('3 * 5')                     #optional - axiom
    15
    >>> a = axiom(Integer(3)) * axiom(Integer(5)); a         #optional - axiom
    15

The type of a is AxiomElement, i.e., an element of the axiom interpreter.

Sage

    sage: type(a)                            #optional - axiom
    <class 'sage.interfaces.axiom.AxiomElement'>
    sage: parent(a)                          #optional - axiom
    Axiom

[Python]

    >>> from sage.all import *
    >>> type(a)                            #optional - axiom
    <class 'sage.interfaces.axiom.AxiomElement'>
    >>> parent(a)                          #optional - axiom
    Axiom

The underlying Axiom type of a is also available, via the type method:

Sage

    sage: a.type()                           #optional - axiom
    PositiveInteger

Python

    >>> from sage.all import *
    >>> a.type()                           #optional - axiom
    PositiveInteger

We factor \(x^5 - y^5\) in Axiom in several different ways. The first way yields a Axiom object.

Sage

    sage: F = axiom.factor('x^5 - y^5'); F      #optional - axiom
               4      3    2 2    3     4
    - (y - x)(y  + x y  + x y  + x y + x )
    sage: type(F)                               #optional - axiom
    <class 'sage.interfaces.axiom.AxiomElement'>
    sage: F.type()                              #optional - axiom
    Factored Polynomial Integer

[Python]

    >>> from sage.all import *
    >>> F = axiom.factor('x^5 - y^5'); F      #optional - axiom
               4      3    2 2    3     4
    - (y - x)(y  + x y  + x y  + x y + x )
    >>> type(F)                               #optional - axiom
    <class 'sage.interfaces.axiom.AxiomElement'>
    >>> F.type()                              #optional - axiom
    Factored Polynomial Integer

Note that Axiom objects are normally displayed using “ASCII art”.

Sage

    sage: a = axiom(2/3); a          #optional - axiom
      2
      -
      3
    sage: a = axiom('x^2 + 3/7'); a      #optional - axiom
       2   3
      x  + -
           7

Python

    >>> from sage.all import *
    >>> a = axiom(Integer(2)/Integer(3)); a          #optional - axiom
      2
      -
      3
    >>> a = axiom('x^2 + 3/7'); a      #optional - axiom
       2   3
      x  + -
           7

The `axiom.eval` command evaluates an expression in axiom and returns the result as a string. This is exact as if we typed in the given line of code to axiom; the return value is what Axiom would print out.

Sage

    sage: print(axiom.eval('factor(x^5 - y^5)'))   # optional - axiom
               4      3    2 2    3     4
    - (y - x)(y  + x y  + x y  + x y + x )
    Type: Factored Polynomial Integer

[Python]

    >>> from sage.all import *
    >>> print(axiom.eval('factor(x^5 - y^5)'))   # optional - axiom
               4      3    2 2    3     4
    - (y - x)(y  + x y  + x y  + x y + x )
    Type: Factored Polynomial Integer

We can create the polynomial \(f\) as a Axiom polynomial, then call the factor method on it. Notice that the notation `f.factor()` is consistent with how the rest of Sage works.

Sage

    sage: f = axiom('x^5 - y^5')                  #optional - axiom
    sage: f^2                                     #optional - axiom
       10     5 5    10
      y   - 2x y  + x
    sage: f.factor()                              #optional - axiom
               4      3    2 2    3     4
    - (y - x)(y  + x y  + x y  + x y + x )

Python

    >>> from sage.all import *
    >>> f = axiom('x^5 - y^5')                  #optional - axiom
    >>> f**Integer(2)                                     #optional - axiom
       10     5 5    10
      y   - 2x y  + x
    >>> f.factor()                              #optional - axiom
               4      3    2 2    3     4
    - (y - x)(y  + x y  + x y  + x y + x )

Control-C interruption works well with the axiom interface, because of the excellent implementation of axiom. For example, try the following sum but with a much bigger range, and hit control-C.

Sage

    sage:  f = axiom('(x^5 - y^5)^10000')       # not tested
    Interrupting Axiom...
    ...
    <class 'exceptions.TypeError'>: Ctrl-c pressed while running Axiom

[Python]

    >>> from sage.all import *
    >>>  f = axiom('(x^5 - y^5)^10000')       # not tested
    Interrupting Axiom...
    ...
    <class 'exceptions.TypeError'>: Ctrl-c pressed while running Axiom

Sage

    sage: axiom('1/100 + 1/101')                  #optional - axiom
       201
      -----
      10100
    sage: a = axiom('(1 + sqrt(2))^5'); a         #optional - axiom
         +-+
      29\|2  + 41

Python

    >>> from sage.all import *
    >>> axiom('1/100 + 1/101')                  #optional - axiom
       201
      -----
      10100
    >>> a = axiom('(1 + sqrt(2))^5'); a         #optional - axiom
         +-+
      29\|2  + 41

class sage.interfaces.axiom.Axiom(name='axiom', command='axiom -nox -noclef', script_subdirectory=None, logfile=None, server=None, server_tmpdir=None, init_code=[')lisp (si::readline-off)'])

  Bases: `PanAxiom`

  console()

    Spawn a new Axiom command-line session.

    EXAMPLES:

    Sage

        sage: axiom.console() #not tested
                                AXIOM Computer Algebra System
                                Version: Axiom (January 2009)
                       Timestamp: Sunday January 25, 2009 at 07:08:54
        -----------------------------------------------------------------------------
           Issue )copyright to view copyright notices.
           Issue )summary for a summary of useful system commands.
           Issue )quit to leave AXIOM and return to shell.
        -----------------------------------------------------------------------------

    Python

        >>> from sage.all import *
        >>> axiom.console() #not tested
                                AXIOM Computer Algebra System
                                Version: Axiom (January 2009)
                       Timestamp: Sunday January 25, 2009 at 07:08:54
        -----------------------------------------------------------------------------
           Issue )copyright to view copyright notices.
           Issue )summary for a summary of useful system commands.
           Issue )quit to leave AXIOM and return to shell.
        -----------------------------------------------------------------------------

sage.interfaces.axiom.AxiomElement

  alias of `PanAxiomElement`

sage.interfaces.axiom.AxiomExpectFunction

  alias of `PanAxiomExpectFunction`

sage.interfaces.axiom.AxiomFunctionElement

  alias of `PanAxiomFunctionElement`

class sage.interfaces.axiom.PanAxiom(name='axiom', command='axiom -nox -noclef', script_subdirectory=None, logfile=None, server=None, server_tmpdir=None, init_code=[')lisp (si::readline-off)'])

  Bases: `ExtraTabCompletion`, `Expect`

  Interface to a PanAxiom interpreter.

  get(var)

    Get the string value of the Axiom variable var.

    EXAMPLES:

    Sage

        sage: # optional - axiom
        sage: axiom.set('xx', '2')
        sage: axiom.get('xx')
        '2'
        sage: a = axiom('(1 + sqrt(2))^5')
        sage: axiom.get(a.name())
        '     +-+\r\r\n  29\\|2  + 41'

    Python

        >>> from sage.all import *
        >>> # optional - axiom
        >>> axiom.set('xx', '2')
        >>> axiom.get('xx')
        '2'
        >>> a = axiom('(1 + sqrt(2))^5')
        >>> axiom.get(a.name())
        '     +-+\r\r\n  29\\|2  + 41'

  set(var, value)

    Set the variable var to the given value.

    EXAMPLES:

    Sage

        sage: axiom.set('xx', '2')    #optional - axiom
        sage: axiom.get('xx')         #optional - axiom
        '2'

    Python

        >>> from sage.all import *
        >>> axiom.set('xx', '2')    #optional - axiom
        >>> axiom.get('xx')         #optional - axiom
        '2'

class sage.interfaces.axiom.PanAxiomElement(parent, value, is_name=False, name=None)

  Bases: `ExpectElement`, `AxiomElement`

  as_type(type)

    Return `self` as type.

    EXAMPLES:

    Sage

        sage: a = axiom(1.2); a            #optional - axiom
        1.2
        sage: a.as_type(axiom.DoubleFloat) #optional - axiom
        1.2
        sage: _.type()                     #optional - axiom
        DoubleFloat

    Python

        >>> from sage.all import *
        >>> a = axiom(RealNumber('1.2')); a            #optional - axiom
        1.2
        >>> a.as_type(axiom.DoubleFloat) #optional - axiom
        1.2
        >>> _.type()                     #optional - axiom
        DoubleFloat

  comma(*args)

    Return an Axiom tuple from `self` and `args`.

    EXAMPLES:

    Sage

        sage: # optional - axiom
        sage: two = axiom(2)
        sage: two.comma(3)
        [2,3]
        sage: two.comma(3,4)
        [2,3,4]
        sage: _.type()
        Tuple PositiveInteger

    Python

        >>> from sage.all import *
        >>> # optional - axiom
        >>> two = axiom(Integer(2))
        >>> two.comma(Integer(3))
        [2,3]
        >>> two.comma(Integer(3),Integer(4))
        [2,3,4]
        >>> _.type()
        Tuple PositiveInteger

  type()

    Return the type of an AxiomElement.

    EXAMPLES:

    Sage

        sage: axiom(x+2).type()  #optional - axiom
        Polynomial Integer

    Python

        >>> from sage.all import *
        >>> axiom(x+Integer(2)).type()  #optional - axiom
        Polynomial Integer

  unparsed_input_form()

    Get the linear string representation of this object, if possible (often it isn’t).

    EXAMPLES:

    Sage

        sage: a = axiom(x^2+1); a     #optional - axiom
           2
          x  + 1
        sage: a.unparsed_input_form() #optional - axiom
        'x*x+1'

    Python

        >>> from sage.all import *
        >>> a = axiom(x**Integer(2)+Integer(1)); a     #optional - axiom
           2
          x  + 1
        >>> a.unparsed_input_form() #optional - axiom
        'x*x+1'

class sage.interfaces.axiom.PanAxiomExpectFunction(parent, name)

  Bases: `ExpectFunction`

class sage.interfaces.axiom.PanAxiomFunctionElement(object, name)

  Bases: `FunctionElement`

sage.interfaces.axiom.axiom_console()

  Spawn a new Axiom command-line session.

  EXAMPLES:

  Sage

      sage: axiom_console() #not tested
                              AXIOM Computer Algebra System
                              Version: Axiom (January 2009)
                     Timestamp: Sunday January 25, 2009 at 07:08:54
      -----------------------------------------------------------------------------
         Issue )copyright to view copyright notices.
         Issue )summary for a summary of useful system commands.
         Issue )quit to leave AXIOM and return to shell.
      -----------------------------------------------------------------------------

  Python

      >>> from sage.all import *
      >>> axiom_console() #not tested
                              AXIOM Computer Algebra System
                              Version: Axiom (January 2009)
                     Timestamp: Sunday January 25, 2009 at 07:08:54
      -----------------------------------------------------------------------------
         Issue )copyright to view copyright notices.
         Issue )summary for a summary of useful system commands.
         Issue )quit to leave AXIOM and return to shell.
      -----------------------------------------------------------------------------

sage.interfaces.axiom.reduce_load_Axiom()

  Return the Axiom interface object defined in sage.interfaces.axiom.

  EXAMPLES:

  Sage

      sage: from sage.interfaces.axiom import reduce_load_Axiom
      sage: reduce_load_Axiom()
      Axiom

  Python

      >>> from sage.all import *
      >>> from sage.interfaces.axiom import reduce_load_Axiom
      >>> reduce_load_Axiom()
      Axiom