-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve converting Latex to SymPy #4
Comments
SymPy converts a simple Latex expression to SymPy representation: >>> import sympy
>>> sympy.__version__
'1.8'
>>> from sympy import *
>>> from sympy.parsing.latex import parse_latex
>>> sympy.srepr(parse_latex('T = 1/f'))
ANTLR runtime and generated code versions disagree: 4.9.2!=4.7.2
"Equality(Symbol('T'), Mul(Integer(1), Pow(Symbol('f'), Integer(-1))))" Integration: >>> sympy.srepr(parse_latex('f = \int_a^b x dx'))
ANTLR runtime and generated code versions disagree: 4.9.2!=4.7.2
"Equality(Symbol('f'), Integral(Symbol('x'), Tuple(Symbol('x'), Symbol('a'), Symbol('b'))))" |
SymPy fails on this Latex >>> import sympy
>>> sympy.__version__
'1.8'
>>> from sympy import *
>>> from sympy.parsing.latex import parse_latex
>>> sympy.srepr(parse_latex('\vec{\psi}(r, t)'))
antlr4.error.Errors.LexerNoViableAltException: LexerNoViableAltException(
sympy.parsing.latex.errors.LaTeXParsingError: I don't understand this The desired SymPy representation would be something like Function('psi')(Symbol('r'), Symbol('t') One reason this example is difficult because the dimensionality of >>> from sympy.vector import CoordSys3D, Del, curl, divergence, gradient so it is feasible to define
This seems to necessitate a multi-line SymPy operation to support a single (ill-defined) Latex expression. |
The grammar has more than a dozen logical errors. It would be ideal to reuse the non-recursive terminals, and to rewrite the recursive rules, with the primary goal of improving correctness while not breaking rules that people depend on. ideas on how to proceed would be welcome. I think the following would be helpful. |
SymPy is capable of converting Latex to SymPy. It works for simple Latex, but complicated expressions do not result in the desired SymPy representation.
The text was updated successfully, but these errors were encountered: