Skip to content

Commit f4b2fe9

Browse files
author
Release Manager
committed
gh-36095: Implementing a generic one method for unital algebras <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> We implement a generic `one()` method for unital algebras in order to fix the following: ```python sage: S2 = simplicial_complexes.Sphere(2) sage: H = S2.cohomology_ring(QQ) sage: C = cartesian_product([H, H]) sage: C.one() # this raises an error currently B[(0, (0, 0))] + B[(1, (0, 0))] ``` ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36095 Reported by: Travis Scrimshaw Reviewer(s): Frédéric Chapoton
2 parents 8c8f129 + 82d7e9d commit f4b2fe9

3 files changed

Lines changed: 62 additions & 8 deletions

File tree

src/sage/categories/algebras.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ def extra_super_categories(self):
216216
sage: C.extra_super_categories()
217217
[Category of algebras over Rational Field]
218218
sage: sorted(C.super_categories(), key=str)
219-
[Category of Cartesian products of distributive magmas and additive magmas,
220-
Category of Cartesian products of monoids,
221-
Category of Cartesian products of vector spaces over Rational Field,
219+
[Category of Cartesian products of monoids,
220+
Category of Cartesian products of unital algebras over Rational Field,
222221
Category of algebras over Rational Field]
223222
"""
224223
return [self.base_category()]

src/sage/categories/algebras_with_basis.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ class ParentMethods:
231231
@cached_method
232232
def one_from_cartesian_product_of_one_basis(self):
233233
"""
234-
Returns the one of this Cartesian product of algebras, as per ``Monoids.ParentMethods.one``
234+
Return the one of this Cartesian product of algebras, as per
235+
``Monoids.ParentMethods.one``
235236
236237
It is constructed as the Cartesian product of the ones of the
237238
summands, using their :meth:`~AlgebrasWithBasis.ParentMethods.one_basis` methods.
@@ -272,10 +273,11 @@ def one(self):
272273
sage: B.one() # needs sage.combinat sage.modules
273274
B[(0, word: )] + B[(1, word: )] + B[(2, word: )]
274275
"""
275-
if all(hasattr(module, "one_basis") for module in self._sets):
276+
if all(hasattr(module, "one_basis") and module.one_basis is not NotImplemented for module in self._sets):
276277
return self.one_from_cartesian_product_of_one_basis
277-
else:
278-
return NotImplemented
278+
return self._one_generic
279+
280+
_one_generic = UnitalAlgebras.CartesianProducts.ParentMethods.one
279281

280282
# def product_on_basis(self, t1, t2):
281283
# would be easy to implement, but without a special

src/sage/categories/unital_algebras.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
from sage.categories.homset import Hom
1919
from sage.categories.rings import Rings
2020
from sage.categories.magmatic_algebras import MagmaticAlgebras
21+
from sage.categories.cartesian_product import CartesianProductsCategory
2122

2223

2324
class UnitalAlgebras(CategoryWithAxiom_over_base_ring):
2425
"""
2526
The category of non-associative algebras over a given base ring.
2627
2728
A non-associative algebra over a ring `R` is a module over `R`
28-
which s also a unital magma.
29+
which is also a unital magma.
2930
3031
.. WARNING::
3132
@@ -382,3 +383,55 @@ def from_base_ring_from_one_basis(self, r):
382383
3*B[word: ]
383384
"""
384385
return self.term(self.one_basis(), r)
386+
387+
class CartesianProducts(CartesianProductsCategory):
388+
r"""
389+
The category of unital algebras constructed as Cartesian products
390+
of unital algebras.
391+
392+
This construction gives the direct product of algebras. See
393+
discussion on:
394+
395+
- http://groups.google.fr/group/sage-devel/browse_thread/thread/35a72b1d0a2fc77a/348f42ae77a66d16#348f42ae77a66d16
396+
- :wikipedia:`Direct_product`
397+
"""
398+
def extra_super_categories(self):
399+
"""
400+
A Cartesian product of algebras is endowed with a natural
401+
unital algebra structure.
402+
403+
EXAMPLES::
404+
405+
sage: from sage.categories.unital_algebras import UnitalAlgebras
406+
sage: C = UnitalAlgebras(QQ).CartesianProducts()
407+
sage: C.extra_super_categories()
408+
[Category of unital algebras over Rational Field]
409+
sage: sorted(C.super_categories(), key=str)
410+
[Category of Cartesian products of distributive magmas and additive magmas,
411+
Category of Cartesian products of unital magmas,
412+
Category of Cartesian products of vector spaces over Rational Field,
413+
Category of unital algebras over Rational Field]
414+
"""
415+
return [self.base_category()]
416+
417+
class ParentMethods:
418+
@cached_method
419+
def one(self):
420+
r"""
421+
Return the multiplicative unit element.
422+
423+
EXAMPLES::
424+
425+
sage: S2 = simplicial_complexes.Sphere(2)
426+
sage: H = S2.cohomology_ring(QQ)
427+
sage: C = cartesian_product([H, H])
428+
sage: one = C.one()
429+
sage: one
430+
B[(0, (0, 0))] + B[(1, (0, 0))]
431+
sage: one == one * one
432+
True
433+
sage: all(b == b * one for b in C.basis())
434+
True
435+
"""
436+
data = enumerate(self.cartesian_factors())
437+
return self._cartesian_product_of_elements([C.one() for i, C in data])

0 commit comments

Comments
 (0)