grzegorzmazur / yacas

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

OpenMath in Yacas, part 2 #294

Closed MarcoCostantini closed 4 years ago

MarcoCostantini commented 4 years ago

############ NaN, INF, -INF

When converting from OpenMath to Yacas, also the floats NaN, INF, -INF should be converted. For instance, the following should be converted to the native Yacas NaN and infinity, <OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0" cdbase="http://www.openmath.org/cd"> <OMA> <OMS cd="list1" name="list" /> <OMF dec="NaN" /> <OMF dec="INF" /> <OMF dec="-INF" /> </OMA> </OMOBJ>

On the other hand, when converting from Yacas to OpenMath, these are used: <OMS cd="nums1" name="infinity"/> <OMS cd="nums1" name="NaN"/> which is perfect.

############ OpenMath generated by Yacas doesn't validate

Currently, when converting <OMF dec="-INF" /> to Yacas, -INF is treated like a variable with the name starting with a minus: In> FromString("<OMOBJ><OMF dec=\""-INF\""/></OMOBJ> ")OMRead() Out> -INF
In> OMForm(%) <OMOBJ> <OMV name="-INF"/> </OMOBJ> Out> True In>

When converting back to OpenMath, the result doesn't even validate, even if the namespace is added <OMOBJ xmlns="http://www.openmath.org/OpenMath" version="2.0" cdbase="http://www.openmath.org/cd"> <OMV name="-INF"/> </OMOBJ>

(To validate OpenMath pieces, it can be used the online validator https://www.liquid-technologies.com/online-relaxng-validator with the grammar copied from https://www.openmath.org/standard/om20-2019-07-01/omstd20.html#app_openmath.rng)

########### Unary minus instead of binary minus

In these cases, when converting from Yacas to OpenMath, it should be used the unary minus instead of binary minus.

In> -Pi Out> -Pi In> OMForm(%) <OMOBJ> <OMA> <OMS cd="arith1" name="minus"/> <OMS cd="nums1" name="pi"/> </OMA> </OMOBJ>

In this example, pi is in fact the subtrahend, not the minuend before a binary minus. See also https://www.openmath.org/cd/arith1.html#unary_minus https://www.openmath.org/cd/arith1.html#minus

Another example in which unary_minus would required instead of minus is: In> Solve(x^2-2,x)[2][2] Out> -Sqrt(2) In> OMForm(%) <OMOBJ> <OMA> <OMS cd="arith1" name="minus"/> <OMA> <OMS cd="arith1" name="root"/> <OMI>2</OMI> <OMI>2</OMI> </OMA> </OMA> </OMOBJ> Out> True

grzegorzmazur commented 4 years ago

I've split the issue, moving the part related to unary minus to #305