def __call__(self, x): """ TESTS:: sage: s = sage.combinat.combinatorial_algebra.TestAlgebra(QQ) sage: s([2]) s[2] """ try: return CombinatorialFreeModule.__call__(self, x) except TypeError: pass R = self.base_ring() eclass = self._element_class #Coerce elements of the base ring if not isinstance(x, Element): x = R(x) if x.parent() == R: if x == R(0): return eclass(self, {}) else: return eclass(self, {self._one:x}) #Coerce things that coerce into the base ring elif R.has_coerce_map_from(x.parent()): rx = R(x) if rx == R(0): return eclass(self, {}) else: return eclass(self, {self._one:R(x)}) raise TypeError("do not know how to make x (= %s) an element of self (=%s)"%(x,self))
def __call__(self, x): """ TESTS:: sage: s = sage.combinat.combinatorial_algebra.TestAlgebra(QQ) sage: s([2]) s[2] """ try: return CombinatorialFreeModule.__call__(self, x) except TypeError: pass R = self.base_ring() eclass = self._element_class #Coerce elements of the base ring if not isinstance(x, Element): x = R(x) if x.parent() == R: if x == R(0): return eclass(self, {}) else: return eclass(self, {self._one: x}) #Coerce things that coerce into the base ring elif R.has_coerce_map_from(x.parent()): rx = R(x) if rx == R(0): return eclass(self, {}) else: return eclass(self, {self._one: R(x)}) raise TypeError( "do not know how to make x (= %s) an element of self (=%s)" % (x, self))
def __call__(self, v): """ TESTS:: sage: R = RootSystem(['A',4]).ambient_lattice() sage: R([1,2,3,4,5]) (1, 2, 3, 4, 5) sage: len(R([1,0,0,0,0]).monomial_coefficients()) 1 """ # This adds coercion from a list if isinstance(v, (list, tuple)): K = self.base_ring() return self._from_dict(dict((i,K(c)) for i,c in enumerate(v) if c)) else: return CombinatorialFreeModule.__call__(self, v)
def __call__(self, v): """ TESTS:: sage: R = RootSystem(['A',4]).ambient_lattice() sage: R([1,2,3,4,5]) (1, 2, 3, 4, 5) sage: len(R([1,0,0,0,0]).monomial_coefficients()) 1 """ # This adds coercion from a list if isinstance(v, (list, tuple)): K = self.base_ring() return self._from_dict(dict((i,K(c)) for i,c in enumerate(v) if c)) else: return CombinatorialFreeModule.__call__(self, v)