#8890: map_support modifies the zero element of a free module, and related fixes
and cleanup
---------------------------------+------------------------------------------
Reporter: jbandlow | Owner: AlexGhitza
Type: defect | Status: needs_review
Priority: major | Milestone: sage-4.4.3
Component: algebra | Keywords: free modules
Author: Nicolas M. ThiƩry | Upstream: N/A
Reviewer: Jason Bandlow | Merged:
Work_issues: |
---------------------------------+------------------------------------------
Changes (by nthiery):
* status: needs_work => needs_review
* milestone: => sage-4.4.3
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!
>
> 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
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 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, and also moves _repr_ to ModulesWithBasis to enable
subcategories to override it.
Patch available from:
http://combinat.sagemath.org/hgwebdir.cgi/patches/file/tip/trac_8890
-free_module-cleanup-nt.patch. Final version will be posted there.
--
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8890#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.