On Oct 4, 5:48 pm, Ondrej Certik <
ond...@certik.cz> wrote:
This seems to almost work. If I set it to:
print [term for term in expr.args if term.as_coeff_terms()[0] >= tol]
Then I can see that the correct terms are printed into a list.
However, when I use the following:
return Add(term for term in expr.args if term.as_coeff_terms()[0] >=
tol)
I get an error:
sympy.core.sympify.SympifyError: SympifyError: <generator object at
0x01911E68> is NOT a valid SymPy expression
The output from the print command I showed above is the following
list:
[0.166666666666667*x1*x2*y2/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*y1*x4**2/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*x1*x4*y1/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*y4*x3**2/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*x3*x4*y4/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*y2*x1**2/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*x2*x3*y3/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3),
0.166666666666667*y3*x2**2/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3)]
So I'm thinking that it matters that a term is not a simple
polynomial, the first term is:
0.166666666666667*x1*x2*y2/(0.5*x1*y2 + 0.5*x2*y3 + 0.5*x3*y4 +
0.5*x4*y1 - 0.5*x1*y4 - 0.5*x2*y1 - 0.5*x3*y2 - 0.5*x4*y3)
(Note that term.as_coeff_terms()[0] == 0.166666666666667 which is
correct)
Thanks for the help!
Scott