#20453: wrong conversion from symbolic to SR[]
-----------------------------+------------------------
Reporter: rws | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-7.2
Component: symbolics | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
-----------------------------+------------------------
Comment (by nbruin):
I don't think you'll be able to reasonably code this. It will be too much
of an exception. Base rings ''coerce'' into polynomial rings over them, by
mapping them to constant polynomials. Conversions use coercion if
available. The behaviour you're proposing is so deeply against the general
rules that even if you get this particular case to work, I expect the
exceptional behaviour will be causing problems in all kinds of other
situations.
With the following you should be able to do what you want:
{{{
def mapcons(x,P):
return lambda f: sum([c[0]*P.0^c[1] for c in f.coefficients(x)])
P=SR['x']
H= SetMorphism(Hom(SR,P),mapcons(x,P))
}}}
{{{
sage: var('y')
y
sage: H((x+y)^3).coefficients()
[y^3, 3*y^2, 3*y, 1]
}}}
The map you want, while reasonable and useful, doesn't fit with the
generic rules that exist about conversion maps. That's not a problem. Just
don't insist that every useful map needs to be a conversion map, define
the map you do want, and use that. Perhaps we need better
tools/documentation on how to conveniently define useful maps and
homomorphisms?
Note that applying the map is not actually require longer syntax than
conversion, so calling the map is already very convenient. Getting the map
in the first place is perhaps a little more challenging and a little less
discoverable presently.
--
Ticket URL: <http://trac.sagemath.org/ticket/20453#comment:1>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.