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
smichr on master
EmptySet/Complexes/nan usage fix #22338 Merge pull request #22370 from … (compare)
H
is an Add
object whose arguments are Mul
objects, not a vector.In [10]: srepr(H)
Out[10]: "Add(Mul(T.x, Function('Hx')(Symbol('x'), Symbol('y'), Symbol('z'))), Mul(T.y, Function('Hy')(Symbol('x'), Symbol('y'), Symbol('z'))), Mul(T.z, Function('Hz')(Symbol('x'), Symbol('y'), Symbol('z'))))"
Hi, I'd like to express a vector norm with indexed variables for differentation, but I don't quite know how. Every search I came up with led to matrix norms, which aren't really in question here. The variables are indeed vectors, but I don't care about the dimensionality in this case. Formulating a difference is easy enough, but I'm not sure how to continue.
# || x_a - y_b ||
x = sp.IndexedBase('x')
a = sp.Idx('a')
y = sp.IndexedBase('y')
b = sp.Idx('b')
diff = (x[a] - y[b])
How could this be achieved? I'm open for any other formulations as well! Much appreciated.
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