coneill-math / m2r

Macaulay2 interface for R
5 stars 5 forks source link

Parsing error #228

Closed dkahle closed 5 years ago

dkahle commented 5 years ago

Guillaume Pouliot brought this to my attention; looks like a parser error. Thoughts?

library("m2r")
#> Loading required package: mpoly
#>   Please cite m2r! See citation("m2r") for details.
#>   M2 found in /Applications/Macaulay2-1.10/bin

R <- ring("Beta1", "Beta2", "t1", "t2", coefring = "RR", order = "grevlex")
#> Starting M2...
#> done.
gb("10 + 10*Beta1")
#> Beta1  +  1
gb("11 + 10*Beta1")
#> Error in error_on_fail(tokens[i - 1] == ",", paste0("Parsing error: malformed ", : Parsing error: malformed list

a <- gb.("10 + 10*Beta1")
m2_meta(a)$ext_str
#> [1] "map((m2rintring00000001)^1,(m2rintring00000001)^{{-1}},{{Beta1+1}})"

b <- gb.("11 + 10*Beta1")
m2_meta(b)$ext_str
#> [1] "map((m2rintring00000001)^1,(m2rintring00000001)^{{-1}},{{Beta1+1.1}})"

m2_parse(m2_meta(b)$ext_str)
#> Error in error_on_fail(tokens[i - 1] == ",", paste0("Parsing error: malformed ", : Parsing error: malformed list

Created on 2019-08-11 by the reprex package (v0.2.1)

coneill-math commented 5 years ago

Well, I see the issue. Macaulay2 is inconsistent with its toExternalString format for floating points. For example,

> m2("1+1.1")
[1] ".21000000000000001p53e1"
> m2_parse(m2("1+1.1"))
[1] 2.1

is parsed correctly, whereas the output above returned from M2 by gb() contains "1.1", a different format for floating point values than the parser was expecting.

> m2_parse("{1.1}")
# ERROR
> m2("{1.1}")
[1] "{.11000000000000001p53e1}"
> m2_parse(m2("{1.1}"))
M2 List
[[1]]
[1] 1.1
dkahle commented 5 years ago

Hm, tests don't pick up any problems, but I worry about downstream parsing errors with that kind of thing. Is there any Macaulay2 documentation of that behavior?