Symbolically Speaking...
MuPAD Logo

OpenMath and SCSCP Package for MuPAD


Note: MuPAD is a commercial Computer Algebra System developed by SciFace Software in Paderborn. It is no longer availabe as a standalone product but as the Symbolic Toolbox of Matlab. For more Details see the MuPAD FAQ.

MuPAD, Matlab, SciFace and MathWorks are trademarks of their respective owners and are used for documentation purposes only.

The packages described on this page are developed by Peter Horn, Department of Mathematics, University of Kassel, Germany. It is work done in the SCIEnce EU-Project.


There are two main components to this package:

MuPAD OpenMath Package

The MuPAD OpenMath package is designed to

In contrast to most other OpenMath implementations, you can really use OpenMath in MuPAD to do things with it, That's possibly best showed in a short example:

>> package("OpenMath")
Package 'OpenMath' loading. To get further information try OpenMath::doc()

>> d := OpenMath(sin)
transc1.sin

>> d(9)
transc1.sin(9)

>> dd := d(9*PI)
transc1.sin(arith1.times(9, nums1.pi))
                                                                                                                                              
>> xml := OpenMath::toXml(dd)
<OMA>
  <OMS cd='transc1' name='sin'/>
  <OMA>
    <OMS cd='arith1' name='times'/>
    <OMI>
      9
    </OMI>
    <OMS cd='nums1' name='pi'/>
  </OMA>
</OMA>

>> expand(dd)
sin(9*PI)

>> eval(%)
0

>> s := OpenMath::xml2text(xml)
"<OMA><OMS cd='transc1' name='sin'/>\n<OMA><OMS cd='arith1' name='times'/>\n<OMI>9</OMI>\n
<OMS cd='nums1' name='pi'/>\n</OMA>\n</OMA>\n"
                                                                                                                                              
>> d2 := OpenMath::parse(s)
transc1.sin(arith1.times(9, nums1.pi))

So the same intermediate representation is used no matter whether you create the OpenMath object programmatically, by parsing, or by converting.

Programmatically Creating OpenMath/The OpenMath Domain

To represent the different OpenMath tags, there are the following Domains:

OpenMath::Apply

Constructor: OpenMath::Apply(head, params <, id>)

Parameters:

Representing XML:

<OMA>head params[1] ... params[n]</OMA>

This is the OpenMath datatype used to represent the application of an object (typically a Symbol) on some parameters.

Expands to the application of head to params.

OpenMath::Bind

Constructor: OpenMath::Apply(head, vars, param <, id>)

Parameters:

Representing XML:

<OMBIND> 
    head 
    <OMBVARS>vars[1] ... vars[n]</OMBVARS> 
    expr
</OMBIND>

This is the OpenMath datatype used to represent an expression in which some occurring variables are bound to some other object (typically a Symbol).

Expands to the application of head to vars and param.

OpenMath::Error

Constructor: OpenMath::Error(head, params <, id>)

Parameters:

Representing XML:

<OME>head params[1] ... params[n]</OME>

This is the OpenMath datatype used to represent an OpenMath error, which is the error-application of an object (typically a Symbol) on some parameters.

Expands to an error textually containig head and params.

OpenMath::Float

Constructor: OpenMath::Float(f <, id>)

Parameters:

Representing XML:

<OMF dec='f' />

This is the OpenMath datatype used to store floating point numbers.

Expands to the represented DOM_FLOAT.

OpenMath::Integer

Constructor: OpenMath::Integer(int <, id>)

Parameters:

Representing XML:

<OMI>int</OMI>

This is the OpenMath datatype used to store arbitrary precision integers.

Expands to the represented DOM_INT.

OpenMath::Object

Constructor: OpenMath::Object(param)

Parameters:

Representing XML:

<OMOBJ>param</OMOBJ>

This is the OpenMath datatype used to represent the OMOBJ tag wrapping every vald OpenMath XML tree.

Expands to the expansion of the wrapped OpenMath object.

OpenMath::Reference

