OpenMaple Application Program Interface (API) for Python
OpenMaple for Python provides an interface between the Maple evaluation engine and a Python program. This is implemented using Python classes and standard interfaces.
Overviewmaple Packagemaple.namespace SubpackageClasses
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk0">Overview</Text-field>
To use the Maple API for Python, start by importing the library maple. This implicitly launches a Maple session.
import maple
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk1">maple Package</Text-field>
The maple package has the following commands:rangesymbolsymbols
To access Maple variables and predefined functions and commands, you can use the symbol or symbols function or import the maple.namespace interface:
The symbol function returns an Expression object.
The symbols function returns a tuple of Expression objects.
The namespace subpackage offers general access to any Maple name or function.
The range function returns an Expression object corresponding to a Maple range.
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk2">maple.namespace Subpackage</Text-field>
The maple.namespace subpackage allows any Maple name or function to be accessed with a simple prefix. This prefix is arbitrary, but for consistency in these examples we will assume the subpackage was assigned the name mpl after being imported with the following command.
import maple.namespace as mpl
Global names or commands may be referenced as mpl.sin, mpl.solve, etc.
Commands in Maple packages or subpackages may be referenced using the chosen prefix and replacing instances of the Maple member selection operator (:-) in the Maple qualified name with a period (.). For example, LinearAlgebra:-Determinant would become mpl.LinearAlgebra.Determinant.import maple.namespace as mpl
lengthFormula = mpl.sqrt( mpl.x**2 + mpl.y**2 + mpl.z**2 )
myMatrix = mpl.Matrix( [[1,2],[3,4]] )
mpl.LinearAlgebra.Determinant( myMatrix )
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk3">Classes</Text-field>
Every OpenMaple object created in a Python session is an Expression object.
Depending on the type of the underlying Maple expression, the object may also be an instance of a subclass of Expression, such as ComplexNumeric or List.
<Text-field style="Heading 3" layout="Heading 3" bookmark="bkmrk4">Class Listing</Text-field>ComplexNumericExpressionExpressionSequenceIndexableListNameRealNumericRTableSetTable
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk5">Expression</Text-field>
The Expression class is the parent class of all the classes that represent Maple objects. Its member functions provide access to all the basic functions that can be performed on a Maple expression.__abs____add____call____ceil____eq____floor____floordiv____ge____getitem____gt____hash____le____len____lt____mul____ne____neg____pow____radd____rfloordiv____rmod____rmul____round____rpow____rsub____rtruediv____sub____truediv____trunc__eval
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk6">ComplexNumeric</Text-field>
The ComplexNumeric class represents complex numbers. Conceptually, a ComplexNumeric object contains two RealNumeric objects: its real part and its imaginary part.
Inherits from Expression.conjugateimagreal
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk7">RealNumeric</Text-field>
The RealNumeric class represents numeric literals. Note that Maple integers and fractions appearing in output from OpenMaple computations are represented as Python integers and Fractions.fraction objects, so this class is effectively only used for floating-point numbers.
Inherits from ComplexNumeric.
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk8">Name</Text-field>
The Name class represents a Maple symbol. This includes both global symbols and names defined in Maple packages.
Inherits from Expression.__getattr__assign
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk9">Indexable</Text-field>
The Indexable class is the parent class of all the classes that represent Maple collections. Its member functions provide access to the basic functions that can be performed on a collection, such as querying its size and testing for membership.
Inherits from Expression.__contains____iter____len__
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk10">ExpressionSequence</Text-field>
The ExpressionSequence class represents a Maple expression sequence.
Inherits from Indexable.__reversed__index
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk11">List</Text-field>
The List class represents a Maple list.
Inherits from Indexable.__reversed__index
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk12">RTable</Text-field>
The RTable class represents an rtable (rectangular table), a Maple data structure for storing homogenous data of arbitrary dimension.
Inherits from Indexable.__bytes__
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk13">Set</Text-field>
The Set class represents a Maple set.
Inherits from Indexable.__`and`____`or`____`xor`____ge____gt____le____lt____sub__isdisjoint
<Text-field style="Heading 4" layout="Heading 4" bookmark="bkmrk14">Table</Text-field>
The Table class represents a table. Data can be inserted and removed from the table and a table can be searched for a particular element.
Inherits from Indexable.
See AlsoPython