File: parsing.rst

package info (click to toggle)
sympy 1.7.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 37,052 kB
  • sloc: python: 426,614; xml: 359; sh: 318; makefile: 138; lisp: 4
file content (128 lines) | stat: -rw-r--r-- 3,835 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
=======
Parsing
=======

.. module:: sympy.parsing

Parsing Functions Reference
---------------------------

.. autofunction:: sympy.parsing.sympy_parser.parse_expr

.. autofunction:: sympy.parsing.sympy_parser.stringify_expr

.. autofunction:: sympy.parsing.sympy_parser.eval_expr

.. autofunction:: sympy.parsing.maxima.parse_maxima

.. autofunction:: sympy.parsing.mathematica.mathematica


Parsing Transformations Reference
---------------------------------

A transformation is a function that accepts the arguments ``tokens,
local_dict, global_dict`` and returns a list of transformed tokens. They can
be used by passing a list of functions to :py:func:`~.parse_expr` and are
applied in the order given.

.. autodata:: sympy.parsing.sympy_parser.standard_transformations

.. autofunction:: sympy.parsing.sympy_parser.split_symbols

.. autofunction:: sympy.parsing.sympy_parser.split_symbols_custom

.. autofunction:: sympy.parsing.sympy_parser.implicit_multiplication

.. autofunction:: sympy.parsing.sympy_parser.implicit_application

.. autofunction:: sympy.parsing.sympy_parser.function_exponentiation

.. autofunction:: sympy.parsing.sympy_parser.implicit_multiplication_application

.. autofunction:: sympy.parsing.sympy_parser.rationalize

.. autofunction:: sympy.parsing.sympy_parser.convert_xor

These are included in
:data:``sympy.parsing.sympy_parser.standard_transformations`` and generally
don't need to be manually added by the user.

.. autofunction:: sympy.parsing.sympy_parser.lambda_notation

.. autofunction:: sympy.parsing.sympy_parser.auto_symbol

.. autofunction:: sympy.parsing.sympy_parser.repeated_decimals

.. autofunction:: sympy.parsing.sympy_parser.auto_number

.. autofunction:: sympy.parsing.sympy_parser.factorial_notation

Experimental LaTeX Parsing
--------------------------------------

LaTeX parsing was ported from
`latex2sympy <https://github.com/augustt198/latex2sympy>`_. While functional
and its API should remain stable, the parsing behavior or backend may change in
future releases.

LaTeX Parsing Caveats
---------------------------------

The current implementation is experimental. The behavior, parser backend and
API might change in the future. Unlike some of the other parsers, LaTeX is
designed as a *type-setting* language, not a *computer algebra system* and so
can contain typographical conventions that might be interpreted multiple ways.

In its current definition, the parser will at times will fail to fully parse
the expression, but not throw a warning::

    parse_latex(r'x -')

Will simply find ``x``. What is covered by this behavior will almost certainly
change between releases, and become stricter, more relaxed, or some mix.


LaTeX Parsing Functions Reference
---------------------------------------------

.. autofunction:: sympy.parsing.latex.parse_latex

LaTeX Parsing Exceptions Reference
----------------------------------------------

.. autoclass:: sympy.parsing.latex.LaTeXParsingError


SymPy Expression Reference
--------------------------

.. module:: sympy.parsing.sym_expr

.. autoclass:: SymPyExpression
  :members:

Runtime Installation
--------------------

The currently-packaged LaTeX parser backend is partially generated with
`ANTLR4 <http://antlr4.org>`_,
but to use the parser, you only need the ``antlr4`` Python package available.

Depending on your package manager, you can install the right package with, for
example, ``pip3`` (Python 3 only)::

    $ pip3 install antlr4-python3-runtime

or ``pip`` (Python 2 only)::

    $ pip install antlr4-python2-runtime

or ``conda`` (Python 2 or Python 3)::

    $ conda install --channel=conda-forge antlr-python-runtime

The C parser depends on ``clang`` and the Fortran parser depends on ``LFortran``.
You can install these packages using::

    $ conda install -c conda-forge lfortran clang