Constructor: OpenMath::Reference(href)

Parameters:

Representing XML:

<OMR href='href' />

This is the OpenMath datatype used to represent a reference to a previously defined OpenMath object.

NOTE: Every OpenMath object accepts an additional id parameter. A named reference is then stored in some 'global' registry. Whenever a OpenMath::Reference object is expanded, it looks up the object associated to its name and returns the expansion of that. If such an object can not be found, an error is raised.

Expands to an object or raises an error.

OpenMath::String

Constructor: OpenMath::String(str <, id>)

Parameters:

Representing XML:

<OMSTR>str</OMSTR>
This is the OpenMath datatype used to store strings. Expands to the represented DOM_STRING.

OpenMath::Symbol

Constructor: OpenMath::Symbol(cdname, name <, id>)

Parameters:

Representing XML:

<OMS cd='cdname' name='name' />

This is the OpenMath datatype used to represent symbols. These carry the actual mathematical semantics. They are organized in Content Dictionaries (CDs) and identified by their CD-Name and name. For general details see openmath.org

There are a couple of symbols shipping with the OpenMath library covering the most common functions/symbols.

What happens if MuPAD tries to expand <OMS cd='cdname' name='name' />?

  1. If it is 'pre-packaged', it is used
  2. If it is NOT pre-packaged and the cd is not pre-packaged and there is a file OpenMathSymbols/cdname.mu which contains a table, this table is evaluated and all its entries are added as symbols. This is done ONCE, and the read symbols are 'statically' available for future use.
  3. If it is NOT pre-packaged and there is a file OpenMathSymbols/cdname/name.mu, the content of the file is evaluated and being returned. This is done EVERY TIME the symbol is used, so editing this file changes the bevaviour of the next evaluation.
  4. if no such thing can be found, it expands to the DOM_IDENT `cdname.name`

Expands as above.

OpenMath::Variable

Constructor: OpenMath::Variable(name <, id>)

Parameters:

Representing XML:

<OMV name='name' />

This is the OpenMath datatype used to represent on OpenMath Variable.

Expands to an DOM_IDENT.

Converting MuPAD Expressions to OpenMath

There are two ways of converting MuPAD Expressions to OpenMath:

Parsing OpenMath XML

For parsing OpenMath XML there are two functions available:

In both cases, an object of the OpenMath domain is returned.

Handling OpenMath

Convert to MuPAD

To convert an object of the OpenMath domain to its MuPAD representation, simply use the expand command.

Note that it may me necessary to call eval afterwards to get the actual value.

Convert to XML

To convert an object of the OpenMath domain to its XML representation (that is, a domain element of adt:Xml), you need to call OpenMath::toXml(...) on it.

Note that you need to call expr2text or OpenMath::xml2text on it afterwards, if you want the string containing the XML representation.

SCSCP client

The SCSCP domain is contained in the OpenMath package and is used to represent an SCSCP Client connection.

Constructor: SCSCP(host <, port>)

Parameters:

By the call SCSCP(host, port), an SCSCP connection object is created, which can be used to send comands to the SCSCP server. Note that the actual connection is initiated on construction by starting the java program WUPSI found in OpenMath/lib/wupsi.jar. It is using an asynchroneous file system based message exchange mode and thus can be used to do computations in the background.

>> s := SCSCP("somewhere.org", 26133);

  SCSCP(somewhere.org, 26133)

To actually let the server compute something, you use

>> s::compute(...)

or, equivalently

>> s(...)

Note that it may be necessary to wrap the parameter in a hold() to prevent premature evaluation in MuPAD.

To use the connection asynchroneously, the commands send and retrieve are used:

>> s::send(...)
3

where the returned integer is used to identify the computation and to retrieve the result later on:

>> s::retrieve(3)
...

Note, that retrieve returns FAIL if the result of the computation is not yet computed unless you specify a second parameter TRUE:

>> s::retrieve(3, true)
...

Please disconnect the connection after usage (and before reset or the like) because otherwise the runing java program (aka WUPSI) will keep running (and using resources as memory and cpu time):

