Module: sage.interfaces.axiom
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
.
For many links to Axiom documentation see
http://wiki.axiom-developer.org.
Author Log:
If the string "error" (case insensitive) occurs in the output of anything from axiom, a RuntimeError exception is raised.
We evaluate a very simple expression in axiom.
sage: axiom('3 * 5') # optional
15
sage: a = axiom(3) * axiom(5); a # optional
15
The type of a is AxiomElement, i.e., an element of the axiom interpreter.
sage: type(a) # optional <class 'sage.interfaces.axiom.AxiomElement'> sage: parent(a) # optional Axiom
The underlying Axiom type of a is also available, via the type method:
sage: a.type() # optional PositiveInteger
We factor
in Axiom in several different ways.
The first way yields a Axiom object.
sage: F = axiom.factor('x^5 - y^5'); F # optional
4 3 2 2 3 4
- (y - x)(y + x y + x y + x y + x )
sage: type(F) # optional
<class 'sage.interfaces.axiom.AxiomElement'>
sage: F.type() # optional
Factored Polynomial Integer
Note that Axiom objects are normally displayed using ``ASCII art''.
sage: a = axiom(2/3); a # optional
2
-
3
sage: a = axiom('x^2 + 3/7'); a # optional
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
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
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
sage: f^2 # optional
10 5 5 10
y - 2x y + x
sage: f.factor() # optional
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
201
-----
10100
sage: a = axiom('(1 + sqrt(2))^5'); a # optional
+-+
29\|2 + 41
TESTS: We check to make sure the subst method works with keyword arguments.
sage: a = axiom(x+2); a #optional x + 2 sage: a.subst(x=3) #optional 5
We verify that Axiom floating point numbers can be converted to Python floats.
sage: float(axiom(2)) #optional 2.0
Module-level Functions
| ) |
Spawn a new Axiom (FriCAS) command-line session.
sage: axiom_console() #not tested
FriCAS (AXIOM fork) Computer Algebra System
Version: FriCAS 2007-07-19
Timestamp: Saturday October 20, 2007 at 20:08:37
---------------------------------------------------------------------------
--
Issue )copyright to view copyright notices.
Issue )summary for a summary of useful system commands.
Issue )quit to leave AXIOM and return to shell.
---------------------------------------------------------------------------
--
| x) |
Returns True of x is of type AxiomElement.
sage: from sage.interfaces.axiom import is_AxiomElement sage: is_AxiomElement(axiom(2)) #optional -- requires Axiom True sage: is_AxiomElement(2) False
| ) |
Returns the Axiom interface object defined in sage.interfaces.axiom.
sage: from sage.interfaces.axiom import reduce_load_Axiom sage: reduce_load_Axiom() Axiom
Class: Axiom
| self, [script_subdirectory=None], [logfile=None], [server=None], [server_tmpdir=None]) |
Create an instance of the Axiom interpreter.
TESTS:
sage: axiom == loads(dumps(axiom)) True
Functions: console,
get,
set,
trait_names
| self) |
Spawn a new Axiom (FriCAS) command-line session.
sage: axiom.console() #not tested
FriCAS (AXIOM fork) Computer Algebra System
Version: FriCAS 2007-07-19
Timestamp: Saturday October 20, 2007 at 20:08:37
---------------------------------------------------------------------------
--
Issue )copyright to view copyright notices.
Issue )summary for a summary of useful system commands.
Issue )quit to leave AXIOM and return to shell.
---------------------------------------------------------------------------
--
| self, var) |
Get the string value of the Axiom variable var.
sage: axiom.set('xx', '2') #optional -- requires Axiom
sage: axiom.get('xx') #optional
'2'
sage: a = axiom('(1 + sqrt(2))^5') #optional
sage: axiom.get(a.name()) #optional
' +-+
29\|2 + 41'
| self, var, value) |
Set the variable var to the given value.
sage: axiom.set('xx', '2') #optional -- requires Axiom
sage: axiom.get('xx') #optional
'2'
| self, [verbose=True], [use_disk_cache=True]) |
Returns a list of all the commands defined in Axiom and optionally (per default) store them to disk.
sage: c = axiom.trait_names(use_disk_cache=False, verbose=False) #optional sage: len(c) > 100 #optional True sage: 'factor' in c #optional True sage: '**' in c #optional False sage: 'upperCase?' in c #optional False sage: 'upperCase_q' in c #optional True sage: 'upperCase_e' in c #optional True
Special Functions: __init__,
__reduce__,
_commands,
_eval_line,
_function_class,
_function_element_class,
_object_class,
_quit_string,
_read_in_file_command,
_start
| self) |
sage: axiom.__reduce__() (<function reduce_load_Axiom at 0x...>, ()) sage: f, args = _ sage: f(*args) Axiom
| self) |
Returns a list of commands available. This is done by parsing the result of the first section of the output of ')what things'.
sage: cmds = axiom._commands() #optional -- requires Axiom sage: len(cmds) > 100 #optional True sage: '<' in cmds #optional True sage: 'factor' in cmds #optional True
| self, line, [reformat=True], [allow_use_file=False], [wait_for_prompt=True]) |
sage: print axiom._eval_line('2+2') #optional -- requires Axiom
4
Type: PositiveInteger
| self) |
Return the AxiomExpectFunction class.
sage: axiom._function_class() <class 'sage.interfaces.axiom.AxiomExpectFunction'> sage: type(axiom.gcd) <class 'sage.interfaces.axiom.AxiomExpectFunction'>
| self) |
Returns the Axiom function element class.
sage: axiom._function_element_class() <class 'sage.interfaces.axiom.AxiomFunctionElement'> sage: type(axiom(2).gcd) #optional -- requires Axiom <class 'sage.interfaces.axiom.AxiomFunctionElement'>
| self) |
sage: axiom._object_class() <class 'sage.interfaces.axiom.AxiomElement'> sage: type(axiom(2)) #optional -- requires Axiom <class 'sage.interfaces.axiom.AxiomElement'>
| self) |
Returns the string used to quit Axiom.
sage: axiom._quit_string() ')lisp (quit)'
sage: a = Axiom() sage: a.is_running() False sage: a._start() #optional -- requires axiom sage: a.is_running() #optional True sage: a.quit() #optional sage: a.is_running() #optional False
| self, filename) |
sage: axiom._read_in_file_command('test.input')
')read test.input
'
sage: axiom._read_in_file_command('test')
Traceback (most recent call last):
...
ValueError: the filename must end with .input
sage: filename = tmp_filename()+'.input'
sage: f = open(filename, 'w')
sage: f.write('xx := 22;
')
sage: f.close()
sage: axiom.read(filename) #optional -- requires Axiom
sage: axiom.get('xx') #optional
'22'
| self) |
Start the Axiom interpreter.
sage: a = Axiom() sage: a.is_running() False sage: a._start() #optional -- requires axiom sage: a.is_running() #optional True sage: a.quit() #optional
Class: AxiomElement
Functions: comma,
type
| self) |
Returns a Axiom tuple from self and args.
sage: two = axiom(2) #optional -- requires Axiom sage: two.comma(3) #optional [2,3] sage: two.comma(3,4) #optional [2,3,4] sage: _.type() #optional Tuple PositiveInteger
| self) |
Returns the type of an AxiomElement.
sage: axiom(x+2).type() #optional -- requires Axiom Polynomial Integer
Special Functions: __call__,
__cmp__,
__getitem__,
__len__,
_latex_
| self, x) |
sage: f = axiom(x+2) #optional -- requires Axiom sage: f(2) #optional 4
| self, other) |
sage: two = axiom(2) #optional -- requires Axiom sage: two == 2 #optional True sage: two == 3 #optional False sage: two < 3 #optional True sage: two > 1 #optional True
| self, n) |
Return the n-th element of this list.
Note: Lists are 1-based.
sage: v = axiom('[i*x^i for i in 0..5]'); v # optional
2 3 4 5
[0,x,2x ,3x ,4x ,5x ]
sage: v[4] # optional
3
3x
sage: v[1] # optional
0
sage: v[10] # optional
Traceback (most recent call last):
...
IndexError: index out of range
| self) |
Return the length of a list.
sage: v = axiom('[x^i for i in 0..5]') # optional
sage: len(v) # optional
6
| self) |
sage: a = axiom(1/2) #optional -- requires Axiom sage: latex(a) #optional 1 \over 2
Class: AxiomExpectFunction
| self, parent, name) |
TESTS:
sage: axiom.upperCase_q upperCase? sage: axiom.upperCase_e upperCase!
Special Functions: __init__
Class: AxiomFunctionElement
| self, object, name) |
TESTS:
sage: a = axiom('"Hello"') #optional -- requires Axiom
sage: a.upperCase_q #optional
upperCase?
sage: a.upperCase_e #optional
upperCase!
sage: a.upperCase_e() #optional
"HELLO"
Special Functions: __init__
See About this document... for information on suggesting changes.