Interface to FriCAS

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.

FriCAS is a free GPL-compatible (modified BSD license) general purpose computer algebra system based on Axiom. The FriCAS website can be found at http://fricas.sourceforge.net/.

AUTHORS:

  • Mike Hansen (2009-02): Split off the FriCAS interface from the Axiom interface.

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

EXAMPLES: We evaluate a very simple expression in FriCAS.

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

The type of a is FriCASElement, i.e., an element of the FriCAS interpreter.

sage: type(a)                            # optional - fricas
<class 'sage.interfaces.fricas.FriCASElement'>
sage: a.parent()                          # optional - fricas
FriCAS

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

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

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

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

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

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

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

sage: print(fricas.eval('factor(x^5 - y^5)'))   # optional - fricas
           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 FriCAS 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 = fricas('x^5 - y^5')                  # optional - fricas
sage: f^2                                     # optional - fricas
   10     5 5    10
  y   - 2x y  + x
sage: f.factor()                              # optional - fricas
           4      3    2 2    3     4
- (y - x)(y  + x y  + x y  + x y + x )

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

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

TESTS:

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

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

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

sage: float(fricas(2))     #optional - fricas
2.0
class sage.interfaces.fricas.FriCAS(name='fricas', command='fricas -nox -noclef', script_subdirectory=None, logfile=None, server=None, server_tmpdir=None, init_code=[')lisp (si::readline-off)'])

Bases: sage.interfaces.axiom.PanAxiom

Interface to a FriCAS interpreter.

console()

Spawn a new FriCAS command-line session.

EXAMPLES:

sage: fricas.console() #not tested
                 FriCAS (AXIOM fork) Computer Algebra System
                        Version: FriCAS 1.0.5
         Timestamp: Thursday February 19, 2009 at 06:57:33
-----------------------------------------------------------------------------
   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.fricas.FriCASElement(parent, value, is_name=False, name=None)

Bases: sage.interfaces.axiom.PanAxiomElement

class sage.interfaces.fricas.FriCASExpectFunction(parent, name)

Bases: sage.interfaces.axiom.PanAxiomExpectFunction

TESTS:

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

Bases: sage.interfaces.axiom.PanAxiomFunctionElement

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.fricas.fricas_console()

Spawn a new FriCAS command-line session.

EXAMPLES:

sage: fricas_console() #not tested
                 FriCAS (AXIOM fork) Computer Algebra System
                            Version: FriCAS 1.0.5
             Timestamp: Thursday February 19, 2009 at 06:57:33
-----------------------------------------------------------------------------
   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.fricas.is_FriCASElement(x)

Return True if x is of type FriCASElement.

EXAMPLES:

sage: from sage.interfaces.fricas import is_FriCASElement #optional - fricas
sage: is_FriCASElement(fricas(2))  #optional - fricas
True
sage: is_FriCASElement(2)  #optional - fricas
False
sage.interfaces.fricas.reduce_load_fricas()

Returns the FriCAS interface object defined in sage.interfaces.fricas.

EXAMPLES:

sage: from sage.interfaces.fricas import reduce_load_fricas
sage: reduce_load_fricas()
FriCAS