Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
introduce optional argument check
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Apr 21, 2015
1 parent 9b1e098 commit 3a7761e
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
30 changes: 26 additions & 4 deletions src/sage/categories/modules_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,15 +1094,18 @@ def trailing_term(self, cmp=None):
"""
return self.parent().term( *self.trailing_item(cmp=cmp) )

def map_coefficients(self, f):
"""
Mapping a function on coefficients.
def map_coefficients(self, f, check=True):
"""Mapping a function on coefficients.
INPUT:
- ``f`` -- an endofunction on the coefficient ring of the
free module
- ``check``-- (default: ``True``) -- check whether all
images of coefficients under ``f`` are elements of the
coefficient ring.
Return a new element of ``self.parent()`` obtained by applying the
function ``f`` to all of the coefficients of ``self``.
Expand All @@ -1127,8 +1130,27 @@ def map_coefficients(self, f):
sage: a = s([2,1])+2*s([3,2])
sage: a.map_coefficients(lambda x: x*2)
2*s[2, 1] + 4*s[3, 2]
If ``check`` is ``True`` and ``f`` is not an endofunction
for the coefficients at hand, an error is raised::
sage: a.map_coefficients(factor)
Traceback (most recent call last):
...
ValueError: ModulesWithBasis.map_coefficients(f) expects that f produces values in the coefficient ring.
"""
return self.parent().sum_of_terms( (m, f(c)) for m,c in self )
if check:
R = self.parent().base_ring()
def f_check(c):
r = f(c)
if r in R:
return r
else:
raise ValueError("ModulesWithBasis.map_coefficients(f) expects that f produces values in the coefficient ring.")

return self.parent().sum_of_terms( ((m, f_check(c)) for m,c in self), distinct=True )
else:
return self.parent().sum_of_terms( ((m, f(c)) for m,c in self), distinct=True )

def map_support(self, f):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/free_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ def __div__(self, x, self_on_left=False ):

return F._from_dict( D, remove_zeros=False )
else:
return self.map_coefficients(lambda c: _divide_if_possible(c, x))
return self.map_coefficients(lambda c: _divide_if_possible(c, x), check=False)

def _divide_if_possible(x, y):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/root_system/root_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def associated_coroot(self):
#assert(self in self.parent().roots() is not False)
scaled_coroot = self.parent().to_coroot_space_morphism()(self)
s = self.scalar(scaled_coroot)
return scaled_coroot.map_coefficients(lambda c: (2*c) // s)
return scaled_coroot.map_coefficients(lambda c: (2*c) // s, check=False)

def quantum_root(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/sf/jack.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def _normalize(self, x):
.. todo:: this should be a method on the elements (what's the standard name for such methods?)
"""
return x.map_coefficients(self._normalize_coefficients)
return x.map_coefficients(self._normalize_coefficients, check=False)

def _normalize_morphism(self, category):
r"""
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/sf/macdonald.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,7 @@ def _to_s(self, part):
for k in reversed(part):
res = res.creation(k)
res = res._omega_qt_in_schurs()
res = res.map_coefficients(lambda c: c(t,q))
res = res.map_coefficients(lambda c: c(t,q), check=False)
f = lambda part2: res.coefficient(part2)
return f

Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/sf/new_kschur.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def omega_t_inverse(self):
s = self.parent().realization_of().ambient()
t = s.base_ring().gen()
invert = lambda x: s.base_ring()(x.subs(t=1/t))
return self.parent()(s(self).map_coefficients(invert).omega())
return self.parent()(s(self).map_coefficients(invert, check=False).omega())

def is_schur_positive(self, *args, **kwargs):
r"""
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/sf/sfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ def _gram_schmidt(self, n, source, scalar, cache, leading_coeff=None, upper_tria
res = start - sub

if hasattr(self, '_normalize_coefficients'):
res = res.map_coefficients(self._normalize_coefficients)
res = res.map_coefficients(self._normalize_coefficients, check=False)
precomputed_elements.append(res)
# Now, res == precomputed_elements[i]
cache[l[i]] = {}
Expand Down Expand Up @@ -2752,7 +2752,7 @@ def plethysm(self, x, include=None, exclude=None):
pn_pleth = lambda f, n: f.map_support(scale_part(n))

#Takes in a partition and applies
f = lambda part: prod( pn_pleth(p_x.map_coefficients(raise_c(i)), i) for i in part )
f = lambda part: prod( pn_pleth(p_x.map_coefficients(raise_c(i), check=False), i) for i in part )
return parent(p._apply_module_morphism(p(self),f))

__call__ = plethysm
Expand Down

0 comments on commit 3a7761e

Please sign in to comment.