>> s::close()
Closed connection.

Example session

// We first load the package:

>> package("OpenMath")
Package 'OpenMath' loading. To get further information try OpenMath::doc()

// Now, we connect to a KANT SCSCP server running in Berlin:

>> s := SCSCP("issel.math.tu-berlin.de")
Established SCSCP Connection to host 'issel.math.tu-berlin.de' on port '26133'.
Using temporary directory '/var/tmp/tmp.6.lt7xbE'.
SCSCP(issel.math.tu-berlin.de, 26133)

// s now represents the SCSCP connection, and we can use it to do some computation
// (hold is necessary to prevent premature evaluation)

>> s(hold(1+1))
2

// So, KANT is obviously able to add numbers, what about the Euler Phi Function 
// for 2^3-1, ..., 2^10-1?

>> L := [s::compute(hold(numlib::phi)(2^i-1)) $ i=3..10]
[6, 8, 30, 36, 126, 128, 432, 600]

// This worked, but took quite some time. Sad, since it was KANT computing, not MuPAD. 
// Possibly, we can spend our time better during the computation... 
// send and retrieve are functions to do asynchronous communication:

>> L1 := [s::send(hold(numlib::phi)(2^i-1)) $ i=10..160]:
>> L2 := [s::retrieve(i) $ i in L1];
   nops(select(L2, _equal, FAIL))
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13...23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, \
36, 37, 38, 39, 40, 41, 42, 43, 44, 45,...5, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 6\
8, 69, 70, 71, 72, 73, 74, 75, 76, 77, ..., 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 10\
0, 101, 102, 103, 104, 105, 106, 107, 1... 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 1\
26, 127, 128, 129, 130, 131, 132, 133, ..., 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, \
152]                                   
[600, FAIL, FAIL, FAIL, FAIL, FAIL, FAI... FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI\
L, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, ...IL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, \
FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI... FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI\
L, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, ...IL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, \
FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI... FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI\
L, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, ...IL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, \
FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI... FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAI\
L]
150

// So, we request the computation of the Euler Phi Function for 2^10-1,  ... 2^160-1. 
// In L1 there are integers stored identifying the corresponding computation. 
// We immediately retrieve the results and see that most are still FAIL which means
// "not yet computed".

>> L3 := [s::retrieve(i) $ i in L1];
   nops(select(L3, _equal, FAIL))
[600, 1936, 1728, 8190, 10584, 27000, 3...1778112, 2640704, 8210080, 6635520, 32400000, 447174\
00, 113467392, 132765696, 533826432, 53...36448, 11452896600, 32524632000, 26121388032, 136822\
635072, 183250539864, 465193834560, 473...2, 8774777333880, 8834232287232, 28548223200000, 459\
14084232320, 140646443289600, 109586090...00, 1910296842179040, 2338996194662400, 900565310112\
0000, 9618417501143040, 329279978649600...736, 187825489127202816, 576457548871463200, 4064670\
72000000000, 2305843009213693950, 30744...208981628670443520, 35699016772227627000, 3922296603\
2225243136, 147573951827644447920, 1560...40, 659182701276288000000, 2361172847348193467520, 1\
678517965443311861760, FAIL, FAIL, FAIL...FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL\
, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, F...L, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, F\
AIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL...FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL\
, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, F...L, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, F\
AIL, FAIL, FAIL, FAIL, FAIL, FAIL]
88

// A moment later, there are only 88 non-computed requests, ...

>> L4 := [s::retrieve(i) $ i in L1];
   nops(select(L4, _equal, FAIL))
