A computer algebra system written in pure Python http://sympy.org/ . To get started to with contributing https://github.com/sympy/sympy/wiki/Introduction-to-contributing
Hey guys, I'm trying to use parse_latex
function as below:
In [1]: from sympy.parsing.latex import parse_latex
In [2]: r = "5^0 - 4^0"
In [3]: parse_latex(r)
ANTLR runtime and generated code versions disagree: 4.9.2!=4.7.2
ANTLR runtime and generated code versions disagree: 4.9.2!=4.7.2
Out[3]: -1 + 5**0
Is there anyway, I can stop parse_latex
to render it as 5^ 0 - 4^0
and now evaluate 4^0
as 1
?
lh = 5**0
and rh = 4**0
but -1 * rh
will be evaluated to -1
. If you want to preserve rh
, it looks like -1 * rh
should be replaced by Mul(-1, rh, evaluate=False)
.
x**2 + x*y**3
becomes x + x*y
. Any pointers as to what I should review/read in the repo or the sympy.org website, to get me started, would be much appreciated!
In [95]: e = x**(S(3)/2) + x**2*y**3 + x + 1/y
...: e
Out[95]:
3/2 2 3 1
x + x â‹…y + x + â”€
y
In [96]: powers = e.atoms(Pow)
...: powers
Out[96]:
âŽ§ 3/2 2 1 3âŽ«
âŽ¨x , x , â”€, y âŽ¬
âŽ© y âŽ
In [97]: int_powers = list(filter(lambda x: x.exp.is_Integer and x.exp > 1, powers))
...: int_powers
Out[97]:
âŽ¡ 3 2âŽ¤
âŽ£y , x âŽ¦
In [98]: {k:v for k, v in zip(int_powers, list(map(lambda x: x.base, int_powers)))}
Out[98]:
âŽ§ 2 3 âŽ«
âŽ¨x : x, y : yâŽ¬
âŽ© âŽ
In [99]: e.subs({k:v for k, v in zip(int_powers, list(map(lambda x: x.base, int_powers)))})
Out[99]:
3/2 1
x + xâ‹…y + x + â”€
y
Mod
in a*(b%3)
where a
and b
are plain Symbol
? SymPy will evaluate it to a*Mod(b, 3)
, while I'd want to keep the precedence explicit (so that ultimately generation of lower level code honours this user-enforced precedence)