cutcutcodec.core.compilation.parse¶
Extracting information from string.
Functions
|
Convert the number into fraction, or inf float. |
|
Convert the expression in sympy compilable expression. |
Details
- cutcutcodec.core.compilation.parse.parse_to_number(number: str | Real) Fraction | float[source]
Convert the number into fraction, or inf float.
Raises¶
- ValueError
If is not correct.
Examples¶
>>> import math >>> import numpy as np >>> from cutcutcodec.core.compilation.parse import parse_to_number >>> parse_to_number("0") Fraction(0, 1) >>> parse_to_number("2/3") Fraction(2, 3) >>> parse_to_number("-1e-3") Fraction(-1, 1000) >>> parse_to_number(1) Fraction(1, 1) >>> parse_to_number(1.0) Fraction(1, 1) >>> parse_to_number("inf") inf >>> parse_to_number("oo") inf >>> parse_to_number(math.inf) inf >>> parse_to_number("1k") Fraction(1000, 1) >>> parse_to_number("2.3M") Fraction(2300000, 1) >>>
- cutcutcodec.core.compilation.parse.parse_to_sympy(expr: str | Basic | Complex, symbols: dict[str, Symbol] = None) Basic[source]
Convert the expression in sympy compilable expression.
Parameters¶
- exprstr or sympy.Expr
The string representation of the equation. Some operators like multiplication can be implicit.
- symbolsdict[str, sympy.Symbol]
A dictionary of local variables to use when parsing.
Returns¶
- sympy.core.expr.Expr
The version sympy of the expression.
Raises¶
- SyntaxError
If the entered expression does not allow to properly define an equation.
Examples¶
>>> from cutcutcodec.core.compilation.parse import parse_to_sympy >>> parse_to_sympy(0) 0 >>> parse_to_sympy("1/2 + 1/2*cos(2pi(t - i*j))") 1*cos(2*pi*(-i*j + t))/2 + 1/2 >>>