21.04.2011 00:35, Aaron S. Meurer пишет:

>>> [expr.subs(i) for i in sol]
>>>
>>>
>>> because subs works with a dictionary.  Actually, looking at it this
>>> way, this data structure is far superior to any of the others.
>>>
>> That won't work if there's an infinite number of solutions.
> 
> But the only way to represent an infinite number of solutions is to use a 
> parameter, which should cancel if you substitute it into the expression.
> 
> Granted, we should also return a list of the parameters somehow, but I think 
> this is something that would be best done with the Solution class.
> 
> Aaron Meurer
> 


If follow completely, it would be useful to have container "Solutions"
which enclose to itself some tasks (iterible, or generator for infinity
number, or method with parameter to obtain parametrized set or sequences
of solutions).

(the name-tokens and workflow are rough)
# two solutions
>>> sols = solve(expr, vars)
>>> type(sols)
<Solutions class>
>>> len(sols)
>>> 2
>>> sols
[{x:1, y:2}, {x:-1, y:-2}]
>>> for sol in sols:...

>>> sols.variables
[x, y]


Also it resolve representation if  there is only one solution:
# one solutions
>>> sols = solve(expr, vars)
>>> len(sols)
>>> 1
>>> solve(expr, vars)  # representation without unnecessary `[` `]`
{x:1, y:2}

# infinity many solutions
>>> sols = solve(expr, vars)
>>> len()
Infinity

# if infinity solutions is related with sequences
>>> sols.can_be_parametrized    
True
>>> sols.can_be_parametrized_as_sequences ()
True
>>> sols.parameterize(Symbol(n, integer=true))
{x:2*pi*n, y:2*pi*n + pi}


# if a few parameters then multi sequences can be used.
>>> sols.parameterize(n, m)
{x:2*pi*n + m, y:2*pi*n + pi - m}

# if it is not related with Sequences, then generator only
# but this case is complicated, because in general the infinite
# sequences can consist of a finit set part and part with infint
parametrized set.
>>> g = sols.generator()
>>> g.next()
{x:1, y:2}

And so on...


If I prefer the way to use a dictionary or the list of dictionary, it is
possible to hide Solution(s) classes. Nothing prevent to do it.
Doesn't it?

>>> len(sols)
>>> for sol in sols:...
>>> sol
{x:1, y:2}
>>> sol.keys()
[x, y]
>>> sol[x]
>>> 1

And at the same time we do not bound the further development with those
classes.


-- 
Alexey U.

-- 
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