20.04.2011 10:58, Mateusz Paprocki пишет:
> Hi,
>
> On 20 April 2011 08:29, Alexey U. Gudchenko <[email protected]> wrote:
>
>> 20.04.2011 09:45, Chris Smith пишет:
>>> Aaron S. Meurer wrote:
>>>>> On Apr 19, 2011, at 9:24 AM, Vinzent Steinberg wrote:
>>>>>
>>>>>> On Apr 18, 9:43 pm, "Aaron S. Meurer" <[email protected]> wrote:
>>>>>>>>>>> solve((x+y-5,x-y-1),x,y) # a system with a single solution
>>>>>>>> {x: 3, y: 2}
>>>>>>>>>>> solve((x+y-5,x-y**2+1),x,y) # s system with two solutions
>>>>>>>> [(3, 2), (8, -3)]
>>>>>>>
>>>>>>> Wow, do we really do that? That's a horrible convention.
>>>>>>
>>>>>> This is indeed inconsistent. Do you think the latter should be
>>>>>> default, even if there is only one solution?
>>>>>>
>>>>>> Vinzent
>>>>>
>>>>> Either that or always return a tuple as values in the dictionary.
>>>
>>> So if there are 4 solution (x, y) = (1, 2), (1, 3), (2, 4), (2, 5) you
>> would get the following?
>>>
>>> ans = {x:(1, 1, 2, 2), y:(2, 3, 4, 5)}
>>>
>>>
>>
>> As variant:
>> One solution:
>> {x: 3, y: 2}
>> Many solutions (therefore means a list of solutions):
>> [{x: 3, y: 2}, {x: 8, y: -3}]
>>
>
> This is probably the best solution (as long as we stay with built-in data
> structures), because this gives the most information and we should also take
> over-determined systems into account. A problem with dicts is that order of
> elements depends on the printer, not on the solve order (e.g. solve(..., [y,
> x]) may give {x: ..., y: ...}), so the result may be misleading (ordered
> dictionary type was added in Python 2.7). Perfect solution would be to have
> a Solution class which would preserve all information about a solution and
> it would allow conversion to dict and/or tuple.
>
>
Solution class is needed indeed. Also, to recognize correctly the
number of solutions with the help of `len` procedure. If we return the
dictionary it is not clear:
>>> len({x: 3, y: 2})
2
>>> [{x: 3, y: 2}, {x: 8, y: -3}]
2 (too)
Or as variant (I don't like), if we return the list [{x: 3, y: 2}] of
length 1, even if one solution is? More typified interface of function
definition in this case, but it is not convinient for the user (he ask
for a solution, and rare expect a few ones).
In any case, a Solution class will isolate and resolve any those
problems (present and, possible, in a future).
--
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.