#8890: map_support modifies the zero element of a free module, and related fixes
and cleanup
---------------------------------+------------------------------------------
Reporter: jbandlow | Owner: AlexGhitza
Type: defect | Status: needs_work
Priority: major | Milestone:
Component: algebra | Keywords: free modules
Author: Nicolas M. Thiéry | Upstream: N/A
Reviewer: Jason Bandlow | Merged:
Work_issues: |
---------------------------------+------------------------------------------
Changes (by newvalueoldvalue):
* status: new => needs_work
* author: => Nicolas M. Thiéry
* cc: sage-combinat (added)
* keywords: => free modules
* reviewer: => Jason Bandlow
Old description:
> {{{
> sage: B = CombinatorialFreeModule(ZZ, ['a','b'])
> sage: B.an_element().map_support(lambda i: i)
> 2*B['a'] + 2*B['b']
> sage: B.zero()
> 2*B['a'] + 2*B['b']
> }}}
>
> Looking at the code exposes the problem:
> {{{
> res = self.parent()(0)
> z_elt = {}
> for m,c in self.monomial_coefficients().iteritems():
> z_elt[f(m)] = c
> res._monomial_coefficients = z_elt
> return res
> }}}
>
> We should not change the dictionary of zero!
New description:
{{{
sage: B = CombinatorialFreeModule(ZZ, ['a','b'])
sage: B.an_element().map_support(lambda i: i)
2*B['a'] + 2*B['b']
sage: B.zero()
2*B['a'] + 2*B['b']
}}}
Looking at the code exposes the problem:
{{{
res = self.parent()(0)
z_elt = {}
for m,c in self.monomial_coefficients().iteritems():
z_elt[f(m)] = c
res._monomial_coefficients = z_elt
return res
}}}
We should not change the dictionary of zero!
The patch in progress fixes this by rewriting the code in a generic way;
this fixes by the way another bug when the function f is not injective,
and moves the code to ModulesWithBasis. It also deprecates map_term,
map_mc in favor of map_item
--
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8890#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 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.