[600, 1936, 1728, 8190, 10584, 27000, 3...1778112, 2640704, 8210080, 6635520, 32400000, 447174\
00, 113467392, 132765696, 533826432, 53...36448, 11452896600, 32524632000, 26121388032, 136822\
635072, 183250539864, 465193834560, 473...2, 8774777333880, 8834232287232, 28548223200000, 459\
14084232320, 140646443289600, 109586090...00, 1910296842179040, 2338996194662400, 900565310112\
0000, 9618417501143040, 329279978649600...736, 187825489127202816, 576457548871463200, 4064670\
72000000000, 2305843009213693950, 30744...208981628670443520, 35699016772227627000, 3922296603\
2225243136, 147573951827644447920, 1560...40, 659182701276288000000, 2361172847348193467520, 1\
678517965443311861760, 9423214667094417...466841600000000000, 40033380605795207479296, 1417960\
06799615618522688, 17043290616449454739...676952285184000000, 2043229787307479663640576, 31847\
22905274539255351808, 96134939428037577...7437417171784971522603000, 5145583845196882421075952\
0, 131852706288937189380808704, 1458571...37449562110, 574976071743353280000000000, 2453389017\
806598433867468800, 2571221969843915423...8, 13149521939289727941746688000, 381354217093294276\
16227500000, 30685450186823715268098785...04736830141144459574539583488, 504229778688732163627\
192123392, 5707676340000000000000000000...856892692542013109012679884800, 10141204797849178782\
029636868816, 9914249486423333770887168...00, 53571747423621651587342254080000, 16225927682921\
3363391578010288126, 123351940301726295...L, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, F\
AIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL...FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL\
, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, F...L, FAIL, FAIL, FAIL, FAIL, FAIL]
52

// 52, ...

>> L5 := [s::retrieve(i) $ i in L1];
   nops(select(L5, _equal, FAIL))
[600, 1936, 1728, 8190, 10584, 27000, 3...1778112, 2640704, 8210080, 6635520, 32400000, 447174\
00, 113467392, 132765696, 533826432, 53...36448, 11452896600, 32524632000, 26121388032, 136822\
635072, 183250539864, 465193834560, 473...2, 8774777333880, 8834232287232, 28548223200000, 459\
14084232320, 140646443289600, 109586090...00, 1910296842179040, 2338996194662400, 900565310112\
0000, 9618417501143040, 329279978649600...736, 187825489127202816, 576457548871463200, 4064670\
72000000000, 2305843009213693950, 30744...208981628670443520, 35699016772227627000, 3922296603\
2225243136, 147573951827644447920, 1560...40, 659182701276288000000, 2361172847348193467520, 1\
678517965443311861760, 9423214667094417...466841600000000000, 40033380605795207479296, 1417960\
06799615618522688, 17043290616449454739...676952285184000000, 2043229787307479663640576, 31847\
22905274539255351808, 96134939428037577...7437417171784971522603000, 5145583845196882421075952\
0, 131852706288937189380808704, 1458571...37449562110, 574976071743353280000000000, 2453389017\
806598433867468800, 2571221969843915423...8, 13149521939289727941746688000, 381354217093294276\
16227500000, 30685450186823715268098785...04736830141144459574539583488, 504229778688732163627\
192123392, 5707676340000000000000000000...856892692542013109012679884800, 10141204797849178782\
029636868816, 9914249486423333770887168...00, 53571747423621651587342254080000, 16225927682921\
3363391578010288126, 123351940301726295...590307830832, 717709346317655597032427520000000, 221\
5284311186607256078262064316416, 240712...495821490560709669174725120, 11846856184820457329145\
512419614720, 3934027996906890926660935...656194560, 138499492979567032899631188101038080, 221\
452611594919528321884264560640000, 6565...21234411085951401984000000000000, 251084090621904839\
6167001678273299008, 354460798875977565...31508948042637415424, 113391481185645420534263109927\
45676800, 41071880671279428824073086400...09722093568, 170141183460469231731687303715884105726\
, 1698751076994102941595497169413996544...12640, 791833580987845895506908728919000000000, 2711\
908140936452545320278240216677456816, 2...4, 10803274696870990546240110208762211434488, 145187\
12265628834194002277420894154513920, 35...0, 43359134801337627438882344989572779212800, 174224\
571863520493287776724605868623539744, 1...800, 696898287453958097040785987678873251389600, 581\
260973292210752459947423825920000000000...7056000, 3716774438970406511087878052673397835366400\
, 1054443384325986568080345947511549191...90213024727040, 429179661064150954063036368954396270\
71270400, 59299317497289299209298926313...821431350314326521724928, 18775182614499157340560133\
3668951989204025344, FAIL, FAIL, FAIL, ...IL, FAIL, FAIL]
12

