powers in the mathematica parser and *^

76 views
Skip to first unread message

Roberto

unread,
Oct 12, 2020, 11:03:56 AM10/12/20
to sympy
from sympy.parsing.mathematica import mathematica

Power with ** works 
_mma = mathematica('3**2', {})
also the ^ works
_mma = mathematica('3^2', {})
but there seems to be a problem with *^ notation 
_mma = mathematica('3*^2', {})
as ^ is parsed as **, without checking ahead if there is any "*^"
SympifyError: Sympify of expression 'could not parse '3***2'' failed, because of exception being raised: SyntaxError: invalid syntax (<string>, line 1) 

Am I misusing the parser?

Aaron Meurer

unread,
Oct 12, 2020, 11:23:31 AM10/12/20
to sympy
It's probably not supported, but it could be added. The Mathematica
parser is still relatively rudimentary, so a lot of syntax features of
Mathematica aren't supported.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/d21ef284-37bb-4f4f-93c1-16efbcc24aadn%40googlegroups.com.

S.Y. Lee

unread,
Oct 16, 2020, 1:21:59 AM10/16/20
to sympy
**, *^ are not valid Mathematica syntax for powers.
and *^ is scientific notation
Also ^^ is the  nnnn expressed in b-base

So the reason that ** had possibly worked before was that although it is not parsed correctly in Mathematica parser, 
it somewhat got parsed in sympify as a valid python syntax and I think that it is completely wrong to parse it as power.

Actually, they are rarely used syntax for Mathematica that I didn't know that they existed, 
and especially *^ and ^^ are much more limited that it only works with restricted classes of digits, with no symbolic capability,
and you can achieve the same thing with other Mathematica functions like FromDigits.
For example, the bases for ^^ is restricted only for 2~36 because after it exceeds 37, you will exhaust every digits 0~9 and English alphabets A~Z, 
so if we are going to build parser for that, it must be considered.

roberto franceschini

unread,
Oct 16, 2020, 8:14:05 AM10/16/20
to sy...@googlegroups.com
You are correct, ** is a whole different thing, I forgot to point out that the parses was doing the python thing, but it should have not. So, all in all

** is mis-interpreted
*^ is mis-interpreted
^^ is mis-interpreted

I think the parser should first look for  "forms" and notation, i.e. start with ** and deal with it, then substitute  *^ -> "e", then ^^ -> dunno what makes that in sympy , then finally ^ -> **.
No idea if regexp is a good way to do that without surprises 

Reply all
Reply to author
Forward
0 new messages