Objects - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Objects in Maple 16

With the addition of objects to the language, Maple users can write code that integrates much more closely with Maple.  For a general overview of objects see the object help page.  For details on declaring new objects, see the object,create page.  Objects can implement methods (see object,methods), overload built-ins (see object,builtins) and various operators (see object,operators)  that will be invoked when those objects appear in standard Maple syntax.  This allows user defined objects to integrate into Maple as naturally as built-in Maple types.  In the following example, we implement an object that represents an integer modulo n.


Create a new instance of the IntMod class using the IntMod object factory.

i0m5  IntMod 0, 5 ;

i0m5:=0 mod 5


Notice the nicely printed form.

We can also create a new object by copying an existing one.   In this case we will specify a new value, but the base will be copied from the given object.

i1m5  Object i0m5, 1 ;

i1m5:=1 mod 5


We can test that these newly create objects are instances of the IntMod class

type i1m5, 'IntMod' ;



The ModuleType procedure allows the IntMod type check to support specifying a base.

type i1m5, 'IntMod'3 ;



type i1m5, 'IntMod'5 ;



ModInt implements a '+' operator.  We can use this to generate the rest of the integers mod 5

i2m5  i1m5 + 1;

i2m5:=2 mod 5


i3m5  i2m5 + 1;

i3m5:=3 mod 5


i4m5  i3m5 + 1;

i4m5:=4 mod 5


i4m5 + 1;

0 mod 5



2 mod 5


The implementation of + also supports non-integer values, by leaving them alone.

4 + i1m5 + 18 + i2m5 + 3 + fx + y;

3 mod 5+fx+y


IntMod overloads the * and ^ operators.

i3m5 * i4m5 * y * fx;

2 mod 5yfx


Note that the ^ does not get called in the 0 case, automatic simplification gets in the way.





2 mod 5



4 mod 5



3 mod 5



1 mod 5



2 mod 5


The ModInt object also overloads the convert function.  This allows the conversion of IntMods to integers.

convert i3m5, 'integer' ;