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: axiom('3 * 5')                     #optional - axiom
15
sage: a = axiom(3) * axiom(5); a         #optional - axiom
15

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

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

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

sage: 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: 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

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

sage: a = axiom(2/3); a          #optional - axiom
  2
  -
  3
sage: 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: 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: 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 )

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:  f = axiom('(x^5 - y^5)^10000')       # not tested
Interrupting Axiom...
...
<type 'exceptions.TypeError'>: Ctrl-c pressed while running Axiom
sage: axiom('1/100 + 1/101')                  #optional - axiom
   201
  -----
  10100
sage: a = axiom('(1 + sqrt(2))^5'); a         #optional - axiom
     +-+
  29\|2  + 41

TESTS: We check to make sure the subst method works with keyword arguments.

sage: a = axiom(x+2); a  #optional - axiom
x + 2
sage: a.subst(x=3)       #optional - axiom
5

We verify that Axiom floating point numbers can be converted to Python floats.

sage: float(axiom(2))     #optional - axiom
2.0
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)'])
__reduce__()

EXAMPLES:

sage: axiom.__reduce__()
(<function reduce_load_Axiom at 0x...>, ())
sage: f, args = _
sage: f(*args)
Axiom
_function_class()

Return the AxiomExpectFunction class.

EXAMPLES:

sage: axiom._function_class()
<class 'sage.interfaces.axiom.AxiomExpectFunction'>
sage: type(axiom.gcd)
<class 'sage.interfaces.axiom.AxiomExpectFunction'>
_function_element_class()

Returns the Axiom function element class.

EXAMPLES:

sage: axiom._function_element_class()
<class 'sage.interfaces.axiom.AxiomFunctionElement'>
sage: type(axiom(2).gcd) #optional - axiom
<class 'sage.interfaces.axiom.AxiomFunctionElement'>
_object_class()

EXAMPLES:

sage: axiom._object_class()
<class 'sage.interfaces.axiom.AxiomElement'>
sage: type(axiom(2)) #optional - axiom
<class 'sage.interfaces.axiom.AxiomElement'>
console()

Spawn a new Axiom command-line session.

EXAMPLES:

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.
-----------------------------------------------------------------------------
class sage.interfaces.axiom.AxiomElement(parent, value, is_name=False, name=None)
class sage.interfaces.axiom.AxiomExpectFunction(parent, name)
class sage.interfaces.axiom.AxiomFunctionElement(object, name)
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)'])

Interface to a PanAxiom interpreter.

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

Create an instance of the Axiom interpreter.

TESTS:

sage: axiom == loads(dumps(axiom))
True
_commands()

Returns a list of commands available. This is done by parsing the result of the first section of the output of ‘)what things’.

EXAMPLES:

sage: cmds = axiom._commands() #optional - axiom
sage: len(cmds) > 100  #optional - axiom
True
sage: '<' in cmds      #optional - axiom
True
sage: 'factor' in cmds #optional - axiom
True
_eval_line(line, reformat=True, allow_use_file=False, wait_for_prompt=True)

EXAMPLES:

sage: print axiom._eval_line('2+2')  #optional - axiom
  4
                                           Type: PositiveInteger
_quit_string()

Returns the string used to quit Axiom.

EXAMPLES:

sage: axiom._quit_string()
')lisp (quit)'
sage: a = Axiom()
sage: a.is_running()
False
sage: a._start()     #optional - axiom
sage: a.is_running() #optional - axiom
True
sage: a.quit()       #optional - axiom
sage: a.is_running() #optional - axiom
False
_read_in_file_command(filename)

EXAMPLES:

sage: axiom._read_in_file_command('test.input')
')read test.input \n'
sage: axiom._read_in_file_command('test')
...
ValueError: the filename must end with .input
sage: filename = tmp_filename()+'.input'
sage: f = open(filename, 'w')
sage: f.write('xx := 22;\n')
sage: f.close()
sage: axiom.read(filename)    #optional -- requires Axiom
sage: axiom.get('xx')         #optional
'22'
_start()

Start the Axiom interpreter.

EXAMPLES:

sage: a = Axiom()
sage: a.is_running()
False
sage: a._start()     #optional - axiom
sage: a.is_running() #optional - axiom
True
sage: a.quit()       #optional - axiom
get(var)

Get the string value of the Axiom variable var.

EXAMPLES:

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

Set the variable var to the given value.

EXAMPLES:

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

sage: fricas.set('xx', '2')    #optional - fricas
sage: fricas.get('xx')         #optional - fricas
'2'
trait_names(verbose=True, use_disk_cache=True)

Returns a list of all the commands defined in Axiom and optionally (per default) store them to disk.

EXAMPLES:

sage: c = axiom.trait_names(use_disk_cache=False, verbose=False) #optional - axiom
sage: len(c) > 100  #optional - axiom
True
sage: 'factor' in c  #optional - axiom
True
sage: '**' in c     #optional - axiom
False
sage: 'upperCase?' in c  #optional - axiom
False
sage: 'upperCase_q' in c #optional - axiom
True
sage: 'upperCase_e' in c #optional - axiom
True
class sage.interfaces.axiom.PanAxiomElement(parent, value, is_name=False, name=None)
__call__(x)

EXAMPLES:

sage: f = axiom(x+2) #optional - axiom
sage: f(2)           #optional - axiom
4
__cmp__(other)

EXAMPLES:

sage: two = axiom(2)  #optional - axiom
sage: two == 2        #optional - axiom
True
sage: two == 3        #optional - axiom
False
sage: two < 3         #optional - axiom
True
sage: two > 1         #optional - axiom
True

