Home
| Examples
| **Documentation**
| Download
| Publications

The input to MapleMIX is a user supplied "goal" function. MapleMIX will treat this function as the starting point of execution. The parameters of the goal function will become the parameters of the resulting specialized program. The goal function typically just calls the function for which specialization is desired supplying static inputs and using the goal function parameters as dynamic inputs.

Here we will use a simple powering function as an example of how
to invoke MapleMIX. This simple function just computes x^{n}
for n >= 0;

> pow := proc(x, n) > if n = 0 then > 1 > else > x * pow(x, n - 1) > end if > end proc;

In order to specialize this function with respect to a fixed value for
n we write a simple goal function that calls `pow`.

> goal := proc(x) > pow(x, 3) > end proc;

MapleMIX is then invoked by calling the `OnPE` function
passing the goal function.

> cube := OnPE(goal);The result is a specialized version of

> print(cube:-ModuleApply); proc (x) x*x*x end proc

It is often the case that
MapleMIX will generate several residual functions, these are packaged
together and returned as a Maple module. The specialized goal function
becomes the special `ModuleApply` function of the returned module.
In Maple a `ModuleApply` function is implicitly called when
a module value is used in a function call.

> cube(2); 8 > cube:-ModuleApply(2); 8

It is possible to generate alternate specializations by fixing
different parameters to static values. For example we could
fix `x` to a specific value as well.

> goal2 := proc(n) > pow(10, n) > end proc; > pow10 := OnPE(goal2);

In this case MapleMIX returns a module with two functions, `pow_1` and `ModuleApply`.
Only the `ModuleApply` function is "public" by being exported by the module.

> print(pow10); module() local pow_1; export ModuleApply; end module

In this case the specialized code mostly resides in the `pow_1` function.
In this example less specialization is possible because the expression that
terminates the recursion is dynamic, therefore MapleMIX cannot safely unfold
the recursive calls without risking non-termination.

> print(pow10:-pow_1); proc(n) if n = 0 then 1 else 10 * pow_1(n-1) end if end proc

MapleMIX is designed to be fully automatic, meaning that the subject program does not need to be annotated in order to help the partial evaluator. However sometimes it may be advantageous to provide some extra options.

MapleMIX allows partial evaluation to be directed by supplying an option
object that tells MapleMIX how to treat certain functions that it may encounter.
The following example tells MapleMIX not to specialize the `foo` function.
The residual code then contains an explicit call to `foo` even though
MapleMIX normally would have specialized away the call. This can
be quite useful if a function contains constructs not supported by MapleMIX.

> foo := proc(x,y) x + y end proc; > goal := proc(a) a + foo(2,3) end proc; > opts := PEOptions(); > opts:-addFunction(PEOptions:-DYNAMIC, foo); > ps := OnPE(goal, opts); > print(ps:-ModuleApply); proc(a) a + foo(2, 3) end proc

Home
| Examples
| **Documentation**
| Download
| Publications