Comment #4 on issue 2405 by matt...@gmail.com: solve and solve_poly_system can give ambiguous results
http://code.google.com/p/sympy/issues/detail?id=2405

There will be always some ambiguity as long as solvers aren't returning mappings. However, it's not solve_poly_system() where the discussed ambiguity comes from. This is because if you construct and later unify polynomials, there are rules for this.

In the first case polys assume that x > y (x comes before y), so:

In [1]: parallel_poly_from_expr([x-y-3,x+y+5])
Out[1]:
([Poly(x - y - 3, x, y, domain='ZZ'), Poly(x + y + 5, x, y, domain='ZZ')], {domain: ℤ, gens: (x, y), polys: False})

But you can change this (without affecting generators and domain computations):

In [2]: parallel_poly_from_expr([x-y-3,x+y+5], wrt=y)
Out[2]:
([Poly(-y + x - 3, y, x, domain='ZZ'), Poly(y + x + 5, y, x, domain='ZZ')], {domain: ℤ, gens: (y, x), polys: False, wrt: [y]})

Or using another syntax:

In [3]: parallel_poly_from_expr([x-y-3,x+y+5], sort='y > x')
Out[3]:
([Poly(-y + x - 3, y, x, domain='ZZ'), Poly(y + x + 5, y, x, domain='ZZ')], {domain: ℤ, gens: (y, x), polys: False, sort: [y, x]})

In all other cases the polynomials are already constructed, so unification rules have to be taken into account. If you have two polynomials with the same generators up to a permutation, then poly tries to preserve the order of generators as much as possible, giving the first polynomial precedence, e.g.:

In [14]: from sympy.polys.polyutils import _unify_gens

In [15]: _unify_gens([x, y], [x, y])
Out[15]: (x, y)

In [16]: _unify_gens([x, y], [y, x])
Out[16]: (x, y)

In [17]: _unify_gens([y, x], [y, x])
Out[17]: (y, x)

In [18]: _unify_gens([y, x], [x, y])
Out[18]: (y, x)

This behavior may be seen very complex (maybe it's even too complex), but there is no randomness here. You will always get the same results, unless you tell polynomial manipulation functions to behave differently.

Of course for a user it may be a little too much to know all those rules, but this is his choice to let SymPy figure out what problem he wants to solve. It would help a lot here if solve variables were present in the output.

If you are looking for a source of confusion then lines 159-165 in solvers.py are good candidates (ordering by hash where order is meaningful).

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

Reply via email to