sage: a = axiom(1); b = axiom(2)  #optional - axiom
sage: a == b                      #optional - axiom
False
sage: a < b                       #optional - axiom
True
sage: a > b                       #optional - axiom
False
sage: b < a                       #optional - axiom
False
sage: b > a                       #optional - axiom
True

We can also compare more complicated object such as functions:

sage: f = axiom('sin(x)'); g = axiom('cos(x)')    #optional - axiom
sage: f == g                                      #optional - axiom
False
__getitem__(n)

Return the n-th element of this list.

Note

Lists are 1-based.

EXAMPLES:

sage: v = axiom('[i*x^i for i in 0..5]'); v          # optional - axiom
         2   3   4   5
  [0,x,2x ,3x ,4x ,5x ]
sage: v[4]                                           # optional - axiom
    3
  3x
sage: v[1]                                           # optional - axiom
0
sage: v[10]                                          # optional - axiom
...
IndexError: index out of range
__len__()

Return the length of a list.

EXAMPLES:

sage: v = axiom('[x^i for i in 0..5]')            # optional - axiom
sage: len(v)                                      # optional - axiom  
6
_latex_()

EXAMPLES:

sage: a = axiom(1/2) #optional - axiom
sage: latex(a)       #optional - axiom
\frac{1}{2}

sage: a = fricas(1/2) #optional - fricas
sage: latex(a)        #optional - fricas
1 \over 2
_sage_()

Convert self to a Sage object.

EXAMPLES:

sage: a = axiom(1/2); a #optional - axiom
  1
  -
  2
sage: a.sage()          #optional - axiom
1/2
sage: _.parent()        #optional - axiom
Rational Field

sage: gp(axiom(1/2))    #optional - axiom
1/2

sage: fricas(1/2).sage() #optional - fricas
1/2

DoubleFloat’s in Axiom are converted to be in RDF in Sage.

sage: axiom(2.0).as_type('DoubleFloat').sage()  #optional - axiom
2.0
sage: _.parent() #optional - axiom
Real Double Field


sage: axiom(2.1234)._sage_() #optional - axiom
2.12340000000000
sage: _.parent()             #optional - axiom
Real Field with 53 bits of precision
sage: a = RealField(100)(pi)
sage: axiom(a)._sage_()      #optional - axiom 
3.1415926535897932384626433833
sage: _.parent()             #optional - axiom
Real Field with 100 bits of precision
sage: axiom(a)._sage_() == a #optional - axiom
True
sage: axiom(2.0)._sage_() #optional - axiom
2.00000000000000
sage: _.parent() #optional  - axiom
Real Field with 53 bits of precision
We can also convert Axiom’s polynomials to Sage polynomials.
sage: a = axiom(x^2 + 1) #optional - axiom sage: a.type() #optional - axiom Polynomial Integer sage: a.sage() #optional - axiom x^2 + 1 sage: _.parent() #optional - axiom Univariate Polynomial Ring in x over Integer Ring sage: axiom(‘x^2 + y^2 + 1/2’).sage() #optional - axiom y^2 + x^2 + 1/2 sage: _.parent() #optional - axiom Multivariate Polynomial Ring in y, x over Rational Field
_sage_domain()

A helper function for converting Axiom domains to the corresponding Sage object.

EXAMPLES:

sage: axiom('Integer').sage()  #optional - axiom
Integer Ring
sage: fricas('Integer').sage() #optional - fricas
Integer Ring

sage: axiom('Fraction Integer').sage()  #optional - axiom
Rational Field
sage: fricas('Fraction Integer').sage() #optional - fricas
Rational Field

sage: axiom('DoubleFloat').sage()  #optional - axiom
Real Double Field
sage: fricas('DoubleFloat').sage() #optional - fricas
Real Double Field
as_type(type)

Returns self as type.

EXAMPLES:

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
sage: a = fricas(1.2); a            #optional - fricas
1.2
sage: a.as_type(fricas.DoubleFloat) #optional - fricas
1.2
sage: _.type()                      #optional - fricas
DoubleFloat
comma(*args)

Returns a Axiom tuple from self and args.

EXAMPLES:

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

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

Returns the type of an AxiomElement.

EXAMPLES:

sage: axiom(x+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: a = axiom(x^2+1); a     #optional - axiom
   2
  x  + 1
sage: a.unparsed_input_form() #optional - axiom
'x*x+1'

sage: a = fricas(x^2+1)       #optional - fricas
sage: a.unparsed_input_form() #optional - fricas
'x^2+1'
class sage.interfaces.axiom.PanAxiomExpectFunction(parent, name)
__init__(parent, name)

TESTS:

sage: axiom.upperCase_q
upperCase?
sage: axiom.upperCase_e
upperCase!
class sage.interfaces.axiom.PanAxiomFunctionElement(object, name)
__init__(object, name)

TESTS:

sage: a = axiom('"Hello"') #optional - axiom
sage: a.upperCase_q        #optional - axiom
upperCase?
sage: a.upperCase_e        #optional - axiom
upperCase!
sage: a.upperCase_e()      #optional - axiom
"HELLO"
sage.interfaces.axiom.axiom_console()

Spawn a new Axiom command-line session.

EXAMPLES:

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.
-----------------------------------------------------------------------------
sage.interfaces.axiom.is_AxiomElement(x)

Returns True of x is of type AxiomElement.

EXAMPLES:

sage: from sage.interfaces.axiom import is_AxiomElement
sage: is_AxiomElement(axiom(2)) #optional - axiom
True
sage: is_AxiomElement(2)
False
sage.interfaces.axiom.reduce_load_Axiom()

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

EXAMPLES:

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

Previous topic

Common Interface Functionality

Next topic

Interface to GAP

This Page