grzegorzmazur / yacas

Computer calculations made easy
http://www.yacas.org
GNU Lesser General Public License v2.1
124 stars 24 forks source link

convert back to Yacas dummy <OMS cd="yacas" name="..."/> #300

Closed MarcoCostantini closed 4 years ago

MarcoCostantini commented 4 years ago

Let's consider a Yacas object:

In> Solve(x,x)
Out> {x==0}

if this object is converted to OpenMath, then a dummy object <OMS cd="yacas" name="..."/> is created, and this is OK:

In> OMForm(Solve(x,x))
<OMOBJ>
  <OMA>
    <OMS cd="yacas" name="Solve"/>
    <OMV name="x"/>
    <OMV name="x"/>
  </OMA>
</OMOBJ>
Out> True

Of course, it's not possible to do much with this dummy object, but it should be possible at least to convert it back to Yacas, to get the starting object, but it doesn't work:

In> FromString("<OMOBJ><OMA><OMS cd=\"yacas\" name=\"Solve\"/><OMV name=\"x\"/><OMV name=\"x\"/></OMA></OMOBJ> ")OMRead()
Out> OMS("yacas","Solve")(x,x)

By the way, what about this error?

In> OMForm(%)
<OMOBJ>
CommandLine(1) : Invalid argument
Out> False
In>
grzegorzmazur commented 4 years ago

Hi,

This is because for every function a mapping has to be defined, eg mapping for sine looks like this:OMDef( "Sin" , "transc1","sin" );

Majority of standard (this is existing in mainstream mathematics) functions have such mapping defined, Solve() doesn't. I've added mapping for Solve() and your example works as expected, so I'll close the issue now. But if you need other functions to be properly mapped, just lt me know.

With respect to the other issue, OMS("yacas","Solve")(x,x) simply isn't syntactically correct, hence the error.

Anyway, thanks a lot for the effort, thanks to you OpenMath support has a chance to improve :)

Cheers, Grzesiek

MarcoCostantini commented 4 years ago

There can be a lot of yacas functions without a corresponding openmath function, and more can be added in future. Is it possible to have a general mechanism, so that for every yacas function without the corresponding openmath function this translation is done automatically in both verses?

MarcoCostantini commented 4 years ago

Consider the example at page https://yacas.readthedocs.io/en/latest/reference_manual/functional.html t(x) := If(x<=0.5, 2x, 2(1-x));

OMForm(If(x<=0.5, 2x, 2(1-x))) produces and openmath object, and when I convert it back to yacas, I get OMS("yacas","If")(x<=0.5,2x,2(1-x))