Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing a generic one method for unital algebras #36095

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/sage/categories/algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,8 @@ def extra_super_categories(self):
sage: C.extra_super_categories()
[Category of algebras over Rational Field]
sage: sorted(C.super_categories(), key=str)
[Category of Cartesian products of distributive magmas and additive magmas,
Category of Cartesian products of monoids,
Category of Cartesian products of vector spaces over Rational Field,
[Category of Cartesian products of monoids,
Category of Cartesian products of unital algebras over Rational Field,
Category of algebras over Rational Field]
"""
return [self.base_category()]
Expand Down
12 changes: 7 additions & 5 deletions src/sage/categories/algebras_with_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ class ParentMethods:
@cached_method
def one_from_cartesian_product_of_one_basis(self):
"""
Returns the one of this Cartesian product of algebras, as per ``Monoids.ParentMethods.one``
Return the one of this Cartesian product of algebras, as per
``Monoids.ParentMethods.one``

It is constructed as the Cartesian product of the ones of the
summands, using their :meth:`~AlgebrasWithBasis.ParentMethods.one_basis` methods.
Expand All @@ -248,7 +249,7 @@ def one_from_cartesian_product_of_one_basis(self):
word:

sage: B = cartesian_product((A, A, A)) # optional - sage.combinat
sage: B.one_from_cartesian_product_of_one_basis() # optional - sage.combinat
sage: B.one_from_cartesian_product_of_one_basis() # optional - sage.combinat
B[(0, word: )] + B[(1, word: )] + B[(2, word: )]
sage: B.one() # optional - sage.combinat
B[(0, word: )] + B[(1, word: )] + B[(2, word: )]
Expand All @@ -271,10 +272,11 @@ def one(self):
sage: B.one() # optional - sage.combinat
B[(0, word: )] + B[(1, word: )] + B[(2, word: )]
"""
if all(hasattr(module, "one_basis") for module in self._sets):
if all(hasattr(module, "one_basis") and module.one_basis is not NotImplemented for module in self._sets):
return self.one_from_cartesian_product_of_one_basis
else:
return NotImplemented
return self._one_generic

_one_generic = UnitalAlgebras.CartesianProducts.ParentMethods.one

# def product_on_basis(self, t1, t2):
# would be easy to implement, but without a special
Expand Down
55 changes: 54 additions & 1 deletion src/sage/categories/unital_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
from sage.categories.homset import Hom
from sage.categories.rings import Rings
from sage.categories.magmatic_algebras import MagmaticAlgebras
from sage.categories.cartesian_product import CartesianProductsCategory


class UnitalAlgebras(CategoryWithAxiom_over_base_ring):
"""
The category of non-associative algebras over a given base ring.

A non-associative algebra over a ring `R` is a module over `R`
which s also a unital magma.
which is also a unital magma.

.. WARNING::

Expand Down Expand Up @@ -377,3 +378,55 @@ def from_base_ring_from_one_basis(self, r):
3*B[word: ]
"""
return self.term(self.one_basis(), r)

class CartesianProducts(CartesianProductsCategory):
r"""
The category of unital algebras constructed as Cartesian products
of unital algebras.

This construction gives the direct product of algebras. See
discussion on:

- http://groups.google.fr/group/sage-devel/browse_thread/thread/35a72b1d0a2fc77a/348f42ae77a66d16#348f42ae77a66d16
- :wikipedia:`Direct_product`
"""
def extra_super_categories(self):
"""
A Cartesian product of algebras is endowed with a natural
unital algebra structure.

EXAMPLES::

sage: from sage.categories.unital_algebras import UnitalAlgebras
sage: C = UnitalAlgebras(QQ).CartesianProducts()
sage: C.extra_super_categories()
[Category of unital algebras over Rational Field]
sage: sorted(C.super_categories(), key=str)
[Category of Cartesian products of distributive magmas and additive magmas,
Category of Cartesian products of unital magmas,
Category of Cartesian products of vector spaces over Rational Field,
Category of unital algebras over Rational Field]
"""
return [self.base_category()]

class ParentMethods:
@cached_method
def one(self):
r"""
Return the multiplicative unit element.

EXAMPLES::

sage: S2 = simplicial_complexes.Sphere(2)
sage: H = S2.cohomology_ring(QQ)
sage: C = cartesian_product([H, H])
sage: one = C.one()
sage: one
B[(0, (0, 0))] + B[(1, (0, 0))]
sage: one == one * one
True
sage: all(b == b * one for b in C.basis())
True
"""
data = enumerate(self.cartesian_factors())
return self._cartesian_product_of_elements([C.one() for i, C in data])