#9220: Upredictable parent for polynomial evaluation
------------------------+---------------------------------------------------
Reporter: nbruin | Owner: robertwb
Type: defect | Status: new
Priority: major | Milestone: sage-4.4.4
Component: coercion | Keywords:
Author: | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
------------------------+---------------------------------------------------
Comment(by nbruin):
I think I've found the culprit in:
{{{
built-in method __call__ of
sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular
}}}
Indeed, it tries to coerce the evaluation values into the polynomial ring.
Perhaps it should try to coerce into the base ring of the parent instead?
{{{
if l != parent._ring.N:
raise TypeError, "number of arguments does not match number of
variables in parent"
try:
x = [parent._coerce_c(e) for e in x]
except TypeError:
# give up, evaluate functional
y = parent.base_ring()(0)
for (m,c) in self.dict().iteritems():
y += c*mul([ x[i]**m[i] for i in m.nonzero_positions()])
return y
}}}
If I were to fix this code, I'd simply always do the code under the
"except", but someone probably had a good reason for doing it the way it's
done. Probably because {{{singular_polynomial_call}}} is more efficient? I
see several options:
* Ask the coercion system for a common overring of the base ring of
parent and all the parents of x. If that is parent, then coerce and use
singular_polynomial_call. Otherwise just multiply out manually.
* see if the parent of all members of x is equal to parent (due to the
lax coercion rules, *coercible into* isn't good enough)
* just always evaluate by multiplying out
The first one is the "proper" one in that it uses the coercion system to
figure out if a more efficient option is available. The second option
should be cheap and catch the case where most speed-up should be
attainable. The third option wouldn't waste any time on checking parents,
but would need coercion calls for each coefficient-monomial
multiplication.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9220#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" 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/sage-trac?hl=en.