def __init__(self, A, category=None): """ Initialize ``self``. EXAMPLES:: sage: A = Algebras(QQ).WithBasis().Filtered().example() sage: grA = A.graded_algebra() sage: TestSuite(grA).run(elements=[prod(grA.algebra_generators())]) """ if A not in ModulesWithBasis(A.base_ring().category()).Filtered(): raise ValueError("the base algebra must be filtered and with basis") self._A = A base_ring = A.base_ring() base_one = base_ring.one() category = A.category().Graded().or_subcategory(category) try: opts = copy(A.print_options()) if not opts['prefix'] and not opts['bracket']: opts['bracket'] = '(' opts['prefix'] = opts['prefix'] + 'bar' except AttributeError: opts = {'prefix': 'Abar'} CombinatorialFreeModule.__init__(self, base_ring, A.basis().keys(), category=category, **opts) # Setup the conversion back phi = self.module_morphism(diagonal=lambda x: base_one, codomain=A) self._A.register_conversion(phi)
def homogeneous_component(self, d): """ Return the ``d``-th homogeneous component of ``self``. EXAMPLES:: sage: A = GradedModulesWithBasis(ZZ).example() sage: A.homogeneous_component(4) Degree 4 homogeneous component of An example of a graded module with basis: the free module on partitions over Integer Ring """ from sage.categories.modules_with_basis import ModulesWithBasis from sage.categories.filtered_algebras import FilteredAlgebras if self.base_ring() in FilteredAlgebras: raise NotImplementedError( "this is only a natural module over" " the degree 0 component of the filtered" " algebra and coordinate rings are not" " yet implemented for submodules") category = ModulesWithBasis(self.category().base_ring()) M = self.submodule(self.homogeneous_component_basis(d), category=category, already_echelonized=True) M.rename("Degree {} homogeneous component of {}".format(d, self)) return M
def super_categories(self): """ EXAMPLES:: sage: HeckeModules(QQ).super_categories() [Category of vector spaces with basis over Rational Field] """ R = self.base_ring() return [ModulesWithBasis(R)]
def extra_super_categories(self): r""" EXAMPLES:: sage: FiniteSets().Algebras(QQ).extra_super_categories() [Category of finite dimensional vector spaces with basis over Rational Field] This implements the fact that the algebra of a finite set is finite dimensional:: sage: FiniteMonoids().Algebras(QQ).is_subcategory(AlgebrasWithBasis(QQ).FiniteDimensional()) True """ from sage.categories.modules_with_basis import ModulesWithBasis return [ModulesWithBasis(self.base_ring()).FiniteDimensional()]
def __init__(self, sym, q='q'): r""" Initialize ``self``. TESTS:: sage: Sym = SymmetricFunctions(FractionField(ZZ['q'])) sage: qbar = Sym.qbar() sage: TestSuite(qbar).run() sage: Sym = SymmetricFunctions(QQ) sage: qbar = Sym.qbar(q=2) sage: TestSuite(qbar).run() Check that the conversion `q \to p \to s` agrees with the definition of `q \to s` from [Ram1991]_:: sage: Sym = SymmetricFunctions(FractionField(ZZ['q'])) sage: qbar = Sym.qbar() sage: s = Sym.s() sage: q = qbar.q() sage: def to_schur(mu): ....: if not mu: ....: return s.one() ....: mone = -qbar.base_ring().one() ....: return s.prod(sum(mone**(r-m) * q**(m-1) ....: * s[Partition([m] + [1]*(r-m))] ....: for m in range(1, r+1)) ....: for r in mu) sage: phi = qbar.module_morphism(to_schur, codomain=s) sage: all(phi(qbar[mu]) == s(qbar[mu]) for n in range(6) ....: for mu in Partitions(n)) True """ self.q = sym.base_ring()(q) SymmetricFunctionAlgebra_multiplicative.__init__( self, sym, basis_name="Hecke character with q={}".format(self.q), prefix="qbar") self._p = sym.power() # temporary until Hom(GradedHopfAlgebrasWithBasis work better) category = ModulesWithBasis(self._sym.base_ring()) self.register_coercion( self._p._module_morphism(self._p_to_qbar_on_basis, codomain=self)) self._p.register_coercion( self._module_morphism(self._qbar_to_p_on_basis, codomain=self._p))
def __init__(self, R, n, r): """ Initialize ``self``. TESTS:: sage: T = SchurTensorModule(QQ, 2, 3) sage: TestSuite(T).run() """ C = CombinatorialFreeModule(R, list(range(1, n + 1))) self._n = n self._r = r self._sga = SymmetricGroupAlgebra(R, r) self._schur = SchurAlgebra(R, n, r) cat = ModulesWithBasis(R).TensorProducts().FiniteDimensional() CombinatorialFreeModule_Tensor.__init__(self, tuple([C] * r), category=cat) g = self._schur.module_morphism(self._monomial_product, codomain=self) self._schur_action = self.module_morphism(g, codomain=self, position=1)
def extra_super_categories(self): """ EXAMPLES:: sage: Sets().Algebras(QQ).extra_super_categories() [Category of modules with basis over Rational Field] sage: Sets().Algebras(QQ).super_categories() [Category of modules with basis over Rational Field] sage: Sets().example().algebra(ZZ).categories() [Category of set algebras over Integer Ring, Category of modules with basis over Integer Ring, ... Category of objects] """ from sage.categories.modules_with_basis import ModulesWithBasis return [ModulesWithBasis(self.base_ring())]
def __init__(self, free_module, linear_functions): """ The Python constructor INPUT/OUTPUT: See :func:`LinearTensorParent` TESTS:: sage: from sage.numerical.linear_functions import LinearFunctionsParent sage: LinearFunctionsParent(RDF).tensor(RDF^2) Tensor product of Vector space of dimension 2 over Real Double Field and Linear functions over Real Double Field """ self._free_module = free_module self._linear_functions = linear_functions base_ring = linear_functions.base_ring() from sage.categories.modules_with_basis import ModulesWithBasis Parent.__init__(self, base=base_ring, category=ModulesWithBasis(base_ring))
def __startup__(): import sage.algebras.steenrod.steenrod_algebra import types def resolution(self, memory=None, filename=None): """ The minimal resolution of the ground field as a module over 'self'. TESTS:: sage: from yacop.resolutions.minres import MinimalResolution sage: MinimalResolution(SteenrodAlgebra(7)) is SteenrodAlgebra(7).resolution() True """ from yacop.resolutions.minres import MinimalResolution return MinimalResolution(self, memory=memory, filename=filename) setattr( sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra_generic, "resolution", resolution, ) def Ext(algebra, M, N=None, filename=None): """ ``Ext(M,N)`` over ``algebra``. """ from yacop.resolutions.smashres import SmashResolution assert N is None return SmashResolution(M, algebra.resolution(), filename=filename).Homology() setattr(sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra_generic, "Ext", Ext) # there are known issues in Sage with pickling of morphisms # and we don't want to document the same failures in our test # suite. from sage.combinat.free_module import CombinatorialFreeModule def p_test_pickling(self, tester=None, **options): if not hasattr(self, "_can_test_pickling") or self._can_test_pickling(): tester = self._tester(**options) from sage.misc.all import loads, dumps tester.assertEqual(loads(dumps(self)), self) else: tester.info(" (skipped, not picklable) ", newline=False) def e_test_pickling(self, tester=None, **options): if not hasattr(self, "_can_test_pickling") or self._can_test_pickling(): tester = self._tester(**options) from sage.misc.all import loads, dumps tester.assertEqual(loads(dumps(self)), self) else: tester.info(" (skipped, not picklable) ", newline=False) CombinatorialFreeModule._test_pickling = p_test_pickling # CombinatorialFreeModule.Element._test_pickling = e_test_pickling (no longer possible, by ticket/22632) # workaround for Sage Ticket #13814 from sage.sets.family import LazyFamily from sage.rings.all import Integers if LazyFamily(Integers(), lambda i: 2 * i) == LazyFamily(Integers(), lambda i: 2 * i): def noteq(self, other): if self is other: return True return False LazyFamily.__eq__ = noteq try: 16 in LazyFamily(Integers(), lambda i: 2 * i) except: # we need to overwrite _contains_ in our module base to fix # the test suite of SteenrodModuleBase.basis() def __contains__(self, x): try: return self._contains_(x) except AttributeError: return super(LazyFamily, self).__contains__(x) LazyFamily.__contains__ = __contains__ # workaround for #13811 from sage.sets.family import AbstractFamily def __copy__(self): return self AbstractFamily.__copy__ = __copy__ # LazyFamilies cannot be pickled... turn off the resulting noise def _test_pickling(self, tester=None, **options): pass LazyFamily._test_pickling = _test_pickling # workaround for Sage ticket #13833 from sage.algebras.steenrod.steenrod_algebra import SteenrodAlgebra B = SteenrodAlgebra(2, profile=(3, 2, 1)) A = SteenrodAlgebra(2) id = A.module_morphism(codomain=A, on_basis=lambda x: A.monomial(x)) try: x = id(B.an_element()) except AssertionError: from sage.categories.modules_with_basis import ModuleMorphismByLinearity origcall = ModuleMorphismByLinearity.__call__ def call(self, *args): before = args[0:self._position] after = args[self._position + 1:len(args)] x = args[self._position] nargs = before + (self.domain()(x), ) + after return origcall(self, *nargs) ModuleMorphismByLinearity.__call__ = call # workaround for Sage ticket #18449 from sage.sets.set_from_iterator import EnumeratedSetFromIterator from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets from sage.categories.enumerated_sets import EnumeratedSets from sage.rings.integer_ring import ZZ C = CombinatorialFreeModule(ZZ, EnumeratedSetFromIterator(Integers)) if False and sage.categories.tensor.tensor( (C, )).basis() in FiniteEnumeratedSets(): def __init_18449__(self, set, function, name=None): """ patched __init__ function from ticket #18449 """ from sage.combinat.combinat import CombinatorialClass # workaround #12482 from sage.structure.parent import Parent category = EnumeratedSets() if set in FiniteEnumeratedSets(): category = FiniteEnumeratedSets() elif set in InfiniteEnumeratedSets(): category = InfiniteEnumeratedSets() elif isinstance(set, (list, tuple)): category = FiniteEnumeratedSets() elif isinstance(set, CombinatorialClass): try: if set.is_finite(): category = FiniteEnumeratedSets() except NotImplementedError: pass Parent.__init__(self, category=category) from copy import copy self.set = copy(set) self.function = function self.function_name = name LazyFamily.__init__ = __init_18449__ # use a lower max_runs value for the TestSuite from sage.misc.sage_unittest import InstanceTester InstanceTester.__init_original__ = InstanceTester.__init__ def newinit(self, *args, **kwds): self.__init_original__(*args, **kwds) self._max_runs = 40 InstanceTester.__init__ = newinit # fix a problem for __contain__ in Categories_over_base_ring # when more than one base is involved: from sage.categories.category import Category from sage.categories.category_types import Category_over_base_ring from sage.categories.modules import Modules from sage.categories.algebras import Algebras from sage.categories.modules_with_basis import ModulesWithBasis from sage.rings.finite_rings.finite_field_constructor import GF C = CombinatorialFreeModule(GF(5), ZZ, category=(ModulesWithBasis(GF(5)), Algebras(ZZ))) if C not in Modules(ZZ): _sagecode = Category_over_base_ring.__contains__ Category_over_base_ring.__contains_sage__ = _sagecode def __contains_yacop__(self, Z): ans = self.__contains_sage__(Z) if not ans: try: ans = self in Z.categories() except: pass return ans Category_over_base_ring.__contains__ = __contains_yacop__ # Sage insists that Subquotients of CartesianProducts are again CartesianProducts # (and similarly for TensorProducts). We forcefully disagree: from sage.categories.covariant_functorial_construction import RegressiveCovariantConstructionCategory @classmethod def default_super_categories_yacop(cls, category, *args): """ TESTS:: sage: import yacop sage: # an earlier version of this hack broke the MRO for quasi symmetric functions: sage: QuasiSymmetricFunctions(GF(3)) Quasisymmetric functions over the Finite Field of size 3 """ sageresult = Category.join([ category, super(RegressiveCovariantConstructionCategory, cls).default_super_categories(category, *args) ]) ans = sageresult if isinstance(ans, sage.categories.category.JoinCategory): j = [ cat for cat in sageresult.super_categories() if not hasattr(cat, "yacop_no_default_inheritance") ] ans = Category.join(j) return ans RegressiveCovariantConstructionCategory.default_super_categories = default_super_categories_yacop
def __init__(self, domain, on_generators, position=0, codomain=None, category=None, anti=False): """ Given a map on the multiplicative basis of a free algebra, this method returns the algebra morphism that is the linear extension of its image on generators. INPUT: - ``domain`` -- an algebra with a multiplicative basis - ``on_generators`` -- a function defined on the index set of the generators - ``codomain`` -- the codomain - ``position`` -- integer; default is 0 - ``category`` -- a category; defaults to None - ``anti`` -- a boolean; defaults to False OUTPUT: - module morphism EXAMPLES: We construct explicitly an algbera morphism:: sage: from sage.combinat.ncsf_qsym.generic_basis_code import AlgebraMorphism sage: NCSF = NonCommutativeSymmetricFunctions(QQ) sage: Psi = NCSF.Psi() sage: f = AlgebraMorphism(Psi, attrcall('conjugate'), codomain=Psi) sage: f Generic endomorphism of Non-Commutative Symmetric Functions over the Rational Field in the Psi basis Usually, however, one constructs algebra morphisms using the ``algebra_morphism`` method for an algebra:: sage: NCSF = NonCommutativeSymmetricFunctions(QQ) sage: Psi = NCSF.Psi() sage: def double(i) : return Psi[i,i] sage: f = Psi.algebra_morphism(double, codomain = Psi) sage: f Generic endomorphism of Non-Commutative Symmetric Functions over the Rational Field in the Psi basis sage: f(2*Psi[[]] + 3 * Psi[1,3,2] + Psi[2,4] ) 2*Psi[] + 3*Psi[1, 1, 3, 3, 2, 2] + Psi[2, 2, 4, 4] sage: f.category() Join of Category of hom sets in Category of modules with basis over Rational Field and Category of hom sets in Category of rings When extra properties about the morphism are known, one can specify the category of which it is a morphism:: sage: def negate(i): return -Psi[i] sage: f = Psi.algebra_morphism(negate, codomain = Psi, category = GradedHopfAlgebrasWithBasis(QQ)) sage: f Generic endomorphism of Non-Commutative Symmetric Functions over the Rational Field in the Psi basis sage: f(2*Psi[[]] + 3 * Psi[1,3,2] + Psi[2,4] ) 2*Psi[] - 3*Psi[1, 3, 2] + Psi[2, 4] sage: f.category() Join of Category of hom sets in Category of modules with basis over Rational Field and Category of hom sets in Category of rings If ``anti`` is true, this returns an anti-algebra morphism:: sage: f = Psi.algebra_morphism(double, codomain = Psi, anti=True) sage: f Generic endomorphism of Non-Commutative Symmetric Functions over the Rational Field in the Psi basis sage: f(2*Psi[[]] + 3 * Psi[1,3,2] + Psi[2,4] ) 2*Psi[] + 3*Psi[2, 2, 3, 3, 1, 1] + Psi[4, 4, 2, 2] sage: f.category() Category of hom sets in Category of modules with basis over Rational Field TESTS:: sage: Psi = NonCommutativeSymmetricFunctions(QQ).Psi() sage: Phi = NonCommutativeSymmetricFunctions(QQ).Phi() sage: f = Psi.algebra_morphism(Phi.antipode_on_generators, codomain=Phi) sage: f(Psi[1, 2, 2, 1]) Phi[1, 2, 2, 1] sage: f(Psi[3, 1, 2]) -Phi[3, 1, 2] sage: f.__class__ <class 'sage.combinat.ncsf_qsym.generic_basis_code.AlgebraMorphism'> sage: TestSuite(f).run(skip=['_test_nonzero_equal']) # known issue; see ModuleMorphismByLinearity.__init__ Failure in _test_category: ... The following tests failed: _test_category """ assert position == 0 assert codomain is not None if category is None: if anti: category = ModulesWithBasis(domain.base_ring()) else: category = AlgebrasWithBasis(domain.base_ring()) self._anti = anti self._on_generators = on_generators ModuleMorphismByLinearity.__init__(self, domain=domain, codomain=codomain, position=position, category=category)