You can use itertools.product:

import itertools

parts = (x, y, z, t)

N = len(parts)
P = itertools.product(*[(-1, 1) for i in range(N-1)])
eqs = [parts[0] + sum(i*p for i, p in zip(a, parts[1:])) for a in P]

for this example, it gives

In [49]: eqs
Out[49]: [-t + x - y - z, t + x - y - z, -t + x - y + z, t + x - y +
z, -t + x + y - z, t + x + y - z, -t + x + y + z, t + x + y + z]

Aaron Meurer


On Mon, Apr 4, 2016 at 8:39 AM, Dos18i2-se Beaverov <dos18i...@gmail.com> wrote:
> Hi, I would like to calculate equations like this:
>
> z = part1 (+/-) part2 (+/-) part3 ... (+/-) partN.
>
> In case of 3 parts it`s rather easy to code all variants of equations (z1 =
> part1 + part2 + part3; z2 = part1 + part2 - part3; z3 = part1 - part2 -
> part3; z4 = part1 - part2 + part3). But in case of four or higher numbers of
> equation parts it seems borring.
> Can I use sympy for this task? Could you please give some simple example or
> some key words for search in the google?
> Thanks in advance.
>
> --
> 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 sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> 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/9892df70-b70f-4aa5-b92d-5563efcb4600%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/CAKgW%3D6Jtzoi62X1ko2d6m%3Dd2Eb7oRhHnL8BXAn%3D0QyF0R2OWxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to