String Parsing (Input Standard)
This page is the common standard for all text box inputs. Master these rules and every feature — differentiation, integration, equations, geometry, etc. — will correctly parse your input.
0. Visual Formula Input (v1.6.4 new)
Besides typing directly, click the keyboard icon button to the right of any input box to open the graphical formula editor based on pyqt5-math-widget. Select mathematical structures, operators, or functions via the toolbar; after editing, the formula is automatically converted to a SymPy expression and filled into the input box.
The toolbar groups include: Structure (fractions, roots, powers, etc.), Greek letters, Operators, Functions (sin, cos, log, lim, etc.), and Edit tools.
1. Direct LaTeX Code Input (v1.6.1 new)
Besides standard Python/SymPy syntax, direct LaTeX code input is also supported: prefix the expression with a half-width dollar sign $ as a marker, and the system automatically converts LaTeX to a SymPy expression.
| Math meaning | LaTeX input | Equivalent SymPy input |
|---|---|---|
| x over 2 | $\frac{x}{2} |
x/2 |
| x squared | $x^{2} |
x**2 |
| square root of x | $\sqrt{x} |
sqrt(x) |
| sin(x) | $\sin{x} |
sin(x) |
| natural log ln(x) | $\ln{x} |
log(x) |
| pi | $\pi |
pi |
| infinity ∞ | $\infty |
oo |
Warning
It must start with $ and be a half-width dollar sign. When not starting with $, the system parses using the original SymPy/Python syntax.
LaTeX parsing supports common mathematical symbols and structures; complex expressions can also mix LaTeX and SymPy syntax.
2. Mathematical Symbol Input Standard
- Addition, subtraction, multiplication, division:
+-*/ - Power:
**(e.g.x**2) - Square root:
sqrt() - Absolute value:
abs() - Common logarithm log_a(x):
log(x, a) - Natural logarithm ln(x):
log(x) - Trigonometric functions:
sin()cos()tan()cot()sec()csc() - Inverse trigonometric functions:
asin()acos()atan()acot()etc. - Hyperbolic functions:
sinh()cosh()tanh()etc. - Euler's number:
e - Pi:
pi - Positive / negative infinity:
oo/-oo - Parentheses: use round parentheses
()only - Imaginary unit:
I
Examples
| Math meaning | Expression to input |
|---|---|
| 2x | 2*x |
| x squared | x**2 |
| arithmetic square root of x | sqrt(x) |
| log base 2 of x | log(x,2) |
| natural logarithm ln(x) | log(x) |
| sine of x | sin(x) |
3. Set / Interval Input Standard
- Roster method:
FiniteSet(1,2,3) - Set-builder method:
ImageSet(Lambda(x, f(x)), Domain) - Built-in sets:
- Reals
Reals, ComplexesComplexes, NaturalsNaturals, non-negative integersNaturals0, IntegersIntegers, RationalsRationals, EmptySetEmptySet - Intervals:
- Closed interval
[x,y]:Interval(x,y) - Left-open right-closed
(x,y]:Interval.Lopen(x,y) - Left-closed right-open
[x,y):Interval.Ropen(x,y) - Open interval
(x,y):Interval.open(x,y) - Union:
Union(A,B) - Intersection:
Intersection(A,B) - Complement / difference:
Complement(A,B)(A is the universe)
Examples
| Math meaning | Expression to input |
|---|---|
| set | FiniteSet(1,2) |
| interval [1,2] | Interval(1,2) |
| interval [1,2) | Interval.Ropen(1,2) |
| interval (1,2) | Interval.open(1,2) |
| union {0}∪[1,2] | Union(FiniteSet(0),Interval(1,2)) |
| intersection {1,2}∩{2,3} | Intersection(FiniteSet(1,2),FiniteSet(2,3)) |
| complement R[-1,1] | Complement(Reals,Interval(-1,1)) |
FiniteSet use cases
- Enter
FiniteSet(1,2,3)in the function domain on the "Define" page to restrict the domain to the discrete point set {1,2,3} - Enter
FiniteSet(0,1)in the principal value range on the "Equation" page to restrict solving to roots only within this set - Combination:
Union(Interval(0,1), FiniteSet(2))represents the union of [0,1] and point 2
ImageSet use cases
- Mapped set:
ImageSet(Lambda(x, x**2), Interval(0, 5))represents {x² | x∈[0,5]} - Periodic solution: the solution set of sin(x)=0 can be expressed as
ImageSet(Lambda(n, n*pi), Integers) - Domain description:
ImageSet(Lambda(x, 2*x+1), Integers)represents all odd numbers
4. Function Input Standard
For functions defined on the "Define" page, you can use them directly in most other input boxes:
- As a symbol in operations: having defined
g(x)=x**2, inputg+1/gyieldsx**2 + 1/x**2 - Pass arguments as function calls: having defined
f(x)=x**2, inputf(3)automatically computes3**2=9; nested calls such asf(g(2))are supported
5. Rationalizing the Denominator
In modules such as differentiation, integration, equation solving, and expression transformation, if the result's denominator contains a radical, the system automatically rationalizes the denominator, simplifying the result to its simplest form where both numerator and denominator are polynomials or radicals.
Example
When computing 1/sqrt(2), the result is automatically displayed as sqrt(2)/2 rather than 1/sqrt(2).
6. Differential Equation Input Standard
Differential equation input does not conform to the function input standard above, because the solution of a differential equation is unknown before solving. The system parsing excludes all defined functions to avoid interference, and fixes the unknown function as f(x).
Use f(x).diff(x,n) to denote the n-th derivative with respect to x; 1 can be omitted, so f(x).diff(x) directly denotes the first derivative.
Example
Check "Differential equation", enter f(x).diff(x,1) on the left and f(x)+1 on the right,
which completes the input of equation f'(x)=f(x)+1; solving yields f(x)=C1*exp(x)-1.
Python API
The parsing logic lives in core/sympify.py; the main public function is:
def sympify(expr, fs, locals=None, is_simplify=False, is_rationalize=False):
"""Parse an input expression.
expr (str) : a Python/SymPy expression, or LaTeX code prefixed with $
fs (dict) : function dict; key = name, value = [name, body, domain, var]
locals (dict) : symbol mapping (optional)
is_simplify (bool): whether to auto-simplify
is_rationalize (bool): whether to rationalize the denominator of the result
returns : a SymPy expression; on failure returns the string "不规范的表达式输入"
"""
Workflow: if $-prefixed, treat as LaTeX (via latex2sympy2_extended); expand custom function calls with _preprocess_func_calls; finally evaluate with SymPy's sympify. When is_rationalize=True, radsimp rationalizes the denominator.
Note
Most feature pages call the wrapped functions in functions.<module> (e.g. derivative, integral, solve_fangcheng), which already parse input via sympify internally, so manual calls are rarely needed.