I suspect my initial post was far too ugly for anyone to make sense of. And
in fact the expression I was looking at was correctly labeled as type Add.
But I'm still not getting what I want. A much simpler example is:
x,y,z,n,p = symbols('x y z n p')
expr1 = z * (y * x + y * p) + n
expr2 = collect(expr1,y)
Both expr1 and expr2 yield:
n + z*(p*y + x*y)
However, I was *hoping* that expr2 would yield:
n + z * (y * (p + x))
If I subtract n from either expr1 or expr2, yielding:
expr3 = z*(p*y + x*y)
and then run collect(expr3, y), then I get what I'm looking for:
z * y * (p + x)
Finally:
collect(n + p*y + x*y, y) yields n + y * (p +x) as I would hope.
So it appears that collect doesn't give me the result in the special case
where I have addition as well as undistributed multiplication. Sorry for
what probably seems like a menial question. However, it's important for me
to understand what's going on here as I try to simplify some very
complicated expressions to input into a finite element code. Is there a
better function for achieving what I want to achieve here?
On Tuesday, February 9, 2016 at 10:28:38 PM UTC-5, Alexander Lindsay wrote:
>
> Hi all,
>
> I am making my first in-depth foray into sympy (and also my first in-depth
> foray into using winpdb). I am trying to collect terms that have R in
> expression. Hopefully the pasted screen shot gives an idea of what the
> expression looks like. As hopefully you can see, the expression inside the
> parentheses has multiple terms containing R; however, running collect
> doesn't collect these terms together. I am wondering whether the fact that
> expr is listed as being of type sympy.core.add.Add has something to do with
> this problem. Instinctively I feel like expr should be of type
> sympy.core.mul.Mul since we have the multiplicative term A outside of the
> parentheses.
>
>
>
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/1d5a7ff3-db0d-48cb-87a1-6d8ae4faa7e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.