// 12, ...

>> L6 := [s::retrieve(i) $ i in L1];
   nops(select(L6, _equal, FAIL))
[600, 1936, 1728, 8190, 10584, 27000, 3...1778112, 2640704, 8210080, 6635520, 32400000, 447174\
00, 113467392, 132765696, 533826432, 53...36448, 11452896600, 32524632000, 26121388032, 136822\
635072, 183250539864, 465193834560, 473...2, 8774777333880, 8834232287232, 28548223200000, 459\
14084232320, 140646443289600, 109586090...00, 1910296842179040, 2338996194662400, 900565310112\
0000, 9618417501143040, 329279978649600...736, 187825489127202816, 576457548871463200, 4064670\
72000000000, 2305843009213693950, 30744...208981628670443520, 35699016772227627000, 3922296603\
2225243136, 147573951827644447920, 1560...40, 659182701276288000000, 2361172847348193467520, 1\
678517965443311861760, 9423214667094417...466841600000000000, 40033380605795207479296, 1417960\
06799615618522688, 17043290616449454739...676952285184000000, 2043229787307479663640576, 31847\
22905274539255351808, 96134939428037577...7437417171784971522603000, 5145583845196882421075952\
0, 131852706288937189380808704, 1458571...37449562110, 574976071743353280000000000, 2453389017\
806598433867468800, 2571221969843915423...8, 13149521939289727941746688000, 381354217093294276\
16227500000, 30685450186823715268098785...04736830141144459574539583488, 504229778688732163627\
192123392, 5707676340000000000000000000...856892692542013109012679884800, 10141204797849178782\
029636868816, 9914249486423333770887168...00, 53571747423621651587342254080000, 16225927682921\
3363391578010288126, 123351940301726295...590307830832, 717709346317655597032427520000000, 221\
5284311186607256078262064316416, 240712...495821490560709669174725120, 11846856184820457329145\
512419614720, 3934027996906890926660935...656194560, 138499492979567032899631188101038080, 221\
452611594919528321884264560640000, 6565...21234411085951401984000000000000, 251084090621904839\
6167001678273299008, 354460798875977565...31508948042637415424, 113391481185645420534263109927\
45676800, 41071880671279428824073086400...09722093568, 170141183460469231731687303715884105726\
, 1698751076994102941595497169413996544...12640, 791833580987845895506908728919000000000, 2711\
908140936452545320278240216677456816, 2...4, 10803274696870990546240110208762211434488, 145187\
12265628834194002277420894154513920, 35...0, 43359134801337627438882344989572779212800, 174224\
571863520493287776724605868623539744, 1...800, 696898287453958097040785987678873251389600, 581\
260973292210752459947423825920000000000...7056000, 3716774438970406511087878052673397835366400\
, 1054443384325986568080345947511549191...90213024727040, 429179661064150954063036368954396270\
71270400, 59299317497289299209298926313...821431350314326521724928, 18775182614499157340560133\
3668951989204025344, 713623846352979940...530545098631270400000000000000000000, 28542683344410\
01687780807784081807010857280000, 28445...920, 9543270230349312416152874781983881475047173120,\
 13909672676168170222852662975186748384...35288800838200000000, 368983907821874770222345976590\
99751094681600000, 18268770444885528826...2390305561520339446222293318766776286048, 6261565154\
27767945207338129738188069928960000000,...40000000000]
0

// ...and done we are.

Obviously, we COULD have done something reasonable in the meantime instead of waiting actively.

Licensing

The MuPAD OpenMath Package is published under the Apache 2 License and thus can be used free of charge.

If you have any suggestions on how to improve the package, please feel free to contact us.