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
4077: use signsimp as first ste… remove factor from calculate_se… fix tests and 6 more (compare)
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)
eq [some equation]
it'll solve it
Why does the following latex code of the function varies from the symbol?
import sympy as sp
r = sp.symbols("r")
print(sp.latex(sp.symbols("\delta\ u_t")))
print(sp.latex(sp.Function("\delta\ u_t")(r)))
gives
\delta u_{t}
\delta\ u_{t}{\left(r \right)}
Notice that the space right after \delta
is escaped for the function, but not for the symbol.
Okay, is there a way I can use the Symbol-like expressions for functions, or define the symbol without the space? The way it gets displayed, it appears as if \delta
and u_t
are two different variables. Ofcourse, sp.symbols("\deltau_t")
, it won't work.
Also, why raw strings for latex?
Okay, is there a way I can use the Symbol-like expressions for functions, or define the symbol without the space? The way it gets displayed, it appears as if
\delta
andu_t
are two different variables. Ofcourse,sp.symbols("\deltau_t")
, it won't work.Also, why raw strings for latex?
Any solution for this?
Maybe someone can explain the following to me:
Using sympy 1.7.1 i get the following:
from sympy import *
init_printing()
a = Symbol('a')
a0, = solveset(Eq(2*a**5,0.34),domain=S.Reals)
a0 # 0.70160032942779
0.70160032942779
print(a0.round(4)) # 0.7016
print(a0.round(4).n(10)) # 0.7015991211
Thank you for any hints.
Wolfgang
Sorry, a very general question, I'm just looking around with sympy.
I was confused by sympy having two implementations of vectors, sympy.vector
an sympy.physics.vector
. They seem to not be sharing code and the documentation for either doesn't mention another one and the reason to have them separate. Why is that? Is there a way to make them interoperate?
Thanks!
=
I'm using sym.Eq(a, b)
sym.solve()
with a list of the expressions