I have a few small questions where I can solve the issues manually and have 
the feeling that in my attempts to solve them with SymPy I am overlooking 
something. The examples below are trivial and easy to solve manually, but 
the project I am working on involves much more complex expressions where it 
would be great to have a better solution in SymPy.
Basically, adding two equations does not produce the desired solution, and 
sums do not expand or simplify as expected.
PS. The print('end') statement is just there as a convenient place for a 
breakpoint in my debugger.

from sympy import symbols, Eq, expand, simplify, latex, oo, Sum
x, y, p, q, a, j, Aj, Bj = symbols('x y p q a j A_j B_j')
eq1 = Eq(x, y)
print(latex(eq1)) # OK
eq2 = Eq(p, q)
print(latex(eq2)) # OK
eq3 = eq1 + eq2
print(latex(eq3)) # not what I want
eq4 = Eq(eq1.lhs + eq2.lhs, eq1.rhs + eq2.rhs)
print(latex(eq4)) # yes, what I want, but tedious
eq5 = a*eq1
print(latex(eq5)) # not exactly what I want
eq6 = Eq(a*eq1.lhs, a*eq1.rhs)
print(latex(eq6)) # yes, what I want, but tedious
ex1 = Sum(Aj + Bj, (j, -oo, oo))
print(latex(ex1)) # OK
ex2 = Sum(Aj - Bj, (j, -oo, oo))
print(latex(ex2)) # OK
ex3 = ex1 + ex2
print(latex(ex3)) # correct, but needs consolidation
ex4 = expand(ex3)
print(latex(ex4)) # latex looks bad
ex5 = simplify(ex3)
print(latex(ex5)) # latex completely wrong
print('end')

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/71f9f37a-1b10-4fe5-b7ef-65f92fe3bc86%40googlegroups.com.
from sympy import symbols, Eq, expand, simplify, latex, oo, Sum
x, y, p, q, a, j, Aj, Bj = symbols('x y p q a j A_j B_j')

eq1 = Eq(x, y)
print(latex(eq1)) # OK
eq2 = Eq(p, q)
print(latex(eq2)) # OK
eq3 = eq1 + eq2
print(latex(eq3)) # not what I want
eq4 = Eq(eq1.lhs + eq2.lhs, eq1.rhs + eq2.rhs)
print(latex(eq4)) # yes, what I want, but tedious
eq5 = a*eq1
print(latex(eq5)) # not exactly what I want
eq6 = Eq(a*eq1.lhs, a*eq1.rhs)
print(latex(eq6)) # yes, what I want, but tedious

ex1 = Sum(Aj + Bj, (j, -oo, oo))
print(latex(ex1)) # OK
ex2 = Sum(Aj - Bj, (j, -oo, oo))
print(latex(ex2)) # OK
ex3 = ex1 + ex2
print(latex(ex3)) # correct, but needs consolidation
ex4 = expand(ex3)
print(latex(ex4)) # latex looks bad
ex5 = simplify(ex3)
print(latex(ex5)) # latex completely wrong

print('end')

Reply via email to