Comment #2 on issue 2343 by [email protected]: as_poly returns None
http://code.google.com/p/sympy/issues/detail?id=2343
Ahh...that's it, Mateusz. There is a loose connection between symbols. The
x and y used to generate the equation are not the same as those used in the
calling environment:
h[1] >>> var('x,y')
(x, y)
h[1] >>> e=Ellipse(Point(0,0), 2, 3)
h[1] >>> f=e.equation()
h[1] >>> f.atoms(Symbol)
set([x, y])
h[2] >>> f.as_poly(x,y)
h[2] >>> [s.assumptions0 for s in f.atoms(Symbol)]
[{'real': True, 'imaginary': False, 'complex': True, 'commutative':
True}, {'rea
l': True, 'imaginary': False, 'complex': True, 'commutative': True}]
h[3] >>> [s.assumptions0 for s in [x,y]]
[{}, {}]
h[4] >>> f.has(x)
True
So even though f has x it's not the same x and apparently polys is more
careful about determining if two symbols with the same name are the same or
not. The short-term fix is to make the generator use user-given variables
else it must return the variables that were used so they can be used by the
user.
h[8] >>> def generate_eq(x='x'):
... if not isinstance(x, Symbol):
... x = Symbol(x, real=True)
... v = x
... else:
... v = x
... return x**2, v
...
h[8] >>>
h[8] >>> generate_eq(y)
(y**2, y)
h[8] >>> eq,v=_
h[8] >>> eq.has(y)
True
h[8] >>> eq.as_poly(y)
Poly(y**2, y, domain='ZZ')
h[8] >>> generate_eq('y') # func defines new one
(y**2, y)
h[8] >>> eq,v=_
h[8] >>> eq.has(y)
True
h[8] >>> eq.as_poly(y)
h[8] >>>
Do you think such generators should always return the construction
variables? Or only if the user doesn't provide their own?
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" 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-issues?hl=en.