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
>>> 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: type(a) #optional - axiom
<class 'sage.interfaces.axiom.AxiomElement'>
sage: parent(a) #optional - axiom
Axiom
>>> 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: a.type() #optional - axiom
PositiveInteger
>>> 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: 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
>>> 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: a = axiom(2/3); a #optional - axiom
2
-
3
sage: a = axiom('x^2 + 3/7'); a #optional - axiom
2 3
x + -
7
>>> 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: 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
>>> 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: 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 )
>>> 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: f = axiom('(x^5 - y^5)^10000') # not tested
Interrupting Axiom...
...
<class 'exceptions.TypeError'>: Ctrl-c pressed while running Axiom
>>> 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: axiom('1/100 + 1/101') #optional - axiom
201
-----
10100
sage: a = axiom('(1 + sqrt(2))^5'); a #optional - axiom
+-+
29\|2 + 41
>>> 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)'])[source]#
Bases:
PanAxiom
- console()[source]#
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. -----------------------------------------------------------------------------
>>> 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[source]#
alias of
PanAxiomElement
- sage.interfaces.axiom.AxiomExpectFunction[source]#
alias of
PanAxiomExpectFunction
- sage.interfaces.axiom.AxiomFunctionElement[source]#
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)'])[source]#
Bases:
ExtraTabCompletion
,Expect
Interface to a PanAxiom interpreter.
- get(var)[source]#
Get the string value of the Axiom variable var.
EXAMPLES:
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'
>>> 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'
- class sage.interfaces.axiom.PanAxiomElement(parent, value, is_name=False, name=None)[source]#
Bases:
ExpectElement
,AxiomElement
- as_type(type)[source]#
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
>>> 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)[source]#
Returns a Axiom tuple from self and args.
EXAMPLES:
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
>>> 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()[source]#
Returns the type of an AxiomElement.
EXAMPLES:
sage: axiom(x+2).type() #optional - axiom Polynomial Integer
>>> from sage.all import * >>> axiom(x+Integer(2)).type() #optional - axiom Polynomial Integer
- unparsed_input_form()[source]#
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'
>>> 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)[source]#
Bases:
ExpectFunction
- class sage.interfaces.axiom.PanAxiomFunctionElement(object, name)[source]#
Bases:
FunctionElement
- sage.interfaces.axiom.axiom_console()[source]#
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. -----------------------------------------------------------------------------
>>> 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.is_AxiomElement(x)[source]#
Return True if
x
is of typeAxiomElement
.EXAMPLES:
sage: from sage.interfaces.axiom import is_AxiomElement sage: is_AxiomElement(2) doctest:...: DeprecationWarning: the function is_AxiomElement is deprecated; use isinstance(x, sage.interfaces.abc.AxiomElement) instead See https://github.com/sagemath/sage/issues/34804 for details. False sage: is_AxiomElement(axiom(2)) # optional - axiom True
>>> from sage.all import * >>> from sage.interfaces.axiom import is_AxiomElement >>> is_AxiomElement(Integer(2)) doctest:...: DeprecationWarning: the function is_AxiomElement is deprecated; use isinstance(x, sage.interfaces.abc.AxiomElement) instead See https://github.com/sagemath/sage/issues/34804 for details. False >>> is_AxiomElement(axiom(Integer(2))) # optional - axiom True
- sage.interfaces.axiom.reduce_load_Axiom()[source]#
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
>>> from sage.all import * >>> from sage.interfaces.axiom import reduce_load_Axiom >>> reduce_load_Axiom() Axiom