On Sun, Feb 19, 2012 at 2:24 PM, Aaron Meurer <[email protected]> wrote:

> I just noticed this behavior of solve:
>
> In [258]: print ([b.coeff(eps**i) for i in range(2, 8)])
> [2*alpha2 - 2*b2 + 1, -alpha2 + 2*b2, -alpha2*b2 + 2*alpha4 + b2**2 -
> 2*b4, -alpha4 + 2*b4, -alpha2*b4 - alpha4*b2 + 2*alpha6 + 2*b2*b4 -
> 2*b6, -alpha6 + 2*b6]
>
> In [259]: solve([b.coeff(eps**i) for i in range(2, 8)])
> Out[259]: [{α₂: -1, α₄: 1/4, α₆: -1/8, b₂: -1/2, b₄: 1/8, b₆: -1/16}]
>
> Can someone explain why it returns the dict inside a list?  Is that
> necessary?  In 0.7.1, we got:
>
> It's in a list because there may have been more than one solution (since
the equations are non-linear). Kind of like cse, we return a list so you
know what you are going to get. It's in a dictionary because you didn't say
what the symbols should be so the only way to be unambiguous is to tell you
what the symbols are. If you had specified the symbols you would have
received one or more tuples of values corresponding in order the the
symbols you specified.

>>> eqs
[2*alpha2 - 2*b2 + 1, -alpha2 + 2*b2, -alpha2*b2 + 2*alpha4 + b2**2 - 2*b4,
-alp
ha4 + 2*b4, -alpha2*b4 - alpha4*b2 + 2*alpha6 + 2*b2*b4 - 2*b6, -alpha6 +
2*b6]
>>> list(reduce(set.union, [e.free_symbols for e in eqs], set()))
[alpha6, b2, alpha2, b4, alpha4, b6]
>>> syms=_
>>> solve(eqs, syms)
[(-1/8, -1/2, -1, 1/8, 1/4, -1/16)]

I think the docstring details all the types of output for given inputs...I
think you will only get a dictionary or None for a linear system:

>>> solve([x-3,y-4], x,y)
{x: 3, y: 4}
>>> solve([x-3,y**2-4], x,y)
[(3, -2), (3, 2)]
>>> solve(x-3,x)
[3]
>>> solve([x-3],x)
{x: 3}

/c

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to