Macaulay2 / Macaulay2/M2

the conversion to and from OpenMath of some float numbers doesn't work. The fix is included

Open
#1,145 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

package issue seeking a volunteer
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

```
$ M2
Macaulay2, version 1.15
--loading configuration for package "FourTiTwo" from file /home/kubuntu/.Macaulay2/init-FourTiTwo.m2
--loading configuration for package "Topcom" from file /home/kubuntu/.Macaulay2/init-Topcom.m2
with packages: ConwayPolynomials, Elimination, IntegralClosure, InverseSystems, LLLBases, PrimaryDecomposition, ReesAlgebra, TangentCone, Truncations

i1 : loadPackage "OpenMath"

o1 = OpenMath

o1 : Package

i2 :
-- float numbers with exponent are not supported, and a cryptic error message is generated:
val parse ""

o2 = "

o3 =

RR elt does not match regex

o4 : LibxmlNode (xmlTypeDescription)

i5 : -- this appens also with the float 0.0:
toLibxmlNode openMath (val parse "" )

o5 =

RR elt does not match regex

o5 : LibxmlNode (xmlTypeDescription)
```
In my opinion, this bug is in the function `toExternalString`, which behaves differently on different numbers.

```
i6 : toExternalString 1.0

o6 = .1p53e1

i7 : toExternalString 0.1

o7 = .10000000000000001p53

i8 : toExternalString 0.01

o8 = .1p53e-1

```

If the number starts with `0.` followed by a non zero digit, then the exponent is omitted; instead `toExternalString 0.1` should return `.10000000000000001p53e0`

The following workaround works both if you fix the function `toExternalString` and if you keep it as is.
Again in the file
`Macaulay2/OpenMath/base.m2`
after the lines
```
toOpenMath RR := idCheck(x -> (
sx := toExternalString x;
```
add the line
```
if regex("e", sx) === null then sx = concatenate(sx, "e0");
```

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Macaulay2/OpenMath/base.m2 at the regex used for float parsing and the toOpenMath RR conversion around toExternalString. Reproduce the documented exponent and 0.x examples, then verify that OpenMath floats with exponents parse and that values such as 0.1 and 0.0 convert successfully without the reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
xml
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.