Published 2020-07-29T13:21:00.004Z by Physics Derivation Graph
Quantum mechanics notation is supported in SymPy, but not for parsing Latex input.
>>> import sympy >>> sympy.__version__ '1.5.1' >>> from sympy.parsing.latex import parse_latex >>> sympy.srepr(parse_latex("\\langle a |")) "Mul(Symbol('a'), Symbol('langle'))"
That isn't what I intended.
>>> from sympy.physics.quantum.state import Ket, Bra >>> sympy.latex(Bra('a')) '{\\left\\langle a\\right|}'
SymPy can produce Latex; can it then parse that?
>>> sympy.srepr(parse_latex("{\\left\\langle a\\right|}")) ... File "/usr/local/lib/python3.6/dist-packages/sympy/parsing/latex/_parse_latex_antlr.py", line 57, in syntaxError raise LaTeXParsingError(err) sympy.parsing.latex.errors.LaTeXParsingError: I don't understand this {\left\langle a\right|} ~~~~~~~~~~~~~~~~~~~~~^
A good amount of Dirac notation is supported in Sympy: >>> from sympy.physics.quantum import Operator, Dagger >>> sympy.latex(Bra('a')*Dagger(Operator('A'))*Ket('b')) {\left\langle a\right|} A^{\dagger} {\left|b\right\rangle }