Macaulay2 » Documentation
Packages » MapleInterface :: callMaple
next | previous | forward | backward | up | index | toc

# callMaple -- Run a Maple program from Macaulay 2.

- Usage:
    `callMaple(mapleprogram)`
    `callMaple(inputdata1,inputdata2,mapleprogram)`
- Inputs:
  - inputdata1, a string,
  - inputdata2, a string,
  - mapleprogram, a string,
- Optional inputs:
  - store => ..., default value null, Store result of a Maple computation in a file.
- Outputs:
  - a thing,

## Description

This function calls a Mapleprogram given as a string mapleprogram.

Note that any command line there has to end with a semicolon.

The arguments inputdata1 and inputdata2 are here just for convenience and you can put the empty strings if you want or leave them away.

Inside mapleprogram the string placeholder1 is then replaced by the string inputdata1 and placeholder2 is replaced the string inputdata2.

In the string inputdata1 we take care automatically of the main compatibility problem between Macaulay 2 and Maple which is replacing in lists the curly brackets are by square brackets.

The Maple program has to write its output in the Maple variable returnvalue. This is converted in Maple into a string, square brackets are replaced by curly brackets and then this string is evaluated in Macaulay 2 via the function value.

A very simple example:

    i1 : L={3,5}

    o1 = {3, 5}

    o1 : List

    i2 : mapleprogram="L:=placeholder1;returnvalue:=L[1]+L[2];";

    i3 : callMaple(toString L,"",mapleprogram)

    o3 = 8

Here is an example how to send a Matrix to Maple, compute its integer normal form and send it back to Macaulay 2:

    i4 : A=matrix {{1,5,7},{7,13,5}}

    o4 = | 1 5  7 |
         | 7 13 5 |

                  2        3
    o4 : Matrix ZZ  <--- ZZ

    i5 : inputdata1=toString entries A

    o5 = {{1, 5, 7}, {7, 13, 5}}

    i6 : mapleprogram="with(linalg,ismith);A:=placeholder1;S:=ismith(A);returnvalue:=convert(S,listlist);";

    i7 : matrix callMaple(inputdata1,"",mapleprogram)

    o7 = | 1 0  0 |
         | 0 22 0 |

                  2        3
    o7 : Matrix ZZ  <--- ZZ

Using inputdata2 to pass the command ismith to Maple:

    i8 : A=matrix {{1,5,7},{7,13,5}}

    o8 = | 1 5  7 |
         | 7 13 5 |

                  2        3
    o8 : Matrix ZZ  <--- ZZ

    i9 : inputdata1=toString entries A

    o9 = {{1, 5, 7}, {7, 13, 5}}

    i10 : inputdata2="ismith"

    o10 = ismith

    i11 : mapleprogram="with(linalg,placeholder2);A:=placeholder1;S:=placeholder2(A);returnvalue:=convert(S,listlist);";

    i12 : matrix callMaple(inputdata1,inputdata2,mapleprogram)

    o12 = | 1 0  0 |
          | 0 22 0 |

                   2        3
    o12 : Matrix ZZ  <--- ZZ

(Note that it may be more convenient for you to use for mapleprogram the three-slashes string delimiter but this cannot be done here in the doc environment).

Same program but obtaining also the base change matrices:

    i13 : A=matrix {{1,5,7},{7,13,5}}

    o13 = | 1 5  7 |
          | 7 13 5 |

                   2        3
    o13 : Matrix ZZ  <--- ZZ

    i14 : inputdata1=toString entries A

    o14 = {{1, 5, 7}, {7, 13, 5}}

    i15 : inputdata2="ismith";

    i16 : mapleprogram="with(linalg,placeholder2):A:=placeholder1;S:=placeholder2(A,U,V);returnvalue:=[convert(S,listlist),convert(U,listlist),convert(V,listlist)];";

    i17 : L=callMaple(inputdata1,inputdata2,mapleprogram);

    i18 : S=matrix L#0

    o18 = | 1 0  0 |
          | 0 22 0 |

                   2        3
    o18 : Matrix ZZ  <--- ZZ

    i19 : U=matrix L#1

    o19 = | 1  0 |
          | -7 1 |

                   2        2
    o19 : Matrix ZZ  <--- ZZ

    i20 : V=matrix L#2

    o20 = | 1 5  3  |
          | 0 -1 -2 |
          | 0 0  1  |

                   3        3
    o20 : Matrix ZZ  <--- ZZ

    i21 : U*A*V==S

    o21 = true

## Ways to use callMaple:

- `callMaple(String)`
- `callMaple(String,String,String)`

## For the programmer

The object callMaple is a method function with options.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/MapleInterface.m2:270:0.