passagemath-objects 10.6.47__cp311-cp311-macosx_13_0_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_objects/.dylibs/libgmp.10.dylib +0 -0
- passagemath_objects/__init__.py +3 -0
- passagemath_objects-10.6.47.dist-info/METADATA +115 -0
- passagemath_objects-10.6.47.dist-info/RECORD +280 -0
- passagemath_objects-10.6.47.dist-info/WHEEL +6 -0
- passagemath_objects-10.6.47.dist-info/top_level.txt +3 -0
- sage/all__sagemath_objects.py +37 -0
- sage/arith/all__sagemath_objects.py +5 -0
- sage/arith/long.pxd +411 -0
- sage/arith/numerical_approx.cpython-311-darwin.so +0 -0
- sage/arith/numerical_approx.pxd +35 -0
- sage/arith/numerical_approx.pyx +75 -0
- sage/arith/power.cpython-311-darwin.so +0 -0
- sage/arith/power.pxd +31 -0
- sage/arith/power.pyx +127 -0
- sage/categories/action.cpython-311-darwin.so +0 -0
- sage/categories/action.pxd +29 -0
- sage/categories/action.pyx +641 -0
- sage/categories/algebra_functor.py +745 -0
- sage/categories/all__sagemath_objects.py +33 -0
- sage/categories/basic.py +62 -0
- sage/categories/cartesian_product.py +295 -0
- sage/categories/category.py +3401 -0
- sage/categories/category_cy_helper.cpython-311-darwin.so +0 -0
- sage/categories/category_cy_helper.pxd +8 -0
- sage/categories/category_cy_helper.pyx +322 -0
- sage/categories/category_singleton.cpython-311-darwin.so +0 -0
- sage/categories/category_singleton.pxd +3 -0
- sage/categories/category_singleton.pyx +342 -0
- sage/categories/category_types.py +637 -0
- sage/categories/category_with_axiom.py +2876 -0
- sage/categories/covariant_functorial_construction.py +703 -0
- sage/categories/facade_sets.py +228 -0
- sage/categories/functor.cpython-311-darwin.so +0 -0
- sage/categories/functor.pxd +7 -0
- sage/categories/functor.pyx +691 -0
- sage/categories/homset.py +1338 -0
- sage/categories/homsets.py +364 -0
- sage/categories/isomorphic_objects.py +73 -0
- sage/categories/map.cpython-311-darwin.so +0 -0
- sage/categories/map.pxd +34 -0
- sage/categories/map.pyx +2106 -0
- sage/categories/morphism.cpython-311-darwin.so +0 -0
- sage/categories/morphism.pxd +14 -0
- sage/categories/morphism.pyx +895 -0
- sage/categories/objects.py +167 -0
- sage/categories/primer.py +1696 -0
- sage/categories/pushout.py +4834 -0
- sage/categories/quotients.py +64 -0
- sage/categories/realizations.py +200 -0
- sage/categories/sets_cat.py +3290 -0
- sage/categories/sets_with_partial_maps.py +52 -0
- sage/categories/subobjects.py +64 -0
- sage/categories/subquotients.py +21 -0
- sage/categories/with_realizations.py +311 -0
- sage/cpython/__init__.py +19 -0
- sage/cpython/_py2_random.py +619 -0
- sage/cpython/all.py +3 -0
- sage/cpython/atexit.cpython-311-darwin.so +0 -0
- sage/cpython/atexit.pyx +269 -0
- sage/cpython/builtin_types.cpython-311-darwin.so +0 -0
- sage/cpython/builtin_types.pyx +7 -0
- sage/cpython/cython_metaclass.cpython-311-darwin.so +0 -0
- sage/cpython/cython_metaclass.h +117 -0
- sage/cpython/cython_metaclass.pxd +3 -0
- sage/cpython/cython_metaclass.pyx +130 -0
- sage/cpython/debug.cpython-311-darwin.so +0 -0
- sage/cpython/debug.pyx +302 -0
- sage/cpython/dict_del_by_value.cpython-311-darwin.so +0 -0
- sage/cpython/dict_del_by_value.pxd +9 -0
- sage/cpython/dict_del_by_value.pyx +191 -0
- sage/cpython/dict_internal.h +245 -0
- sage/cpython/getattr.cpython-311-darwin.so +0 -0
- sage/cpython/getattr.pxd +9 -0
- sage/cpython/getattr.pyx +439 -0
- sage/cpython/pycore_long.h +97 -0
- sage/cpython/pycore_long.pxd +10 -0
- sage/cpython/python_debug.h +44 -0
- sage/cpython/python_debug.pxd +47 -0
- sage/cpython/pyx_visit.h +13 -0
- sage/cpython/string.cpython-311-darwin.so +0 -0
- sage/cpython/string.pxd +76 -0
- sage/cpython/string.pyx +34 -0
- sage/cpython/string_impl.h +60 -0
- sage/cpython/type.cpython-311-darwin.so +0 -0
- sage/cpython/type.pxd +2 -0
- sage/cpython/type.pyx +40 -0
- sage/cpython/wrapperdescr.pxd +67 -0
- sage/ext/all__sagemath_objects.py +3 -0
- sage/ext/ccobject.h +64 -0
- sage/ext/cplusplus.pxd +17 -0
- sage/ext/mod_int.h +30 -0
- sage/ext/mod_int.pxd +24 -0
- sage/ext/stdsage.pxd +39 -0
- sage/groups/all__sagemath_objects.py +1 -0
- sage/groups/group.cpython-311-darwin.so +0 -0
- sage/groups/group.pxd +14 -0
- sage/groups/group.pyx +322 -0
- sage/groups/old.cpython-311-darwin.so +0 -0
- sage/groups/old.pxd +14 -0
- sage/groups/old.pyx +219 -0
- sage/libs/all__sagemath_objects.py +3 -0
- sage/libs/gmp/__init__.py +1 -0
- sage/libs/gmp/all.pxd +6 -0
- sage/libs/gmp/binop.pxd +23 -0
- sage/libs/gmp/misc.pxd +8 -0
- sage/libs/gmp/mpf.pxd +88 -0
- sage/libs/gmp/mpn.pxd +57 -0
- sage/libs/gmp/mpq.pxd +57 -0
- sage/libs/gmp/mpz.pxd +202 -0
- sage/libs/gmp/pylong.cpython-311-darwin.so +0 -0
- sage/libs/gmp/pylong.pxd +12 -0
- sage/libs/gmp/pylong.pyx +150 -0
- sage/libs/gmp/random.pxd +25 -0
- sage/libs/gmp/randomize.pxd +59 -0
- sage/libs/gmp/types.pxd +53 -0
- sage/libs/gmpxx.pxd +19 -0
- sage/misc/abstract_method.py +276 -0
- sage/misc/all__sagemath_objects.py +43 -0
- sage/misc/bindable_class.py +253 -0
- sage/misc/c3_controlled.cpython-311-darwin.so +0 -0
- sage/misc/c3_controlled.pxd +2 -0
- sage/misc/c3_controlled.pyx +1402 -0
- sage/misc/cachefunc.cpython-311-darwin.so +0 -0
- sage/misc/cachefunc.pxd +43 -0
- sage/misc/cachefunc.pyx +3781 -0
- sage/misc/call.py +188 -0
- sage/misc/classcall_metaclass.cpython-311-darwin.so +0 -0
- sage/misc/classcall_metaclass.pxd +14 -0
- sage/misc/classcall_metaclass.pyx +599 -0
- sage/misc/constant_function.cpython-311-darwin.so +0 -0
- sage/misc/constant_function.pyx +130 -0
- sage/misc/decorators.py +747 -0
- sage/misc/fast_methods.cpython-311-darwin.so +0 -0
- sage/misc/fast_methods.pxd +20 -0
- sage/misc/fast_methods.pyx +351 -0
- sage/misc/flatten.py +90 -0
- sage/misc/fpickle.cpython-311-darwin.so +0 -0
- sage/misc/fpickle.pyx +177 -0
- sage/misc/function_mangling.cpython-311-darwin.so +0 -0
- sage/misc/function_mangling.pxd +11 -0
- sage/misc/function_mangling.pyx +308 -0
- sage/misc/inherit_comparison.cpython-311-darwin.so +0 -0
- sage/misc/inherit_comparison.pxd +5 -0
- sage/misc/inherit_comparison.pyx +105 -0
- sage/misc/instancedoc.cpython-311-darwin.so +0 -0
- sage/misc/instancedoc.pyx +331 -0
- sage/misc/lazy_attribute.cpython-311-darwin.so +0 -0
- sage/misc/lazy_attribute.pyx +607 -0
- sage/misc/lazy_format.py +135 -0
- sage/misc/lazy_import.cpython-311-darwin.so +0 -0
- sage/misc/lazy_import.pyx +1299 -0
- sage/misc/lazy_import_cache.py +36 -0
- sage/misc/lazy_list.cpython-311-darwin.so +0 -0
- sage/misc/lazy_list.pxd +19 -0
- sage/misc/lazy_list.pyx +1187 -0
- sage/misc/lazy_string.cpython-311-darwin.so +0 -0
- sage/misc/lazy_string.pxd +7 -0
- sage/misc/lazy_string.pyx +546 -0
- sage/misc/misc.py +1066 -0
- sage/misc/misc_c.cpython-311-darwin.so +0 -0
- sage/misc/misc_c.pxd +3 -0
- sage/misc/misc_c.pyx +766 -0
- sage/misc/namespace_package.py +37 -0
- sage/misc/nested_class.cpython-311-darwin.so +0 -0
- sage/misc/nested_class.pxd +3 -0
- sage/misc/nested_class.pyx +394 -0
- sage/misc/persist.cpython-311-darwin.so +0 -0
- sage/misc/persist.pyx +1251 -0
- sage/misc/prandom.py +418 -0
- sage/misc/randstate.cpython-311-darwin.so +0 -0
- sage/misc/randstate.pxd +30 -0
- sage/misc/randstate.pyx +1059 -0
- sage/misc/repr.py +203 -0
- sage/misc/reset.cpython-311-darwin.so +0 -0
- sage/misc/reset.pyx +196 -0
- sage/misc/sage_ostools.cpython-311-darwin.so +0 -0
- sage/misc/sage_ostools.pyx +323 -0
- sage/misc/sage_timeit.py +275 -0
- sage/misc/sage_timeit_class.cpython-311-darwin.so +0 -0
- sage/misc/sage_timeit_class.pyx +120 -0
- sage/misc/sage_unittest.py +637 -0
- sage/misc/sageinspect.py +2768 -0
- sage/misc/session.cpython-311-darwin.so +0 -0
- sage/misc/session.pyx +392 -0
- sage/misc/superseded.py +557 -0
- sage/misc/test_nested_class.py +228 -0
- sage/misc/timing.py +264 -0
- sage/misc/unknown.py +222 -0
- sage/misc/verbose.py +253 -0
- sage/misc/weak_dict.cpython-311-darwin.so +0 -0
- sage/misc/weak_dict.pxd +15 -0
- sage/misc/weak_dict.pyx +1231 -0
- sage/modules/all__sagemath_objects.py +1 -0
- sage/modules/module.cpython-311-darwin.so +0 -0
- sage/modules/module.pxd +5 -0
- sage/modules/module.pyx +329 -0
- sage/rings/all__sagemath_objects.py +3 -0
- sage/rings/integer_fake.h +22 -0
- sage/rings/integer_fake.pxd +55 -0
- sage/sets/all__sagemath_objects.py +3 -0
- sage/sets/pythonclass.cpython-311-darwin.so +0 -0
- sage/sets/pythonclass.pxd +9 -0
- sage/sets/pythonclass.pyx +247 -0
- sage/structure/__init__.py +4 -0
- sage/structure/all.py +30 -0
- sage/structure/category_object.cpython-311-darwin.so +0 -0
- sage/structure/category_object.pxd +28 -0
- sage/structure/category_object.pyx +1087 -0
- sage/structure/coerce.cpython-311-darwin.so +0 -0
- sage/structure/coerce.pxd +44 -0
- sage/structure/coerce.pyx +2107 -0
- sage/structure/coerce_actions.cpython-311-darwin.so +0 -0
- sage/structure/coerce_actions.pxd +27 -0
- sage/structure/coerce_actions.pyx +988 -0
- sage/structure/coerce_dict.cpython-311-darwin.so +0 -0
- sage/structure/coerce_dict.pxd +51 -0
- sage/structure/coerce_dict.pyx +1557 -0
- sage/structure/coerce_exceptions.py +23 -0
- sage/structure/coerce_maps.cpython-311-darwin.so +0 -0
- sage/structure/coerce_maps.pxd +28 -0
- sage/structure/coerce_maps.pyx +718 -0
- sage/structure/debug_options.cpython-311-darwin.so +0 -0
- sage/structure/debug_options.pxd +6 -0
- sage/structure/debug_options.pyx +54 -0
- sage/structure/dynamic_class.py +541 -0
- sage/structure/element.cpython-311-darwin.so +0 -0
- sage/structure/element.pxd +272 -0
- sage/structure/element.pyx +4772 -0
- sage/structure/element_wrapper.cpython-311-darwin.so +0 -0
- sage/structure/element_wrapper.pxd +12 -0
- sage/structure/element_wrapper.pyx +582 -0
- sage/structure/factorization.py +1422 -0
- sage/structure/factorization_integer.py +105 -0
- sage/structure/factory.cpython-311-darwin.so +0 -0
- sage/structure/factory.pyx +786 -0
- sage/structure/formal_sum.py +489 -0
- sage/structure/gens_py.py +73 -0
- sage/structure/global_options.py +1743 -0
- sage/structure/indexed_generators.py +863 -0
- sage/structure/list_clone.cpython-311-darwin.so +0 -0
- sage/structure/list_clone.pxd +65 -0
- sage/structure/list_clone.pyx +1867 -0
- sage/structure/list_clone_demo.cpython-311-darwin.so +0 -0
- sage/structure/list_clone_demo.pyx +248 -0
- sage/structure/list_clone_timings.py +179 -0
- sage/structure/list_clone_timings_cy.cpython-311-darwin.so +0 -0
- sage/structure/list_clone_timings_cy.pyx +86 -0
- sage/structure/mutability.cpython-311-darwin.so +0 -0
- sage/structure/mutability.pxd +21 -0
- sage/structure/mutability.pyx +348 -0
- sage/structure/nonexact.py +69 -0
- sage/structure/parent.cpython-311-darwin.so +0 -0
- sage/structure/parent.pxd +112 -0
- sage/structure/parent.pyx +3093 -0
- sage/structure/parent_base.cpython-311-darwin.so +0 -0
- sage/structure/parent_base.pxd +13 -0
- sage/structure/parent_base.pyx +44 -0
- sage/structure/parent_gens.cpython-311-darwin.so +0 -0
- sage/structure/parent_gens.pxd +22 -0
- sage/structure/parent_gens.pyx +377 -0
- sage/structure/parent_old.cpython-311-darwin.so +0 -0
- sage/structure/parent_old.pxd +25 -0
- sage/structure/parent_old.pyx +294 -0
- sage/structure/proof/__init__.py +1 -0
- sage/structure/proof/all.py +243 -0
- sage/structure/proof/proof.py +300 -0
- sage/structure/richcmp.cpython-311-darwin.so +0 -0
- sage/structure/richcmp.pxd +213 -0
- sage/structure/richcmp.pyx +495 -0
- sage/structure/sage_object.cpython-311-darwin.so +0 -0
- sage/structure/sage_object.pxd +3 -0
- sage/structure/sage_object.pyx +988 -0
- sage/structure/sage_object_test.py +19 -0
- sage/structure/sequence.py +937 -0
- sage/structure/set_factories.py +1178 -0
- sage/structure/set_factories_example.py +527 -0
- sage/structure/support_view.py +179 -0
- sage/structure/test_factory.py +56 -0
- sage/structure/unique_representation.py +1359 -0
|
@@ -0,0 +1,2876 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
# delvewheel: patch
|
|
3
|
+
r"""
|
|
4
|
+
Axioms
|
|
5
|
+
|
|
6
|
+
This documentation covers how to implement axioms and proceeds with an
|
|
7
|
+
overview of the implementation of the axiom infrastructure. It assumes
|
|
8
|
+
that the reader is familiar with the :ref:`category primer
|
|
9
|
+
<sage.categories.primer>`, and in particular its :ref:`section about
|
|
10
|
+
axioms <category-primer-axioms>`.
|
|
11
|
+
|
|
12
|
+
Implementing axioms
|
|
13
|
+
===================
|
|
14
|
+
|
|
15
|
+
Simple case involving a single predefined axiom
|
|
16
|
+
-----------------------------------------------
|
|
17
|
+
|
|
18
|
+
Suppose that one wants to provide code (and documentation, tests, ...)
|
|
19
|
+
for the objects of some existing category ``Cs()`` that satisfy some
|
|
20
|
+
predefined axiom ``A``.
|
|
21
|
+
|
|
22
|
+
The first step is to open the hood and check whether there already
|
|
23
|
+
exists a class implementing the category ``Cs().A()``. For example,
|
|
24
|
+
taking ``Cs=Semigroups`` and the ``Finite`` axiom, there already
|
|
25
|
+
exists a class for the category of finite semigroups::
|
|
26
|
+
|
|
27
|
+
sage: Semigroups().Finite()
|
|
28
|
+
Category of finite semigroups
|
|
29
|
+
sage: type(Semigroups().Finite())
|
|
30
|
+
<class 'sage.categories.finite_semigroups.FiniteSemigroups_with_category'>
|
|
31
|
+
|
|
32
|
+
In this case, we say that the category of semigroups *implements* the
|
|
33
|
+
axiom ``Finite``, and code about finite semigroups should go in the
|
|
34
|
+
class :class:`FiniteSemigroups` (or, as usual, in its nested classes
|
|
35
|
+
``ParentMethods``, ``ElementMethods``, and so on).
|
|
36
|
+
|
|
37
|
+
On the other hand, there is no class for the category of infinite
|
|
38
|
+
semigroups::
|
|
39
|
+
|
|
40
|
+
sage: Semigroups().Infinite()
|
|
41
|
+
Category of infinite semigroups
|
|
42
|
+
sage: type(Semigroups().Infinite())
|
|
43
|
+
<class 'sage.categories.category.JoinCategory_with_category'>
|
|
44
|
+
|
|
45
|
+
This category is indeed just constructed as the intersection of the
|
|
46
|
+
categories of semigroups and of infinite sets respectively::
|
|
47
|
+
|
|
48
|
+
sage: Semigroups().Infinite().super_categories()
|
|
49
|
+
[Category of semigroups, Category of infinite sets]
|
|
50
|
+
|
|
51
|
+
In this case, one needs to create a new class to implement the axiom
|
|
52
|
+
``Infinite`` for this category. This boils down to adding a nested
|
|
53
|
+
class ``Semigroups.Infinite`` inheriting from :class:`CategoryWithAxiom`.
|
|
54
|
+
|
|
55
|
+
In the following example, we implement a category ``Cs``, with a
|
|
56
|
+
subcategory for the objects satisfying the ``Finite`` axiom defined in
|
|
57
|
+
the super category ``Sets`` (we will see later on how to *define* new
|
|
58
|
+
axioms)::
|
|
59
|
+
|
|
60
|
+
sage: from sage.categories.category_with_axiom import CategoryWithAxiom
|
|
61
|
+
sage: class Cs(Category):
|
|
62
|
+
....: def super_categories(self):
|
|
63
|
+
....: return [Sets()]
|
|
64
|
+
....: class Finite(CategoryWithAxiom):
|
|
65
|
+
....: class ParentMethods:
|
|
66
|
+
....: def foo(self):
|
|
67
|
+
....: print("I am a method on finite C's")
|
|
68
|
+
|
|
69
|
+
::
|
|
70
|
+
|
|
71
|
+
sage: Cs().Finite()
|
|
72
|
+
Category of finite cs
|
|
73
|
+
sage: Cs().Finite().super_categories()
|
|
74
|
+
[Category of finite sets, Category of cs]
|
|
75
|
+
sage: Cs().Finite().all_super_categories()
|
|
76
|
+
[Category of finite cs, Category of finite sets,
|
|
77
|
+
Category of cs, Category of sets, ...]
|
|
78
|
+
sage: Cs().Finite().axioms()
|
|
79
|
+
frozenset({'Finite'})
|
|
80
|
+
|
|
81
|
+
Now a parent declared in the category ``Cs().Finite()`` inherits from
|
|
82
|
+
all the methods of finite sets and of finite `C`'s, as desired::
|
|
83
|
+
|
|
84
|
+
sage: P = Parent(category=Cs().Finite())
|
|
85
|
+
sage: P.is_finite() # Provided by Sets.Finite.ParentMethods
|
|
86
|
+
True
|
|
87
|
+
sage: P.foo() # Provided by Cs.Finite.ParentMethods
|
|
88
|
+
I am a method on finite C's
|
|
89
|
+
|
|
90
|
+
.. _category-with-axiom-design:
|
|
91
|
+
|
|
92
|
+
.. NOTE::
|
|
93
|
+
|
|
94
|
+
- This follows the same idiom as for
|
|
95
|
+
:ref:`sage.categories.covariant_functorial_construction`.
|
|
96
|
+
|
|
97
|
+
- From an object oriented point of view, any subcategory ``Cs()``
|
|
98
|
+
of :class:`Sets` inherits a ``Finite`` method. Usually ``Cs``
|
|
99
|
+
could complement this method by overriding it with a method
|
|
100
|
+
``Cs.Finite`` which would make a super call to ``Sets.Finite``
|
|
101
|
+
and then do extra stuff.
|
|
102
|
+
|
|
103
|
+
In the above example, ``Cs`` also wants to complement
|
|
104
|
+
``Sets.Finite``, though not by doing more stuff, but by
|
|
105
|
+
providing it with an additional mixin class containing the code
|
|
106
|
+
for finite ``Cs``. To keep the analogy, this mixin class is to
|
|
107
|
+
be put in ``Cs.Finite``.
|
|
108
|
+
|
|
109
|
+
- By defining the axiom ``Finite``, :class:`Sets` fixes the
|
|
110
|
+
semantic of ``Cs.Finite()`` for all its subcategories ``Cs``:
|
|
111
|
+
namely "the category of ``Cs`` which are finite as sets". Hence,
|
|
112
|
+
for example, ``Modules.Free.Finite`` cannot be used to model the
|
|
113
|
+
category of free modules of finite rank, even though their
|
|
114
|
+
traditional name "finite free modules" might suggest it.
|
|
115
|
+
|
|
116
|
+
- It may come as a surprise that we can actually use the same name
|
|
117
|
+
``Finite`` for the mixin class and for the method defining the
|
|
118
|
+
axiom; indeed, by default a class does not have a binding
|
|
119
|
+
behavior and would completely override the method. See the
|
|
120
|
+
section :ref:`axioms-defining-a-new-axiom` for details and the
|
|
121
|
+
rationale behind it.
|
|
122
|
+
|
|
123
|
+
An alternative would have been to give another name to the mixin
|
|
124
|
+
class, like ``FiniteCategory``. However this would have resulted
|
|
125
|
+
in more namespace pollution, whereas using ``Finite`` is already
|
|
126
|
+
clear, explicit, and easier to remember.
|
|
127
|
+
|
|
128
|
+
- Under the hood, the category ``Cs().Finite()`` is aware that it
|
|
129
|
+
has been constructed from the category ``Cs()`` by adding the
|
|
130
|
+
axiom ``Finite``::
|
|
131
|
+
|
|
132
|
+
sage: Cs().Finite().base_category()
|
|
133
|
+
Category of cs
|
|
134
|
+
sage: Cs().Finite()._axiom
|
|
135
|
+
'Finite'
|
|
136
|
+
|
|
137
|
+
Over time, the nested class ``Cs.Finite`` may become large and too
|
|
138
|
+
cumbersome to keep as a nested subclass of ``Cs``. Or the category with
|
|
139
|
+
axiom may have a name of its own in the literature, like *semigroups*
|
|
140
|
+
rather than *associative magmas*, or *fields* rather than *commutative
|
|
141
|
+
division rings*. In this case, the category with axiom can be put
|
|
142
|
+
elsewhere, typically in a separate file, with just a link from
|
|
143
|
+
``Cs``::
|
|
144
|
+
|
|
145
|
+
sage: class Cs(Category):
|
|
146
|
+
....: def super_categories(self):
|
|
147
|
+
....: return [Sets()]
|
|
148
|
+
sage: class FiniteCs(CategoryWithAxiom):
|
|
149
|
+
....: class ParentMethods:
|
|
150
|
+
....: def foo(self):
|
|
151
|
+
....: print("I am a method on finite C's")
|
|
152
|
+
sage: Cs.Finite = FiniteCs
|
|
153
|
+
sage: Cs().Finite()
|
|
154
|
+
Category of finite cs
|
|
155
|
+
|
|
156
|
+
For a real example, see the code of the class :class:`FiniteGroups` and the
|
|
157
|
+
link to it in :class:`Groups`. Note that the link is implemented using
|
|
158
|
+
:class:`~sage.misc.lazy_import.LazyImport`; this is highly recommended: it
|
|
159
|
+
makes sure that :class:`FiniteGroups` is imported after :class:`Groups` it
|
|
160
|
+
depends upon, and makes it explicit that the class :class:`Groups` can be
|
|
161
|
+
imported and is fully functional without importing :class:`FiniteGroups`.
|
|
162
|
+
|
|
163
|
+
.. NOTE::
|
|
164
|
+
|
|
165
|
+
Some categories with axioms are created upon Sage's startup. In such a
|
|
166
|
+
case, one needs to pass the ``at_startup=True`` option to
|
|
167
|
+
:class:`~sage.misc.lazy_import.LazyImport`, in order to quiet the warning
|
|
168
|
+
about that lazy import being resolved upon startup. See for example
|
|
169
|
+
``Sets.Finite``.
|
|
170
|
+
|
|
171
|
+
This is undoubtedly a code smell. Nevertheless, it is preferable
|
|
172
|
+
to stick to lazy imports, first to resolve the import order
|
|
173
|
+
properly, and more importantly as a reminder that the category
|
|
174
|
+
would be best not constructed upon Sage's startup. This is to spur
|
|
175
|
+
developers to reduce the number of parents (and therefore
|
|
176
|
+
categories) that are constructed upon startup. Each
|
|
177
|
+
``at_startup=True`` that will be removed will be a measure of
|
|
178
|
+
progress in this direction.
|
|
179
|
+
|
|
180
|
+
.. NOTE::
|
|
181
|
+
|
|
182
|
+
In principle, due to a limitation of
|
|
183
|
+
:class:`~sage.misc.lazy_import.LazyImport` with nested classes (see
|
|
184
|
+
:issue:`15648`), one should pass the option ``as_name`` to
|
|
185
|
+
:class:`~sage.misc.lazy_import.LazyImport`::
|
|
186
|
+
|
|
187
|
+
Finite = LazyImport('sage.categories.finite_groups', 'FiniteGroups',
|
|
188
|
+
as_name='Finite')
|
|
189
|
+
|
|
190
|
+
in order to prevent ``Groups.Finite`` to keep on reimporting
|
|
191
|
+
``FiniteGroups``.
|
|
192
|
+
|
|
193
|
+
Given that passing this option introduces some redundancy and is
|
|
194
|
+
error prone, the axiom infrastructure includes a little workaround
|
|
195
|
+
which makes the ``as_name`` unnecessary in this case.
|
|
196
|
+
|
|
197
|
+
Making the category with axiom directly callable
|
|
198
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
199
|
+
|
|
200
|
+
If desired, a category with axiom can be constructed directly through
|
|
201
|
+
its class rather than through its base category::
|
|
202
|
+
|
|
203
|
+
sage: Semigroups()
|
|
204
|
+
Category of semigroups
|
|
205
|
+
sage: Semigroups() is Magmas().Associative()
|
|
206
|
+
True
|
|
207
|
+
|
|
208
|
+
sage: FiniteGroups()
|
|
209
|
+
Category of finite groups
|
|
210
|
+
sage: FiniteGroups() is Groups().Finite()
|
|
211
|
+
True
|
|
212
|
+
|
|
213
|
+
For this notation to work, the class :class:`Semigroups` needs to be
|
|
214
|
+
aware of the base category class (here, :class:`Magmas`) and of the
|
|
215
|
+
axiom (here, ``Associative``)::
|
|
216
|
+
|
|
217
|
+
sage: Semigroups._base_category_class_and_axiom
|
|
218
|
+
(<class 'sage.categories.magmas.Magmas'>, 'Associative')
|
|
219
|
+
sage: Fields._base_category_class_and_axiom
|
|
220
|
+
(<class 'sage.categories.division_rings.DivisionRings'>, 'Commutative')
|
|
221
|
+
sage: FiniteGroups._base_category_class_and_axiom
|
|
222
|
+
(<class 'sage.categories.groups.Groups'>, 'Finite')
|
|
223
|
+
sage: FiniteDimensionalAlgebrasWithBasis._base_category_class_and_axiom
|
|
224
|
+
(<class 'sage.categories.algebras_with_basis.AlgebrasWithBasis'>, 'FiniteDimensional')
|
|
225
|
+
|
|
226
|
+
In our example, the attribute ``_base_category_class_and_axiom`` was
|
|
227
|
+
set upon calling ``Cs().Finite()``, which makes the notation seemingly
|
|
228
|
+
work::
|
|
229
|
+
|
|
230
|
+
sage: FiniteCs()
|
|
231
|
+
Category of finite cs
|
|
232
|
+
sage: FiniteCs._base_category_class_and_axiom
|
|
233
|
+
(<class '__main__.Cs'>, 'Finite')
|
|
234
|
+
sage: FiniteCs._base_category_class_and_axiom_origin
|
|
235
|
+
'set by __classget__'
|
|
236
|
+
|
|
237
|
+
But calling ``FiniteCs()`` right after defining the class would have
|
|
238
|
+
failed (try it!). In general, one needs to set the attribute explicitly::
|
|
239
|
+
|
|
240
|
+
sage: class FiniteCs(CategoryWithAxiom):
|
|
241
|
+
....: _base_category_class_and_axiom = (Cs, 'Finite')
|
|
242
|
+
....: class ParentMethods:
|
|
243
|
+
....: def foo(self):
|
|
244
|
+
....: print("I am a method on finite C's")
|
|
245
|
+
|
|
246
|
+
Having to set explicitly this link back from ``FiniteCs`` to ``Cs``
|
|
247
|
+
introduces redundancy in the code. It would therefore be desirable to
|
|
248
|
+
have the infrastructure set the link automatically instead (a
|
|
249
|
+
difficulty is to achieve this while supporting lazy imported
|
|
250
|
+
categories with axiom).
|
|
251
|
+
|
|
252
|
+
As a first step, the link is set automatically upon accessing the
|
|
253
|
+
class from the base category class::
|
|
254
|
+
|
|
255
|
+
sage: Algebras.WithBasis._base_category_class_and_axiom
|
|
256
|
+
(<class 'sage.categories.algebras.Algebras'>, 'WithBasis')
|
|
257
|
+
sage: Algebras.WithBasis._base_category_class_and_axiom_origin
|
|
258
|
+
'set by __classget__'
|
|
259
|
+
|
|
260
|
+
Hence, for whatever this notation is worth, one can currently do::
|
|
261
|
+
|
|
262
|
+
sage: Algebras.WithBasis(QQ)
|
|
263
|
+
Category of algebras with basis over Rational Field
|
|
264
|
+
|
|
265
|
+
We don't recommend using syntax like ``Algebras.WithBasis(QQ)``, as it
|
|
266
|
+
may eventually be deprecated.
|
|
267
|
+
|
|
268
|
+
As a second step, Sage tries some obvious heuristics to deduce the link
|
|
269
|
+
from the name of the category with axiom (see
|
|
270
|
+
:func:`base_category_class_and_axiom` for the details). This typically
|
|
271
|
+
covers the following examples::
|
|
272
|
+
|
|
273
|
+
sage: FiniteCoxeterGroups()
|
|
274
|
+
Category of finite Coxeter groups
|
|
275
|
+
sage: FiniteCoxeterGroups() is CoxeterGroups().Finite()
|
|
276
|
+
True
|
|
277
|
+
sage: FiniteCoxeterGroups._base_category_class_and_axiom_origin
|
|
278
|
+
'deduced by base_category_class_and_axiom'
|
|
279
|
+
|
|
280
|
+
sage: FiniteDimensionalAlgebrasWithBasis(QQ)
|
|
281
|
+
Category of finite dimensional algebras with basis over Rational Field
|
|
282
|
+
sage: FiniteDimensionalAlgebrasWithBasis(QQ) is Algebras(QQ).FiniteDimensional().WithBasis()
|
|
283
|
+
True
|
|
284
|
+
|
|
285
|
+
If the heuristic succeeds, the result is guaranteed to be correct. If
|
|
286
|
+
it fails, typically because the category has a name of its own like
|
|
287
|
+
:class:`Fields`, the attribute ``_base_category_class_and_axiom``
|
|
288
|
+
should be set explicitly. For more examples, see the code of the
|
|
289
|
+
classes :class:`Semigroups` or :class:`Fields`.
|
|
290
|
+
|
|
291
|
+
.. NOTE::
|
|
292
|
+
|
|
293
|
+
When printing out a category with axiom, the heuristic determines
|
|
294
|
+
whether a category has a name of its own by checking out how
|
|
295
|
+
``_base_category_class_and_axiom`` was set::
|
|
296
|
+
|
|
297
|
+
sage: Fields._base_category_class_and_axiom_origin
|
|
298
|
+
'hardcoded'
|
|
299
|
+
|
|
300
|
+
See :meth:`CategoryWithAxiom._without_axioms`,
|
|
301
|
+
:meth:`CategoryWithAxiom._repr_object_names_static`.
|
|
302
|
+
|
|
303
|
+
In our running example ``FiniteCs``, Sage failed to deduce
|
|
304
|
+
automatically the base category class and axiom because the class
|
|
305
|
+
``Cs`` is not in the standard location ``sage.categories.cs``.
|
|
306
|
+
|
|
307
|
+
.. TOPIC:: Design discussion
|
|
308
|
+
|
|
309
|
+
The above deduction, based on names, is undoubtedly inelegant. But
|
|
310
|
+
it's safe (either the result is guaranteed to be correct, or an
|
|
311
|
+
error is raised), it saves on some redundant information, and it
|
|
312
|
+
is only used for the simple shorthands like ``FiniteGroups()`` for
|
|
313
|
+
``Groups().Finite()``. Finally, most if not all of these
|
|
314
|
+
shorthands are likely to eventually disappear (see :issue:`15741`
|
|
315
|
+
and the :ref:`related discussion in the primer
|
|
316
|
+
<category-primer-axioms-single-entry-point>`).
|
|
317
|
+
|
|
318
|
+
.. _axioms-defining-a-new-axiom:
|
|
319
|
+
|
|
320
|
+
Defining a new axiom
|
|
321
|
+
--------------------
|
|
322
|
+
|
|
323
|
+
We describe now how to define a new axiom. The first step is to figure
|
|
324
|
+
out the largest category where the axiom makes sense. For example
|
|
325
|
+
``Sets`` for ``Finite``, ``Magmas`` for ``Associative``, or
|
|
326
|
+
``Modules`` for ``FiniteDimensional``. Here we define the axiom
|
|
327
|
+
``Green`` for the category ``Cs`` and its subcategories::
|
|
328
|
+
|
|
329
|
+
sage: from sage.categories.category_with_axiom import CategoryWithAxiom
|
|
330
|
+
sage: class Cs(Category):
|
|
331
|
+
....: def super_categories(self):
|
|
332
|
+
....: return [Sets()]
|
|
333
|
+
....: class SubcategoryMethods:
|
|
334
|
+
....: def Green(self):
|
|
335
|
+
....: '<documentation of the axiom Green>'
|
|
336
|
+
....: return self._with_axiom("Green")
|
|
337
|
+
....: class Green(CategoryWithAxiom):
|
|
338
|
+
....: class ParentMethods:
|
|
339
|
+
....: def foo(self):
|
|
340
|
+
....: print("I am a method on green C's")
|
|
341
|
+
|
|
342
|
+
With the current implementation, the name of the axiom must also be
|
|
343
|
+
added to a global container::
|
|
344
|
+
|
|
345
|
+
sage: all_axioms = sage.categories.category_with_axiom.all_axioms
|
|
346
|
+
sage: all_axioms += ("Green",)
|
|
347
|
+
|
|
348
|
+
We can now use the axiom as usual::
|
|
349
|
+
|
|
350
|
+
sage: Cs().Green()
|
|
351
|
+
Category of green cs
|
|
352
|
+
|
|
353
|
+
sage: P = Parent(category=Cs().Green())
|
|
354
|
+
sage: P.foo()
|
|
355
|
+
I am a method on green C's
|
|
356
|
+
|
|
357
|
+
Compared with our first example, the only newcomer is the method
|
|
358
|
+
``.Green()`` that can be used by any subcategory ``Ds()`` of ``Cs()``
|
|
359
|
+
to add the axiom ``Green``. Note that the expression ``Ds().Green``
|
|
360
|
+
always evaluates to this method, regardless of whether ``Ds`` has a
|
|
361
|
+
nested class ``Ds.Green`` or not (an implementation detail)::
|
|
362
|
+
|
|
363
|
+
sage: Cs().Green
|
|
364
|
+
<bound method Cs.SubcategoryMethods.Green of Category of cs>
|
|
365
|
+
|
|
366
|
+
Thanks to this feature (implemented in :meth:`CategoryWithAxiom.__classget__`),
|
|
367
|
+
the user is systematically referred to the documentation of this
|
|
368
|
+
method when doing introspection on ``Ds().Green``::
|
|
369
|
+
|
|
370
|
+
sage: C = Cs()
|
|
371
|
+
sage: C.Green? # not tested
|
|
372
|
+
sage: Cs().Green.__doc__
|
|
373
|
+
'<documentation of the axiom Green>'
|
|
374
|
+
|
|
375
|
+
It is therefore the natural spot for the documentation of the axiom.
|
|
376
|
+
|
|
377
|
+
.. NOTE::
|
|
378
|
+
|
|
379
|
+
The presence of the nested class ``Green`` in ``Cs`` is currently
|
|
380
|
+
mandatory even if it is empty.
|
|
381
|
+
|
|
382
|
+
.. TODO::
|
|
383
|
+
|
|
384
|
+
Specify whether or not one should systematically use
|
|
385
|
+
@cached_method in the definition of the axiom. And make sure all
|
|
386
|
+
the definition of axioms in Sage are consistent in this respect!
|
|
387
|
+
|
|
388
|
+
.. TODO::
|
|
389
|
+
|
|
390
|
+
We could possibly define an @axiom decorator? This could hide two
|
|
391
|
+
little implementation details: whether or not to make the method a
|
|
392
|
+
cached method, and the call to _with_axiom(...) under the hood. It
|
|
393
|
+
could do possibly do some more magic. The gain is not obvious though.
|
|
394
|
+
|
|
395
|
+
.. NOTE::
|
|
396
|
+
|
|
397
|
+
``all_axioms`` is only used marginally, for sanity checks and when
|
|
398
|
+
trying to derive automatically the base category class. The order
|
|
399
|
+
of the axioms in this tuple also controls the order in which they
|
|
400
|
+
appear when printing out categories with axioms (see
|
|
401
|
+
:meth:`CategoryWithAxiom._repr_object_names_static`).
|
|
402
|
+
|
|
403
|
+
During a Sage session, new axioms should only be added at the *end*
|
|
404
|
+
of ``all_axioms``, as above, so as to not break the cache of
|
|
405
|
+
:func:`axioms_rank`. Otherwise, they can be inserted statically
|
|
406
|
+
anywhere in the tuple. For axioms defined within the Sage library,
|
|
407
|
+
the name is best inserted by editing directly the definition of
|
|
408
|
+
``all_axioms`` in :mod:`sage.categories.category_with_axiom`.
|
|
409
|
+
|
|
410
|
+
.. TOPIC:: Design note
|
|
411
|
+
|
|
412
|
+
Let us state again that, unlike what the existence of
|
|
413
|
+
``all_axioms`` might suggest, the definition of an axiom is local
|
|
414
|
+
to a category and its subcategories. In particular, two
|
|
415
|
+
independent categories ``Cs()`` and ``Ds()`` can very well define
|
|
416
|
+
axioms with the same name and different semantics. As long as the
|
|
417
|
+
two hierarchies of subcategories don't intersect, this is not a
|
|
418
|
+
problem. And if they do intersect naturally (that is if one is
|
|
419
|
+
likely to create a parent belonging to both categories), this
|
|
420
|
+
probably means that the categories ``Cs`` and ``Ds`` are about
|
|
421
|
+
related enough areas of mathematics that one should clear the
|
|
422
|
+
ambiguity by having either the same semantic or different names.
|
|
423
|
+
|
|
424
|
+
This caveat is no different from that of name clashes in hierarchy
|
|
425
|
+
of classes involving multiple inheritance.
|
|
426
|
+
|
|
427
|
+
.. TODO::
|
|
428
|
+
|
|
429
|
+
Explore ways to get rid of this global ``all_axioms`` tuple,
|
|
430
|
+
and/or have automatic registration there, and/or having a
|
|
431
|
+
register_axiom(...) method.
|
|
432
|
+
|
|
433
|
+
Special case: defining an axiom depending on several categories
|
|
434
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
435
|
+
|
|
436
|
+
In some cases, the largest category where the axiom makes sense is the
|
|
437
|
+
intersection of two categories. This is typically the case for axioms
|
|
438
|
+
specifying compatibility conditions between two otherwise unrelated
|
|
439
|
+
operations, like ``Distributive`` which specifies a compatibility
|
|
440
|
+
between `*` and `+`. Ideally, we would want the ``Distributive`` axiom
|
|
441
|
+
to be defined by::
|
|
442
|
+
|
|
443
|
+
sage: Magmas() & AdditiveMagmas()
|
|
444
|
+
Join of Category of magmas and Category of additive magmas
|
|
445
|
+
|
|
446
|
+
The current infrastructure does not support this perfectly: indeed,
|
|
447
|
+
defining an axiom for a category `C` requires `C` to have a class of
|
|
448
|
+
its own; hence a :class:`~.category.JoinCategory` as above won't do;
|
|
449
|
+
we need to implement a new class like
|
|
450
|
+
:class:`~.magmas_and_additive_magmas.MagmasAndAdditiveMagmas`;
|
|
451
|
+
furthermore, we cannot yet model the fact that ``MagmasAndAdditiveMagmas()``
|
|
452
|
+
*is* the intersection of ``Magmas()`` and ``AdditiveMagmas()`` rather than a
|
|
453
|
+
mere subcategory::
|
|
454
|
+
|
|
455
|
+
sage: from sage.categories.magmas_and_additive_magmas import MagmasAndAdditiveMagmas
|
|
456
|
+
sage: Magmas() & AdditiveMagmas() is MagmasAndAdditiveMagmas()
|
|
457
|
+
False
|
|
458
|
+
sage: Magmas() & AdditiveMagmas() # todo: not implemented
|
|
459
|
+
Category of magmas and additive magmas
|
|
460
|
+
|
|
461
|
+
Still, there is a workaround to get the natural notations::
|
|
462
|
+
|
|
463
|
+
sage: (Magmas() & AdditiveMagmas()).Distributive()
|
|
464
|
+
Category of distributive magmas and additive magmas
|
|
465
|
+
sage: (Monoids() & CommutativeAdditiveGroups()).Distributive()
|
|
466
|
+
Category of rings
|
|
467
|
+
|
|
468
|
+
The trick is to define ``Distributive`` as usual in
|
|
469
|
+
:class:`~.magmas_and_additive_magmas.MagmasAndAdditiveMagmas`, and to
|
|
470
|
+
add a method :meth:`Magmas.SubcategoryMethods.Distributive` which
|
|
471
|
+
checks that ``self`` is a subcategory of both ``Magmas()`` and
|
|
472
|
+
``AdditiveMagmas()``, complains if not, and otherwise takes the
|
|
473
|
+
intersection of ``self`` with ``MagmasAndAdditiveMagmas()`` before
|
|
474
|
+
calling ``Distributive``.
|
|
475
|
+
|
|
476
|
+
The downsides of this workaround are:
|
|
477
|
+
|
|
478
|
+
- Creation of an otherwise empty class
|
|
479
|
+
:class:`~.magmas_and_additive_magmas.MagmasAndAdditiveMagmas`.
|
|
480
|
+
|
|
481
|
+
- Pollution of the namespace of ``Magmas()`` (and subcategories like
|
|
482
|
+
``Groups()``) with a method that is irrelevant (but safely complains
|
|
483
|
+
if called).
|
|
484
|
+
|
|
485
|
+
- ``C._with_axiom('Distributive')`` is not strictly equivalent to
|
|
486
|
+
``C.Distributive()``, which can be unpleasantly surprising::
|
|
487
|
+
|
|
488
|
+
sage: (Monoids() & CommutativeAdditiveGroups()).Distributive()
|
|
489
|
+
Category of rings
|
|
490
|
+
|
|
491
|
+
sage: (Monoids() & CommutativeAdditiveGroups())._with_axiom('Distributive')
|
|
492
|
+
Join of Category of monoids and Category of commutative additive groups
|
|
493
|
+
|
|
494
|
+
.. TODO::
|
|
495
|
+
|
|
496
|
+
Other categories that would be better implemented via an axiom
|
|
497
|
+
depending on a join category include:
|
|
498
|
+
|
|
499
|
+
- :class:`Algebras`: defining an associative unital algebra as a
|
|
500
|
+
ring and a module satisfying the suitable compatibility axiom
|
|
501
|
+
between inner multiplication and multiplication by scalars
|
|
502
|
+
(bilinearity). Of course this should be implemented at the level
|
|
503
|
+
of :class:`~.magmatic_algebras.MagmaticAlgebras`, if not higher.
|
|
504
|
+
|
|
505
|
+
- :class:`Bialgebras`: defining a bialgebra as an algebra and
|
|
506
|
+
coalgebra where the coproduct is a morphism for the product.
|
|
507
|
+
|
|
508
|
+
- :class:`Bimodules`: defining a bimodule as a left and right
|
|
509
|
+
module where the two actions commute.
|
|
510
|
+
|
|
511
|
+
.. TODO::
|
|
512
|
+
|
|
513
|
+
- Design and implement an idiom for the definition of an axiom by a join
|
|
514
|
+
category.
|
|
515
|
+
|
|
516
|
+
- Or support more advanced joins, through some hook or registration
|
|
517
|
+
process to specify that a given category *is* the intersection of two
|
|
518
|
+
(or more) categories.
|
|
519
|
+
|
|
520
|
+
- Or at least improve the above workaround to avoid the last issue; this
|
|
521
|
+
possibly could be achieved using a class ``Magmas.Distributive`` with a
|
|
522
|
+
bit of ``__classcall__`` magic.
|
|
523
|
+
|
|
524
|
+
Handling multiple axioms, arborescence structure of the code
|
|
525
|
+
------------------------------------------------------------
|
|
526
|
+
|
|
527
|
+
Prelude
|
|
528
|
+
^^^^^^^
|
|
529
|
+
|
|
530
|
+
Let us consider the category of magmas, together with two of its
|
|
531
|
+
axioms, namely ``Associative`` and ``Unital``. An associative magma is
|
|
532
|
+
a *semigroup* and a unital semigroup is a *monoid*. We have also seen
|
|
533
|
+
that axioms commute::
|
|
534
|
+
|
|
535
|
+
sage: Magmas().Unital()
|
|
536
|
+
Category of unital magmas
|
|
537
|
+
sage: Magmas().Associative()
|
|
538
|
+
Category of semigroups
|
|
539
|
+
sage: Magmas().Associative().Unital()
|
|
540
|
+
Category of monoids
|
|
541
|
+
sage: Magmas().Unital().Associative()
|
|
542
|
+
Category of monoids
|
|
543
|
+
|
|
544
|
+
At the level of the classes implementing these categories, the
|
|
545
|
+
following comes as a general naturalization of the previous section::
|
|
546
|
+
|
|
547
|
+
sage: Magmas.Unital
|
|
548
|
+
<class 'sage.categories.magmas.Magmas.Unital'>
|
|
549
|
+
sage: Magmas.Associative
|
|
550
|
+
<class 'sage.categories.semigroups.Semigroups'>
|
|
551
|
+
sage: Magmas.Associative.Unital
|
|
552
|
+
<class 'sage.categories.monoids.Monoids'>
|
|
553
|
+
|
|
554
|
+
However, the following may look suspicious at first::
|
|
555
|
+
|
|
556
|
+
sage: Magmas.Unital.Associative
|
|
557
|
+
Traceback (most recent call last):
|
|
558
|
+
...
|
|
559
|
+
AttributeError: type object 'Magmas.Unital' has no attribute 'Associative'...
|
|
560
|
+
|
|
561
|
+
The purpose of this section is to explain the design of the code
|
|
562
|
+
layout and the rationale for this mismatch.
|
|
563
|
+
|
|
564
|
+
Abstract model
|
|
565
|
+
^^^^^^^^^^^^^^
|
|
566
|
+
|
|
567
|
+
As we have seen in the :ref:`Primer <category-primer-axioms-explosion>`,
|
|
568
|
+
the objects of a category ``Cs()`` can usually satisfy, or not, many
|
|
569
|
+
different axioms. Out of all combinations of axioms, only a small
|
|
570
|
+
number are relevant in practice, in the sense that we actually want to
|
|
571
|
+
provide features for the objects satisfying these axioms.
|
|
572
|
+
|
|
573
|
+
Therefore, in the context of the category class ``Cs``, we want to
|
|
574
|
+
provide the system with a collection `(D_S)_{S\in \mathcal S}` where
|
|
575
|
+
each `S` is a subset of the axioms and the corresponding `D_S` is a
|
|
576
|
+
class for the subcategory of the objects of ``Cs()`` satisfying the
|
|
577
|
+
axioms in `S`. For example, if ``Cs()`` is the category of magmas, the
|
|
578
|
+
pairs `(S, D_S)` would include::
|
|
579
|
+
|
|
580
|
+
{Associative} : Semigroups
|
|
581
|
+
{Associative, Unital} : Monoids
|
|
582
|
+
{Associative, Unital, Inverse}: Groups
|
|
583
|
+
{Associative, Commutative} : Commutative Semigroups
|
|
584
|
+
{Unital, Inverse} : Loops
|
|
585
|
+
|
|
586
|
+
Then, given a subset `T` of axioms, we want the system to be able to
|
|
587
|
+
select automatically the relevant classes
|
|
588
|
+
`(D_S)_{S\in \mathcal S, S\subset T}`,
|
|
589
|
+
and build from them a category for the objects of ``Cs`` satisfying
|
|
590
|
+
the axioms in `T`, together with its hierarchy of super categories. If
|
|
591
|
+
`T` is in the indexing set `\mathcal S`, then the class of the
|
|
592
|
+
resulting category is directly `D_T`::
|
|
593
|
+
|
|
594
|
+
sage: C = Magmas().Unital().Inverse().Associative(); C
|
|
595
|
+
Category of groups
|
|
596
|
+
sage: type(C)
|
|
597
|
+
<class 'sage.categories.groups.Groups_with_category'>
|
|
598
|
+
|
|
599
|
+
Otherwise, we get a join category::
|
|
600
|
+
|
|
601
|
+
sage: C = Magmas().Infinite().Unital().Associative(); C
|
|
602
|
+
Category of infinite monoids
|
|
603
|
+
sage: type(C)
|
|
604
|
+
<class 'sage.categories.category.JoinCategory_with_category'>
|
|
605
|
+
sage: C.super_categories()
|
|
606
|
+
[Category of monoids, Category of infinite sets]
|
|
607
|
+
|
|
608
|
+
Concrete model as an arborescence of nested classes
|
|
609
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
610
|
+
|
|
611
|
+
We further want the construction to be efficient and amenable to
|
|
612
|
+
laziness. This led us to the following design decision: the collection
|
|
613
|
+
`(D_S)_{S\in \mathcal S}` of classes should be structured as an
|
|
614
|
+
arborescence (or equivalently a *rooted forest*). The root is ``Cs``,
|
|
615
|
+
corresponding to `S=\emptyset`. Any other class `D_S` should be the
|
|
616
|
+
child of a single class `D_{S'}` where `S'` is obtained from `S` by
|
|
617
|
+
removing a single axiom `A`. Of course, `D_{S'}` and `A` are
|
|
618
|
+
respectively the base category class and axiom of the category with
|
|
619
|
+
axiom `D_S` that we have met in the first section.
|
|
620
|
+
|
|
621
|
+
At this point, we urge the reader to explore the code of
|
|
622
|
+
:class:`Magmas` and
|
|
623
|
+
:class:`~.distributive_magmas_and_additive_magmas.DistributiveMagmasAndAdditiveMagmas`
|
|
624
|
+
and see how the arborescence structure on the categories with axioms
|
|
625
|
+
is reflected by the nesting of category classes.
|
|
626
|
+
|
|
627
|
+
Discussion of the design
|
|
628
|
+
^^^^^^^^^^^^^^^^^^^^^^^^
|
|
629
|
+
|
|
630
|
+
Performance
|
|
631
|
+
~~~~~~~~~~~
|
|
632
|
+
|
|
633
|
+
Thanks to the arborescence structure on subsets of axioms,
|
|
634
|
+
constructing the hierarchy of categories and computing intersections
|
|
635
|
+
can be made efficient with, roughly speaking, a linear/quadratic
|
|
636
|
+
complexity in the size of the involved category hierarchy multiplied
|
|
637
|
+
by the number of axioms (see Section :ref:`axioms-algorithmic`). This
|
|
638
|
+
is to be put in perspective with the manipulation of arbitrary
|
|
639
|
+
collections of subsets (aka boolean functions) which can easily raise
|
|
640
|
+
NP-hard problems.
|
|
641
|
+
|
|
642
|
+
Furthermore, thanks to its locality, the algorithms can be made
|
|
643
|
+
suitably lazy: in particular, only the involved category classes need
|
|
644
|
+
to be imported.
|
|
645
|
+
|
|
646
|
+
Flexibility
|
|
647
|
+
~~~~~~~~~~~
|
|
648
|
+
|
|
649
|
+
This design also brings in quite some flexibility, with the
|
|
650
|
+
possibility to support features such as defining new axioms depending
|
|
651
|
+
on other axioms and deduction rules. See below.
|
|
652
|
+
|
|
653
|
+
Asymmetry
|
|
654
|
+
~~~~~~~~~
|
|
655
|
+
|
|
656
|
+
As we have seen at the beginning of this section, this design
|
|
657
|
+
introduces an asymmetry. It's not so bad in practice, since in most
|
|
658
|
+
practical cases, we want to work incrementally. It's for example more
|
|
659
|
+
natural to describe :class:`FiniteFields` as :class:`Fields` with the
|
|
660
|
+
axiom ``Finite`` rather than :class:`Magmas` and
|
|
661
|
+
:class:`AdditiveMagmas` with all (or at least sufficiently many) of
|
|
662
|
+
the following axioms::
|
|
663
|
+
|
|
664
|
+
sage: sorted(Fields().axioms())
|
|
665
|
+
['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse',
|
|
666
|
+
'AdditiveUnital', 'Associative', 'Commutative', 'Distributive',
|
|
667
|
+
'Division', 'NoZeroDivisors', 'Unital']
|
|
668
|
+
|
|
669
|
+
The main limitation is that the infrastructure currently imposes to be
|
|
670
|
+
incremental by steps of a single axiom.
|
|
671
|
+
|
|
672
|
+
In practice, among the roughly 60 categories with axioms that are
|
|
673
|
+
currently implemented in Sage, most admitted a (rather) natural choice
|
|
674
|
+
of a base category and single axiom to add. For example, one usually
|
|
675
|
+
thinks more naturally of a monoid as a semigroup which is unital
|
|
676
|
+
rather than as a unital magma which is associative. Modeling this
|
|
677
|
+
asymmetry in the code actually brings a bonus: it is used for printing
|
|
678
|
+
out categories in a (heuristically) mathematician-friendly way::
|
|
679
|
+
|
|
680
|
+
sage: Magmas().Commutative().Associative()
|
|
681
|
+
Category of commutative semigroups
|
|
682
|
+
|
|
683
|
+
Only in a few cases is a choice made that feels mathematically
|
|
684
|
+
arbitrary. This is essentially in the chain of nested classes
|
|
685
|
+
:class:`.distributive_magmas_and_additive_magmas.DistributiveMagmasAndAdditiveMagmas.AdditiveAssociative.AdditiveCommutative.AdditiveUnital.Associative`.
|
|
686
|
+
|
|
687
|
+
Placeholder classes
|
|
688
|
+
~~~~~~~~~~~~~~~~~~~
|
|
689
|
+
|
|
690
|
+
Given that we can only add a single axiom at a time when implementing
|
|
691
|
+
a :class:`CategoryWithAxiom`, we need to create a few category classes
|
|
692
|
+
that are just placeholders. For the worst example, see the chain of
|
|
693
|
+
nested classes
|
|
694
|
+
:class:`.distributive_magmas_and_additive_magmas.DistributiveMagmasAndAdditiveMagmas.AdditiveAssociative.AdditiveCommutative.AdditiveUnital.Associative`.
|
|
695
|
+
|
|
696
|
+
This is suboptimal, but fits within the scope of the axiom
|
|
697
|
+
infrastructure which is to reduce a potentially exponential number of
|
|
698
|
+
placeholder category classes to just a couple.
|
|
699
|
+
|
|
700
|
+
Note also that, in the above example, it's likely that some of the
|
|
701
|
+
intermediate classes will grow to non placeholder ones, as people will
|
|
702
|
+
explore more weaker variants of rings.
|
|
703
|
+
|
|
704
|
+
Mismatch between the arborescence of nested classes and the hierarchy of categories
|
|
705
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
706
|
+
|
|
707
|
+
The fact that the hierarchy relation between categories is not
|
|
708
|
+
reflected directly as a relation between the classes may sound
|
|
709
|
+
suspicious at first! However, as mentioned in the primer, this is
|
|
710
|
+
actually a big selling point of the axioms infrastructure: by
|
|
711
|
+
calculating automatically the hierarchy relation between categories
|
|
712
|
+
with axioms one avoids the nightmare of maintaining it by hand.
|
|
713
|
+
Instead, only a rather minimal number of links needs to be maintained
|
|
714
|
+
in the code (one per category with axiom).
|
|
715
|
+
|
|
716
|
+
Besides, with the flexibility introduced by runtime deduction rules
|
|
717
|
+
(see below), the hierarchy of categories may depend on the parameters
|
|
718
|
+
of the categories and not just their class. So it's fine to make it
|
|
719
|
+
clear from the onset that the two relations do not match.
|
|
720
|
+
|
|
721
|
+
Evolutivity
|
|
722
|
+
~~~~~~~~~~~
|
|
723
|
+
|
|
724
|
+
At this point, the arborescence structure has to be hardcoded by hand
|
|
725
|
+
with the annoyances we have seen. This does not preclude, in a future
|
|
726
|
+
iteration, to design and implement some idiom for categories with
|
|
727
|
+
axioms that adds several axioms at once to a base category; maybe some
|
|
728
|
+
variation around::
|
|
729
|
+
|
|
730
|
+
class DistributiveMagmasAndAdditiveMagmas:
|
|
731
|
+
...
|
|
732
|
+
|
|
733
|
+
@category_with_axiom(
|
|
734
|
+
AdditiveAssociative,
|
|
735
|
+
AdditiveCommutative,
|
|
736
|
+
AdditiveUnital,
|
|
737
|
+
AdditiveInverse,
|
|
738
|
+
Associative)
|
|
739
|
+
def _(): return LazyImport('sage.categories.rngs', 'Rngs', at_startup=True)
|
|
740
|
+
|
|
741
|
+
or::
|
|
742
|
+
|
|
743
|
+
register_axiom_category(DistributiveMagmasAndAdditiveMagmas,
|
|
744
|
+
{AdditiveAssociative,
|
|
745
|
+
AdditiveCommutative,
|
|
746
|
+
AdditiveUnital,
|
|
747
|
+
AdditiveInverse,
|
|
748
|
+
Associative},
|
|
749
|
+
'sage.categories.rngs', 'Rngs', at_startup=True)
|
|
750
|
+
|
|
751
|
+
The infrastructure would then be in charge of building the appropriate
|
|
752
|
+
arborescence under the hood. Or rely on some database (see discussion
|
|
753
|
+
on :issue:`10963`, in particular at the end of comment 332).
|
|
754
|
+
|
|
755
|
+
Axioms defined upon other axioms
|
|
756
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
757
|
+
|
|
758
|
+
Sometimes an axiom can only be defined when some other axiom
|
|
759
|
+
holds. For example, the axiom ``NoZeroDivisors`` only makes sense if
|
|
760
|
+
there is a zero, that is if the axiom ``AdditiveUnital`` holds. Hence,
|
|
761
|
+
for the category
|
|
762
|
+
:class:`~.magmas_and_additive_magmas.MagmasAndAdditiveMagmas`, we
|
|
763
|
+
consider in the abstract model only those subsets of axioms where the
|
|
764
|
+
presence of ``NoZeroDivisors`` implies that of ``AdditiveUnital``. We
|
|
765
|
+
also want the axiom to be only available if meaningful::
|
|
766
|
+
|
|
767
|
+
sage: Rings().NoZeroDivisors()
|
|
768
|
+
Category of domains
|
|
769
|
+
sage: Rings().Commutative().NoZeroDivisors()
|
|
770
|
+
Category of integral domains
|
|
771
|
+
sage: Semirings().NoZeroDivisors()
|
|
772
|
+
Traceback (most recent call last):
|
|
773
|
+
...
|
|
774
|
+
AttributeError: 'Semirings_with_category' object has no attribute 'NoZeroDivisors'...
|
|
775
|
+
|
|
776
|
+
Concretely, this is to be implemented by defining the new axiom in the
|
|
777
|
+
(``SubcategoryMethods`` nested class of the) appropriate category with
|
|
778
|
+
axiom. For example the axiom ``NoZeroDivisors`` would be naturally
|
|
779
|
+
defined in
|
|
780
|
+
:class:`.magmas_and_additive_magmas.MagmasAndAdditiveMagmas.Distributive.AdditiveUnital`.
|
|
781
|
+
|
|
782
|
+
.. NOTE::
|
|
783
|
+
|
|
784
|
+
The axiom ``NoZeroDivisors`` is currently defined in
|
|
785
|
+
:class:`Rings`, by simple lack of need for the feature; it should
|
|
786
|
+
be lifted up as soon as relevant, that is when some code will be
|
|
787
|
+
available for parents with no zero divisors that are not
|
|
788
|
+
necessarily rings.
|
|
789
|
+
|
|
790
|
+
.. _axioms-deduction-rules:
|
|
791
|
+
|
|
792
|
+
Deduction rules
|
|
793
|
+
^^^^^^^^^^^^^^^
|
|
794
|
+
|
|
795
|
+
A similar situation is when an axiom ``A`` of a category ``Cs``
|
|
796
|
+
implies some other axiom ``B``, with the same consequence as above on
|
|
797
|
+
the subsets of axioms appearing in the abstract model. For example, a
|
|
798
|
+
division ring necessarily has no zero divisors::
|
|
799
|
+
|
|
800
|
+
sage: 'NoZeroDivisors' in Rings().Division().axioms()
|
|
801
|
+
True
|
|
802
|
+
sage: 'NoZeroDivisors' in Rings().axioms()
|
|
803
|
+
False
|
|
804
|
+
|
|
805
|
+
This deduction rule is implemented by the method
|
|
806
|
+
:meth:`Rings.Division.extra_super_categories`::
|
|
807
|
+
|
|
808
|
+
sage: Rings().Division().extra_super_categories()
|
|
809
|
+
(Category of domains,)
|
|
810
|
+
|
|
811
|
+
In general, this is to be implemented by a method
|
|
812
|
+
``Cs.A.extra_super_categories`` returning a tuple ``(Cs().B(),)``, or
|
|
813
|
+
preferably ``(Ds().B(),)`` where ``Ds`` is the category defining the
|
|
814
|
+
axiom ``B``.
|
|
815
|
+
|
|
816
|
+
This follows the same idiom as for deduction rules about functorial
|
|
817
|
+
constructions (see :meth:`.covariant_functorial_construction.CovariantConstructionCategory.extra_super_categories`).
|
|
818
|
+
For example, the fact that a Cartesian product of associative magmas
|
|
819
|
+
(i.e. of semigroups) is an associative magma is implemented in
|
|
820
|
+
:meth:`Semigroups.CartesianProducts.extra_super_categories`::
|
|
821
|
+
|
|
822
|
+
sage: Magmas().Associative()
|
|
823
|
+
Category of semigroups
|
|
824
|
+
sage: Magmas().Associative().CartesianProducts().extra_super_categories()
|
|
825
|
+
[Category of semigroups]
|
|
826
|
+
|
|
827
|
+
Similarly, the fact that the algebra of a commutative magma is
|
|
828
|
+
commutative is implemented in
|
|
829
|
+
:meth:`Magmas.Commutative.Algebras.extra_super_categories`::
|
|
830
|
+
|
|
831
|
+
sage: Magmas().Commutative().Algebras(QQ).extra_super_categories()
|
|
832
|
+
[Category of commutative magmas]
|
|
833
|
+
|
|
834
|
+
.. WARNING::
|
|
835
|
+
|
|
836
|
+
In some situations this idiom is inapplicable as it would require
|
|
837
|
+
to implement two classes for the same category. This is the
|
|
838
|
+
purpose of the next section.
|
|
839
|
+
|
|
840
|
+
Special case
|
|
841
|
+
~~~~~~~~~~~~
|
|
842
|
+
|
|
843
|
+
In the previous examples, the deduction rule only had an influence on
|
|
844
|
+
the super categories of the category with axiom being constructed. For
|
|
845
|
+
example, when constructing ``Rings().Division()``, the rule
|
|
846
|
+
:meth:`Rings.Division.extra_super_categories` simply adds
|
|
847
|
+
``Rings().NoZeroDivisors()`` as a super category thereof.
|
|
848
|
+
|
|
849
|
+
In some situations this idiom is inapplicable because a class for the
|
|
850
|
+
category with axiom under construction already exists elsewhere. Take
|
|
851
|
+
for example Wedderburn's theorem: any finite division ring is
|
|
852
|
+
commutative, i.e. is a finite field. In other words,
|
|
853
|
+
``DivisionRings().Finite()`` *coincides* with ``Fields().Finite()``::
|
|
854
|
+
|
|
855
|
+
sage: DivisionRings().Finite()
|
|
856
|
+
Category of finite enumerated fields
|
|
857
|
+
sage: DivisionRings().Finite() is Fields().Finite()
|
|
858
|
+
True
|
|
859
|
+
|
|
860
|
+
Therefore we cannot create a class ``DivisionRings.Finite`` to hold
|
|
861
|
+
the desired ``extra_super_categories`` method, because there is
|
|
862
|
+
already a class for this category with axiom, namely
|
|
863
|
+
``Fields.Finite``.
|
|
864
|
+
|
|
865
|
+
A natural idiom would be to have ``DivisionRings.Finite`` be a link to
|
|
866
|
+
``Fields.Finite`` (locally introducing an undirected cycle in the
|
|
867
|
+
arborescence of nested classes). It would be a bit tricky to implement
|
|
868
|
+
though, since one would need to detect, upon constructing
|
|
869
|
+
``DivisionRings().Finite()``, that ``DivisionRings.Finite`` is
|
|
870
|
+
actually ``Fields.Finite``, in order to construct appropriately
|
|
871
|
+
``Fields().Finite()``; and reciprocally, upon computing the super
|
|
872
|
+
categories of ``Fields().Finite()``, to not try to add
|
|
873
|
+
``DivisionRings().Finite()`` as a super category.
|
|
874
|
+
|
|
875
|
+
Instead the current idiom is to have a method
|
|
876
|
+
``DivisionRings.Finite_extra_super_categories`` which mimics the
|
|
877
|
+
behavior of the would-be
|
|
878
|
+
``DivisionRings.Finite.extra_super_categories``::
|
|
879
|
+
|
|
880
|
+
sage: DivisionRings().Finite_extra_super_categories()
|
|
881
|
+
(Category of commutative magmas,)
|
|
882
|
+
|
|
883
|
+
This idiom is admittedly rudimentary, but consistent with how
|
|
884
|
+
mathematical facts specifying non trivial inclusion relations between
|
|
885
|
+
categories are implemented elsewhere in the various
|
|
886
|
+
``extra_super_categories`` methods of axiom categories and covariant
|
|
887
|
+
functorial constructions. Besides, it gives a natural spot (the
|
|
888
|
+
docstring of the method) to document and test the modeling of the
|
|
889
|
+
mathematical fact. Finally, Wedderburn's theorem is arguably a theorem
|
|
890
|
+
about division rings (in the context of division rings, finiteness
|
|
891
|
+
implies commutativity) and therefore lives naturally in
|
|
892
|
+
:class:`DivisionRings`.
|
|
893
|
+
|
|
894
|
+
An alternative would be to implement the category of finite division
|
|
895
|
+
rings (i.e. finite fields) in a class ``DivisionRings.Finite`` rather
|
|
896
|
+
than ``Fields.Finite``::
|
|
897
|
+
|
|
898
|
+
sage: from sage.categories.category_with_axiom import CategoryWithAxiom
|
|
899
|
+
|
|
900
|
+
sage: class MyDivisionRings(Category):
|
|
901
|
+
....: def super_categories(self):
|
|
902
|
+
....: return [Rings()]
|
|
903
|
+
|
|
904
|
+
sage: class MyFields(Category):
|
|
905
|
+
....: def super_categories(self):
|
|
906
|
+
....: return [MyDivisionRings()]
|
|
907
|
+
|
|
908
|
+
sage: class MyFiniteFields(CategoryWithAxiom):
|
|
909
|
+
....: _base_category_class_and_axiom = (MyDivisionRings, "Finite")
|
|
910
|
+
....: def extra_super_categories(self): # Wedderburn's theorem
|
|
911
|
+
....: return [MyFields()]
|
|
912
|
+
|
|
913
|
+
sage: MyDivisionRings.Finite = MyFiniteFields
|
|
914
|
+
|
|
915
|
+
sage: MyDivisionRings().Finite()
|
|
916
|
+
Category of my finite fields
|
|
917
|
+
sage: MyFields().Finite() is MyDivisionRings().Finite()
|
|
918
|
+
True
|
|
919
|
+
|
|
920
|
+
In general, if several categories ``C1s()``, ``C2s()``, ... are mapped to
|
|
921
|
+
the same category when applying some axiom ``A`` (that is ``C1s().A()
|
|
922
|
+
== C2s().A() == ...``), then one should be careful to implement this
|
|
923
|
+
category in a single class ``Cs.A``, and set up methods
|
|
924
|
+
``extra_super_categories`` or ``A_extra_super_categories`` methods as
|
|
925
|
+
appropriate. Each such method should return something like
|
|
926
|
+
``[C2s()]`` and not ``[C2s().A()]`` for the latter would likely lead
|
|
927
|
+
to an infinite recursion.
|
|
928
|
+
|
|
929
|
+
.. TOPIC:: Design discussion
|
|
930
|
+
|
|
931
|
+
Supporting similar deduction rules will be an important feature in
|
|
932
|
+
the future, with quite a few occurrences already implemented in
|
|
933
|
+
upcoming issues. For the time being though there is a single
|
|
934
|
+
occurrence of this idiom outside of the tests. So this would be an
|
|
935
|
+
easy thing to refactor after :issue:`10963` if a better idiom is
|
|
936
|
+
found.
|
|
937
|
+
|
|
938
|
+
Larger synthetic examples
|
|
939
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
940
|
+
|
|
941
|
+
We now consider some larger synthetic examples to check that the
|
|
942
|
+
machinery works as expected. Let us start with a category defining a
|
|
943
|
+
bunch of axioms, using :func:`axiom` for conciseness (don't do it for
|
|
944
|
+
real axioms; they deserve a full documentation!)::
|
|
945
|
+
|
|
946
|
+
sage: from sage.categories.category_singleton import Category_singleton
|
|
947
|
+
sage: from sage.categories.category_with_axiom import axiom
|
|
948
|
+
sage: import sage.categories.category_with_axiom
|
|
949
|
+
sage: all_axioms = sage.categories.category_with_axiom.all_axioms
|
|
950
|
+
sage: all_axioms += ("B","C","D","E","F")
|
|
951
|
+
|
|
952
|
+
sage: class As(Category_singleton):
|
|
953
|
+
....: def super_categories(self):
|
|
954
|
+
....: return [Objects()]
|
|
955
|
+
....:
|
|
956
|
+
....: class SubcategoryMethods:
|
|
957
|
+
....: B = axiom("B")
|
|
958
|
+
....: C = axiom("C")
|
|
959
|
+
....: D = axiom("D")
|
|
960
|
+
....: E = axiom("E")
|
|
961
|
+
....: F = axiom("F")
|
|
962
|
+
....:
|
|
963
|
+
....: class B(CategoryWithAxiom):
|
|
964
|
+
....: pass
|
|
965
|
+
....: class C(CategoryWithAxiom):
|
|
966
|
+
....: pass
|
|
967
|
+
....: class D(CategoryWithAxiom):
|
|
968
|
+
....: pass
|
|
969
|
+
....: class E(CategoryWithAxiom):
|
|
970
|
+
....: pass
|
|
971
|
+
....: class F(CategoryWithAxiom):
|
|
972
|
+
....: pass
|
|
973
|
+
|
|
974
|
+
Now we construct a subcategory where, by some theorem of William,
|
|
975
|
+
axioms ``B`` and ``C`` together are equivalent to ``E`` and ``F``
|
|
976
|
+
together::
|
|
977
|
+
|
|
978
|
+
sage: class A1s(Category_singleton):
|
|
979
|
+
....: def super_categories(self):
|
|
980
|
+
....: return [As()]
|
|
981
|
+
....:
|
|
982
|
+
....: class B(CategoryWithAxiom):
|
|
983
|
+
....: def C_extra_super_categories(self):
|
|
984
|
+
....: return [As().E(), As().F()]
|
|
985
|
+
....:
|
|
986
|
+
....: class E(CategoryWithAxiom):
|
|
987
|
+
....: def F_extra_super_categories(self):
|
|
988
|
+
....: return [As().B(), As().C()]
|
|
989
|
+
|
|
990
|
+
sage: A1s().B().C()
|
|
991
|
+
Category of e f a1s
|
|
992
|
+
|
|
993
|
+
The axioms ``B`` and ``C`` do not show up in the name of the obtained
|
|
994
|
+
category because, for concision, the printing uses some heuristics to
|
|
995
|
+
not show axioms that are implied by others. But they are satisfied::
|
|
996
|
+
|
|
997
|
+
sage: sorted(A1s().B().C().axioms())
|
|
998
|
+
['B', 'C', 'E', 'F']
|
|
999
|
+
|
|
1000
|
+
Note also that this is a join category::
|
|
1001
|
+
|
|
1002
|
+
sage: type(A1s().B().C())
|
|
1003
|
+
<class 'sage.categories.category.JoinCategory_with_category'>
|
|
1004
|
+
sage: A1s().B().C().super_categories()
|
|
1005
|
+
[Category of e a1s,
|
|
1006
|
+
Category of f as,
|
|
1007
|
+
Category of b a1s,
|
|
1008
|
+
Category of c as]
|
|
1009
|
+
|
|
1010
|
+
As desired, William's theorem holds::
|
|
1011
|
+
|
|
1012
|
+
sage: A1s().B().C() is A1s().E().F()
|
|
1013
|
+
True
|
|
1014
|
+
|
|
1015
|
+
and propagates appropriately to subcategories::
|
|
1016
|
+
|
|
1017
|
+
sage: C = A1s().E().F().D().B().C()
|
|
1018
|
+
sage: C is A1s().B().C().E().F().D() # commutativity
|
|
1019
|
+
True
|
|
1020
|
+
sage: C is A1s().E().F().E().F().D() # William's theorem
|
|
1021
|
+
True
|
|
1022
|
+
sage: C is A1s().E().E().F().F().D() # commutativity
|
|
1023
|
+
True
|
|
1024
|
+
sage: C is A1s().E().F().D() # idempotency
|
|
1025
|
+
True
|
|
1026
|
+
sage: C is A1s().D().E().F()
|
|
1027
|
+
True
|
|
1028
|
+
|
|
1029
|
+
In this quick variant, we actually implement the category of ``b c
|
|
1030
|
+
a2s``, and choose to do so in ``A2s.B.C``::
|
|
1031
|
+
|
|
1032
|
+
sage: class A2s(Category_singleton):
|
|
1033
|
+
....: def super_categories(self):
|
|
1034
|
+
....: return [As()]
|
|
1035
|
+
....:
|
|
1036
|
+
....: class B(CategoryWithAxiom):
|
|
1037
|
+
....: class C(CategoryWithAxiom):
|
|
1038
|
+
....: def extra_super_categories(self):
|
|
1039
|
+
....: return [As().E(), As().F()]
|
|
1040
|
+
....:
|
|
1041
|
+
....: class E(CategoryWithAxiom):
|
|
1042
|
+
....: def F_extra_super_categories(self):
|
|
1043
|
+
....: return [As().B(), As().C()]
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
sage: A2s().B().C()
|
|
1047
|
+
Category of e f a2s
|
|
1048
|
+
sage: sorted(A2s().B().C().axioms())
|
|
1049
|
+
['B', 'C', 'E', 'F']
|
|
1050
|
+
sage: type(A2s().B().C())
|
|
1051
|
+
<class '__main__.A2s.B.C_with_category'>
|
|
1052
|
+
|
|
1053
|
+
As desired, William's theorem and its consequences hold::
|
|
1054
|
+
|
|
1055
|
+
sage: A2s().B().C() is A2s().E().F()
|
|
1056
|
+
True
|
|
1057
|
+
sage: C = A2s().E().F().D().B().C()
|
|
1058
|
+
sage: C is A2s().B().C().E().F().D() # commutativity
|
|
1059
|
+
True
|
|
1060
|
+
sage: C is A2s().E().F().E().F().D() # William's theorem
|
|
1061
|
+
True
|
|
1062
|
+
sage: C is A2s().E().E().F().F().D() # commutativity
|
|
1063
|
+
True
|
|
1064
|
+
sage: C is A2s().E().F().D() # idempotency
|
|
1065
|
+
True
|
|
1066
|
+
sage: C is A2s().D().E().F()
|
|
1067
|
+
True
|
|
1068
|
+
|
|
1069
|
+
Finally, we "accidentally" implement the category of ``b c a1s``, both
|
|
1070
|
+
in ``A3s.B.C`` and ``A3s.E.F``::
|
|
1071
|
+
|
|
1072
|
+
sage: class A3s(Category_singleton):
|
|
1073
|
+
....: def super_categories(self):
|
|
1074
|
+
....: return [As()]
|
|
1075
|
+
....:
|
|
1076
|
+
....: class B(CategoryWithAxiom):
|
|
1077
|
+
....: class C(CategoryWithAxiom):
|
|
1078
|
+
....: def extra_super_categories(self):
|
|
1079
|
+
....: return [As().E(), As().F()]
|
|
1080
|
+
....:
|
|
1081
|
+
....: class E(CategoryWithAxiom):
|
|
1082
|
+
....: class F(CategoryWithAxiom):
|
|
1083
|
+
....: def extra_super_categories(self):
|
|
1084
|
+
....: return [As().B(), As().C()]
|
|
1085
|
+
|
|
1086
|
+
We can still construct, say::
|
|
1087
|
+
|
|
1088
|
+
sage: A3s().B()
|
|
1089
|
+
Category of b a3s
|
|
1090
|
+
sage: A3s().C()
|
|
1091
|
+
Category of c a3s
|
|
1092
|
+
|
|
1093
|
+
However,
|
|
1094
|
+
::
|
|
1095
|
+
|
|
1096
|
+
sage: A3s().B().C() # not tested
|
|
1097
|
+
|
|
1098
|
+
runs into an infinite recursion loop, as ``A3s().B().C()`` wants to
|
|
1099
|
+
have ``A3s().E().F()`` as super category and reciprocally.
|
|
1100
|
+
|
|
1101
|
+
.. TODO::
|
|
1102
|
+
|
|
1103
|
+
The above example violates the specifications (a category should
|
|
1104
|
+
be modelled by at most one class), so it's appropriate that it
|
|
1105
|
+
fails. Yet, the error message could be usefully complemented by
|
|
1106
|
+
some hint at what the source of the problem is (a category
|
|
1107
|
+
implemented in two distinct classes). Leaving a large enough piece
|
|
1108
|
+
of the backtrace would be useful though, so that one can explore
|
|
1109
|
+
where the issue comes from (e.g. with post mortem debugging).
|
|
1110
|
+
|
|
1111
|
+
Specifications
|
|
1112
|
+
==============
|
|
1113
|
+
|
|
1114
|
+
After fixing some vocabulary, we summarize here some specifications
|
|
1115
|
+
about categories and axioms.
|
|
1116
|
+
|
|
1117
|
+
The lattice of constructible categories
|
|
1118
|
+
---------------------------------------
|
|
1119
|
+
|
|
1120
|
+
A mathematical category `C` is *implemented* if there is a class in
|
|
1121
|
+
Sage modelling it; it is *constructible* if it is either implemented,
|
|
1122
|
+
or is the intersection of *implemented* categories; in the latter case
|
|
1123
|
+
it is modelled by a :class:`~.category.JoinCategory`. The comparison of two
|
|
1124
|
+
constructible categories with the :meth:`Category.is_subcategory`
|
|
1125
|
+
method is supposed to model the comparison of the corresponding
|
|
1126
|
+
mathematical categories for inclusion of the objects (see
|
|
1127
|
+
:ref:`category-primer-subcategory` for details). For example::
|
|
1128
|
+
|
|
1129
|
+
sage: Fields().is_subcategory(Rings())
|
|
1130
|
+
True
|
|
1131
|
+
|
|
1132
|
+
However this modelling may be incomplete. It can happen that a
|
|
1133
|
+
mathematical fact implying that a category `A` is a subcategory of a
|
|
1134
|
+
category `B` is not implemented. Still, the comparison should endow
|
|
1135
|
+
the set of constructible categories with a poset structure and in fact
|
|
1136
|
+
a lattice structure.
|
|
1137
|
+
|
|
1138
|
+
In this lattice, the join of two categories (:meth:`Category.join`) is
|
|
1139
|
+
supposed to model their intersection. Given that we compare categories
|
|
1140
|
+
for inclusion, it would be more natural to call this operation the
|
|
1141
|
+
*meet*; blames go to me (Nicolas) for originally comparing categories
|
|
1142
|
+
by *amount of structure* rather than by *inclusion*. In practice, the
|
|
1143
|
+
join of two categories may be a strict super category of their
|
|
1144
|
+
intersection; first because this intersection might not be
|
|
1145
|
+
constructible; second because Sage might miss some mathematical
|
|
1146
|
+
information to recover the smallest constructible super category of
|
|
1147
|
+
the intersection.
|
|
1148
|
+
|
|
1149
|
+
Axioms
|
|
1150
|
+
------
|
|
1151
|
+
|
|
1152
|
+
We say that an axiom ``A`` is *defined by* a category ``Cs()`` if
|
|
1153
|
+
``Cs`` defines an appropriate method ``Cs.SubcategoryMethods.A``, with
|
|
1154
|
+
the semantic of the axiom specified in the documentation; for any
|
|
1155
|
+
subcategory ``Ds()``, ``Ds().A()`` models the subcategory of the
|
|
1156
|
+
objects of ``Ds()`` satisfying ``A``. In this case, we say that the
|
|
1157
|
+
axiom ``A`` is *defined for* the category ``Ds()``. Furthermore,
|
|
1158
|
+
``Ds`` *implements the axiom* ``A`` if ``Ds`` has a category with
|
|
1159
|
+
axiom as nested class ``Ds.A``. The category ``Ds()`` *satisfies* the
|
|
1160
|
+
axiom if ``Ds()`` is a subcategory of ``Cs().A()`` (meaning that all
|
|
1161
|
+
the objects of ``Ds()`` are known to satisfy the axiom ``A``).
|
|
1162
|
+
|
|
1163
|
+
A digression on the structure of fibers when adding an axiom
|
|
1164
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
1165
|
+
|
|
1166
|
+
Consider the application `\phi_A` which maps a category to its
|
|
1167
|
+
category of objects satisfying `A`. Equivalently, `\phi_A` is
|
|
1168
|
+
computing the intersection with the defining category with axiom of
|
|
1169
|
+
`A`. It follows immediately from the latter that `\phi_A` is a
|
|
1170
|
+
regressive endomorphism of the lattice of categories. It restricts
|
|
1171
|
+
to a regressive endomorphism ``Cs() |-> Cs().A()``
|
|
1172
|
+
on the lattice of constructible categories.
|
|
1173
|
+
|
|
1174
|
+
This endomorphism may have non trivial fibers, as in our favorite
|
|
1175
|
+
example: ``DivisionRings()`` and ``Fields()`` are in the same fiber
|
|
1176
|
+
for the axiom ``Finite``::
|
|
1177
|
+
|
|
1178
|
+
sage: DivisionRings().Finite() is Fields().Finite()
|
|
1179
|
+
True
|
|
1180
|
+
|
|
1181
|
+
Consider the intersection `S` of such a fiber of `\phi_A` with the
|
|
1182
|
+
upper set `I_A` of categories that do not satisfy ``A``. The fiber
|
|
1183
|
+
itself is a sublattice. However `I_A` is not guaranteed to be stable
|
|
1184
|
+
under intersection (though exceptions should be rare). Therefore,
|
|
1185
|
+
there is a priori no guarantee that `S` would be stable under
|
|
1186
|
+
intersection. Also it's presumably finite, in fact small, but this is
|
|
1187
|
+
not guaranteed either.
|
|
1188
|
+
|
|
1189
|
+
Specifications
|
|
1190
|
+
--------------
|
|
1191
|
+
|
|
1192
|
+
- Any constructible category ``C`` should admit a finite number of
|
|
1193
|
+
larger constructible categories.
|
|
1194
|
+
|
|
1195
|
+
- The methods ``super_categories``, ``extra_super_categories``, and
|
|
1196
|
+
friends should always return strict supercategories.
|
|
1197
|
+
|
|
1198
|
+
For example, to specify that a finite division ring is a finite
|
|
1199
|
+
field, ``DivisionRings.Finite_extra_super_categories`` should not
|
|
1200
|
+
return ``Fields().Finite()``! It could possibly return ``Fields()``;
|
|
1201
|
+
but it's preferable to return the largest category that contains the
|
|
1202
|
+
relevant information, in this case ``Magmas().Commutative()``, and
|
|
1203
|
+
to let the infrastructure apply the derivations.
|
|
1204
|
+
|
|
1205
|
+
- The base category of a :class:`CategoryWithAxiom` should be an
|
|
1206
|
+
implemented category (i.e. not a
|
|
1207
|
+
:class:`~.category.JoinCategory`). This is checked by
|
|
1208
|
+
:meth:`CategoryWithAxiom._test_category_with_axiom`.
|
|
1209
|
+
|
|
1210
|
+
- Arborescent structure: Let ``Cs()`` be a category, and `S` be some
|
|
1211
|
+
set of axioms defined in some super categories of ``Cs()`` but not
|
|
1212
|
+
satisfied by ``Cs()``. Suppose we want to provide a category with
|
|
1213
|
+
axiom for the elements of ``Cs()`` satisfying the axioms in
|
|
1214
|
+
`S`. Then, there should be a single enumeration ``A1, A2, ..., Ak``
|
|
1215
|
+
without repetition of axioms in `S` such that
|
|
1216
|
+
``Cs.A1.A2....Ak`` is an implemented category.
|
|
1217
|
+
Furthermore, every intermediate step
|
|
1218
|
+
``Cs.A1.A2....Ai`` with `i\leq k` should be a category with axiom
|
|
1219
|
+
having ``Ai`` as axiom and ``Cs.A1.A2....Ai-1`` as base category
|
|
1220
|
+
class; this base category class should not satisfy ``Ai``. In
|
|
1221
|
+
particular, when some axioms of `S` can be deduced from previous
|
|
1222
|
+
ones by deduction rules, they should not appear in the enumeration
|
|
1223
|
+
``A1, A2, ..., Ak``.
|
|
1224
|
+
|
|
1225
|
+
- In particular, if ``Cs()`` is a category that satisfies some axiom
|
|
1226
|
+
``A`` (e.g. from one of its super categories), then it should not
|
|
1227
|
+
implement that axiom. For example, a category class ``Cs`` can never
|
|
1228
|
+
have a nested class ``Cs.A.A``. Similarly, applying the
|
|
1229
|
+
specification recursively, a category satisfying ``A`` cannot have a
|
|
1230
|
+
nested class ``Cs.A1.A2.A3.A`` where ``A1``, ``A2``, ``A3`` are
|
|
1231
|
+
axioms.
|
|
1232
|
+
|
|
1233
|
+
- A category can only implement an axiom if this axiom is defined by
|
|
1234
|
+
some super category. The code has not been systematically checked to
|
|
1235
|
+
support having two super categories defining the same axiom (which
|
|
1236
|
+
should of course have the same semantic). You are welcome to try, at
|
|
1237
|
+
your own risk. :-)
|
|
1238
|
+
|
|
1239
|
+
- When a category defines an axiom or functorial construction ``A``,
|
|
1240
|
+
this fixes the semantic of ``A`` for all the subcategories. In
|
|
1241
|
+
particular, if two categories define ``A``, then these categories
|
|
1242
|
+
should be independent, and either the semantic of ``A`` should be
|
|
1243
|
+
the same, or there should be no natural intersection between the two
|
|
1244
|
+
hierarchies of subcategories.
|
|
1245
|
+
|
|
1246
|
+
- Any super category of a
|
|
1247
|
+
:class:`~.category.CategoryWithParameters` should either be a
|
|
1248
|
+
:class:`~.category.CategoryWithParameters` or a
|
|
1249
|
+
:class:`Category_singleton`.
|
|
1250
|
+
|
|
1251
|
+
- A :class:`CategoryWithAxiom` having a
|
|
1252
|
+
:class:`~sage.categories.category_singleton.Category_singleton` as base
|
|
1253
|
+
category should be a :class:`CategoryWithAxiom_singleton`. This is handled
|
|
1254
|
+
automatically by :meth:`CategoryWithAxiom.__init__` and checked in
|
|
1255
|
+
:meth:`CategoryWithAxiom._test_category_with_axiom`.
|
|
1256
|
+
|
|
1257
|
+
- A :class:`CategoryWithAxiom` having a
|
|
1258
|
+
:class:`Category_over_base_ring` as base category should be a
|
|
1259
|
+
:class:`Category_over_base_ring`. This currently has to be handled
|
|
1260
|
+
by hand, using :class:`CategoryWithAxiom_over_base_ring`. This is
|
|
1261
|
+
checked in :meth:`CategoryWithAxiom._test_category_with_axiom`.
|
|
1262
|
+
|
|
1263
|
+
.. TODO::
|
|
1264
|
+
|
|
1265
|
+
The following specifications would be desirable but are not yet
|
|
1266
|
+
implemented:
|
|
1267
|
+
|
|
1268
|
+
- A functorial construction category (Graded, CartesianProducts,
|
|
1269
|
+
...) having a :class:`Category_singleton` as base category
|
|
1270
|
+
should be a :class:`CategoryWithAxiom_singleton`.
|
|
1271
|
+
|
|
1272
|
+
Nothing difficult to implement, but this will need to rework the
|
|
1273
|
+
current "no subclass of a concrete class" assertion test of
|
|
1274
|
+
:meth:`Category_singleton.__classcall__`.
|
|
1275
|
+
|
|
1276
|
+
- Similarly, a covariant functorial construction category having a
|
|
1277
|
+
:class:`Category_over_base_ring` as base category should be a
|
|
1278
|
+
:class:`Category_over_base_ring`.
|
|
1279
|
+
|
|
1280
|
+
The following specification might be desirable, or not:
|
|
1281
|
+
|
|
1282
|
+
- A join category involving a :class:`Category_over_base_ring`
|
|
1283
|
+
should be a :class:`Category_over_base_ring`. In the mean
|
|
1284
|
+
time, a ``base_ring`` method is automatically provided for most
|
|
1285
|
+
of those by :meth:`Modules.SubcategoryMethods.base_ring`.
|
|
1286
|
+
|
|
1287
|
+
|
|
1288
|
+
Design goals
|
|
1289
|
+
============
|
|
1290
|
+
|
|
1291
|
+
As pointed out in the primer, the main design goal of the axioms
|
|
1292
|
+
infrastructure is to subdue the potential combinatorial explosion of
|
|
1293
|
+
the category hierarchy by letting the developer focus on implementing
|
|
1294
|
+
a few bookshelves for which there is actual code or mathematical
|
|
1295
|
+
information, and let Sage *compose dynamically and lazily* these
|
|
1296
|
+
building blocks to construct the minimal hierarchy of classes needed
|
|
1297
|
+
for the computation at hand. This allows for the infrastructure to
|
|
1298
|
+
scale smoothly as bookshelves are added, extended, or reorganized.
|
|
1299
|
+
|
|
1300
|
+
Other design goals include:
|
|
1301
|
+
|
|
1302
|
+
- Flexibility in the code layout: the category of, say, finite sets
|
|
1303
|
+
can be implemented either within the Sets category (in a nested
|
|
1304
|
+
class ``Sets.Finite``), or in a separate file (typically in a class
|
|
1305
|
+
``FiniteSets`` in a lazily imported module
|
|
1306
|
+
sage.categories.finite_sets).
|
|
1307
|
+
|
|
1308
|
+
- Single point of truth: a theorem, like Wedderburn's, should be
|
|
1309
|
+
implemented in a single spot.
|
|
1310
|
+
|
|
1311
|
+
- Single entry point: for example, from the entry :class:`Rings`, one
|
|
1312
|
+
can explore a whole range of related categories just by applying
|
|
1313
|
+
axioms and constructions::
|
|
1314
|
+
|
|
1315
|
+
sage: Rings().Commutative().Finite().NoZeroDivisors()
|
|
1316
|
+
Category of finite integral domains
|
|
1317
|
+
sage: Rings().Finite().Division()
|
|
1318
|
+
Category of finite enumerated fields
|
|
1319
|
+
|
|
1320
|
+
This will allow for progressively getting rid of all the entries
|
|
1321
|
+
like :class:`GradedHopfAlgebrasWithBasis` which are polluting the
|
|
1322
|
+
global name space.
|
|
1323
|
+
|
|
1324
|
+
Note that this is not about precluding the existence of multiple
|
|
1325
|
+
natural ways to construct the same category::
|
|
1326
|
+
|
|
1327
|
+
sage: Groups().Finite()
|
|
1328
|
+
Category of finite groups
|
|
1329
|
+
sage: Monoids().Finite().Inverse()
|
|
1330
|
+
Category of finite groups
|
|
1331
|
+
sage: Sets().Finite() & Monoids().Inverse()
|
|
1332
|
+
Category of finite groups
|
|
1333
|
+
|
|
1334
|
+
- Concise idioms for the users (adding axioms, ...)
|
|
1335
|
+
|
|
1336
|
+
- Concise idioms and well highlighted hierarchy of bookshelves for
|
|
1337
|
+
the developer (especially with code folding)
|
|
1338
|
+
|
|
1339
|
+
- Introspection friendly (listing the axioms, recovering the mixins)
|
|
1340
|
+
|
|
1341
|
+
.. NOTE::
|
|
1342
|
+
|
|
1343
|
+
The constructor for instances of this class takes as input the
|
|
1344
|
+
base category. Hence, they should in principle be constructed
|
|
1345
|
+
as::
|
|
1346
|
+
|
|
1347
|
+
sage: FiniteSets(Sets())
|
|
1348
|
+
Category of finite sets
|
|
1349
|
+
|
|
1350
|
+
sage: Sets.Finite(Sets())
|
|
1351
|
+
Category of finite sets
|
|
1352
|
+
|
|
1353
|
+
None of these idioms are really practical for the user. So instead,
|
|
1354
|
+
this object is to be constructed using any of the following idioms::
|
|
1355
|
+
|
|
1356
|
+
sage: Sets()._with_axiom('Finite')
|
|
1357
|
+
Category of finite sets
|
|
1358
|
+
sage: FiniteSets()
|
|
1359
|
+
Category of finite sets
|
|
1360
|
+
sage: Sets().Finite()
|
|
1361
|
+
Category of finite sets
|
|
1362
|
+
|
|
1363
|
+
The later two are implemented using respectively
|
|
1364
|
+
:meth:`CategoryWithAxiom.__classcall__` and
|
|
1365
|
+
:meth:`CategoryWithAxiom.__classget__`.
|
|
1366
|
+
|
|
1367
|
+
Upcoming features
|
|
1368
|
+
=================
|
|
1369
|
+
|
|
1370
|
+
.. TODO::
|
|
1371
|
+
|
|
1372
|
+
- Implement compatibility axiom / functorial constructions. For
|
|
1373
|
+
example, one would want to have::
|
|
1374
|
+
|
|
1375
|
+
A.CartesianProducts() & B.CartesianProducts() = (A&B).CartesianProducts()
|
|
1376
|
+
|
|
1377
|
+
- Once full subcategories are implemented (see :issue:`10668`),
|
|
1378
|
+
make the relevant categories with axioms be such. This can be
|
|
1379
|
+
done systematically for, e.g., the axioms ``Associative`` or
|
|
1380
|
+
``Commutative``, but not for the axiom ``Unital``: a semigroup
|
|
1381
|
+
morphism between two monoids need not preserve the unit.
|
|
1382
|
+
|
|
1383
|
+
Should all full subcategories be implemented in term of axioms?
|
|
1384
|
+
|
|
1385
|
+
.. _axioms-algorithmic:
|
|
1386
|
+
|
|
1387
|
+
Algorithms
|
|
1388
|
+
==========
|
|
1389
|
+
|
|
1390
|
+
Computing joins
|
|
1391
|
+
---------------
|
|
1392
|
+
|
|
1393
|
+
The workhorse of the axiom infrastructure is the algorithm for
|
|
1394
|
+
computing the join `J` of a set `C_1, \ldots, C_k` of categories (see
|
|
1395
|
+
:meth:`Category.join`). Formally, `J` is defined as the largest
|
|
1396
|
+
constructible category such that `J \subset C_i` for all `i`, and
|
|
1397
|
+
`J \subset C.A()` for every constructible category `C \supset J`
|
|
1398
|
+
and any axiom `A` satisfied by `J`.
|
|
1399
|
+
|
|
1400
|
+
The join `J` is naturally computed as a closure in the lattice of
|
|
1401
|
+
constructible categories: it starts with the `C_i`'s, gathers the set
|
|
1402
|
+
`S` of all the axioms satisfied by them, and repeatedly adds each
|
|
1403
|
+
axiom `A` to those categories that do not yet satisfy `A` using
|
|
1404
|
+
:meth:`Category._with_axiom`. Due to deduction rules or (extra) super
|
|
1405
|
+
categories, new categories or new axioms may appear in the
|
|
1406
|
+
process. The process stops when each remaining category has been
|
|
1407
|
+
combined with each axiom. In practice, only the smallest categories
|
|
1408
|
+
are kept along the way; this is correct because adding an axiom is
|
|
1409
|
+
covariant: ``C.A()`` is a subcategory of ``D.A()`` whenever ``C`` is a
|
|
1410
|
+
subcategory of ``D``.
|
|
1411
|
+
|
|
1412
|
+
As usual in such closure computations, the result does not depend on
|
|
1413
|
+
the order of execution. Furthermore, given that adding an axiom is an
|
|
1414
|
+
idempotent and regressive operation, the process is guaranteed to stop
|
|
1415
|
+
in a number of steps which is bounded by the number of super
|
|
1416
|
+
categories of `J`. In particular, it is a finite process.
|
|
1417
|
+
|
|
1418
|
+
.. TODO::
|
|
1419
|
+
|
|
1420
|
+
Detail this a bit. What could typically go wrong is a situation
|
|
1421
|
+
where, for some category ``C1``, ``C1.A()`` specifies a category
|
|
1422
|
+
``C2`` as super category such that ``C2.A()`` specifies ``C3`` as
|
|
1423
|
+
super category such that ...; this would clearly cause an infinite
|
|
1424
|
+
execution. Note that this situation violates the specifications
|
|
1425
|
+
since ``C1.A()`` is supposed to be a subcategory of ``C2.A()``,
|
|
1426
|
+
... so we would have an infinite increasing chain of constructible
|
|
1427
|
+
categories.
|
|
1428
|
+
|
|
1429
|
+
It's reasonable to assume that there is a finite number of axioms
|
|
1430
|
+
defined in the code. There remains to use this assumption to argue
|
|
1431
|
+
that any infinite execution of the algorithm would give rise to
|
|
1432
|
+
such an infinite sequence.
|
|
1433
|
+
|
|
1434
|
+
Adding an axiom
|
|
1435
|
+
---------------
|
|
1436
|
+
|
|
1437
|
+
Let ``Cs`` be a category and ``A`` an axiom defined for this
|
|
1438
|
+
category. To compute ``Cs().A()``, there are two cases.
|
|
1439
|
+
|
|
1440
|
+
Adding an axiom ``A`` to a category ``Cs()`` not implementing it
|
|
1441
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
1442
|
+
|
|
1443
|
+
In this case, ``Cs().A()`` returns the join of:
|
|
1444
|
+
|
|
1445
|
+
- ``Cs()``
|
|
1446
|
+
- ``Bs().A()`` for every direct super category ``Bs()`` of ``Cs()``
|
|
1447
|
+
- the categories appearing in ``Cs().A_extra_super_categories()``
|
|
1448
|
+
|
|
1449
|
+
This is a highly recursive process. In fact, as such, it would run
|
|
1450
|
+
right away into an infinite loop! Indeed, the join of ``Cs()`` with
|
|
1451
|
+
``Bs().A()`` would trigger the construction of ``Cs().A()`` and
|
|
1452
|
+
reciprocally. To avoid this, the :meth:`Category.join` method itself
|
|
1453
|
+
does not use :meth:`Category._with_axiom` to add axioms, but its
|
|
1454
|
+
sister :meth:`Category._with_axiom_as_tuple`; the latter builds a
|
|
1455
|
+
tuple of categories that should be joined together but leaves the
|
|
1456
|
+
computation of the join to its caller, the master join calculation.
|
|
1457
|
+
|
|
1458
|
+
Adding an axiom ``A`` to a category ``Cs()`` implementing it
|
|
1459
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
1460
|
+
|
|
1461
|
+
In this case ``Cs().A()`` simply constructs an instance `D` of
|
|
1462
|
+
``Cs.A`` which models the desired category. The non trivial part is
|
|
1463
|
+
the construction of the super categories of `D`. Very much like
|
|
1464
|
+
above, this includes:
|
|
1465
|
+
|
|
1466
|
+
- ``Cs()``
|
|
1467
|
+
- ``Bs().A()`` for every super category ``Bs()`` of ``Cs()``
|
|
1468
|
+
- the categories appearing in ``D.extra_super_categories()``
|
|
1469
|
+
|
|
1470
|
+
This by itself may not be sufficient, due in particular to deduction
|
|
1471
|
+
rules. On may for example discover a new axiom ``A1`` satisfied by
|
|
1472
|
+
`D`, imposing to add ``A1`` to all of the above categories. Therefore
|
|
1473
|
+
the super categories are computed as the join of the above categories.
|
|
1474
|
+
Up to one twist: as is, the computation of this join would trigger
|
|
1475
|
+
recursively a recalculation of ``Cs().A()``! To avoid this,
|
|
1476
|
+
:meth:`Category.join` is given an optional argument to specify that
|
|
1477
|
+
the axiom ``A`` should *not* be applied to ``Cs()``.
|
|
1478
|
+
|
|
1479
|
+
Sketch of proof of correctness and evaluation of complexity
|
|
1480
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
1481
|
+
|
|
1482
|
+
As we have seen, this is a highly recursive process! In particular,
|
|
1483
|
+
one needs to argue that, as long as the specifications are satisfied,
|
|
1484
|
+
the algorithm won't run in an infinite recursion, in particular in
|
|
1485
|
+
case of deduction rule.
|
|
1486
|
+
|
|
1487
|
+
.. TOPIC:: Theorem
|
|
1488
|
+
|
|
1489
|
+
Consider the construction of a category `C` by adding an axiom to
|
|
1490
|
+
a category (or computing of a join). Let `H` be the hierarchy of
|
|
1491
|
+
implemented categories above `C`. Let `n` and `m` be respectively
|
|
1492
|
+
the number of categories and the number of inheritance edges in
|
|
1493
|
+
`H`.
|
|
1494
|
+
|
|
1495
|
+
Assuming that the specifications are satisfied, the construction
|
|
1496
|
+
of `C` involves constructing the categories in `H` exactly once
|
|
1497
|
+
(and no other category), and at most `n` join calculations. In
|
|
1498
|
+
particular, the time complexity should be, roughly speaking,
|
|
1499
|
+
bounded by `n^2`. In particular, it's finite.
|
|
1500
|
+
|
|
1501
|
+
.. TOPIC:: Remark
|
|
1502
|
+
|
|
1503
|
+
It's actually to be expected that the complexity is more of the
|
|
1504
|
+
order of magnitude of `na+m`, where `a` is the number of axioms
|
|
1505
|
+
satisfied by `C`. But this is to be checked in detail, in
|
|
1506
|
+
particular due to the many category inclusion tests involved.
|
|
1507
|
+
|
|
1508
|
+
The key argument is that :class:`Category.join` cannot call itself
|
|
1509
|
+
recursively without going through the construction of some implemented
|
|
1510
|
+
category. In turn, the construction of some implemented category `C`
|
|
1511
|
+
only involves constructing strictly smaller categories, and possibly a
|
|
1512
|
+
direct join calculation whose result is strictly smaller than
|
|
1513
|
+
`C`. This statement is obvious if `C` implements the
|
|
1514
|
+
``super_categories`` method directly, and easy to check for functorial
|
|
1515
|
+
construction categories. It requires a proof for categories with
|
|
1516
|
+
axioms since there is a recursive join involved.
|
|
1517
|
+
|
|
1518
|
+
.. TOPIC:: Lemma
|
|
1519
|
+
|
|
1520
|
+
Let `C` be a category implementing an axiom `A`. Recall that the
|
|
1521
|
+
construction of ``C.A()`` involves a single direct join
|
|
1522
|
+
calculation for computing the super categories. No other direct
|
|
1523
|
+
join calculation occur, and the calculation involves only
|
|
1524
|
+
implemented categories that are strictly smaller than ``C.A()``.
|
|
1525
|
+
|
|
1526
|
+
.. TOPIC:: Proof
|
|
1527
|
+
|
|
1528
|
+
Let `D` be a category involved in the join calculation for the
|
|
1529
|
+
super categories of ``C.A()``, and assume by induction that `D` is
|
|
1530
|
+
strictly smaller than ``C.A()``. A category `E` newly constructed
|
|
1531
|
+
from `D` can come from:
|
|
1532
|
+
|
|
1533
|
+
- ``D.(extra_)super_categories()``
|
|
1534
|
+
|
|
1535
|
+
In this case, the specifications impose that `E` should be
|
|
1536
|
+
strictly smaller than `D` and therefore strictly smaller than
|
|
1537
|
+
`C`.
|
|
1538
|
+
|
|
1539
|
+
- ``D.with_axiom_as_tuple('B')`` or ``D.B_extra_super_categories()``
|
|
1540
|
+
for some axiom `B`
|
|
1541
|
+
|
|
1542
|
+
In this case, the axiom `B` is satisfied by some subcategory of
|
|
1543
|
+
``C.A()``, and therefore must be satisfied by ``C.A()`` itself.
|
|
1544
|
+
Since adding an axiom is a regressive construction, `E` must be a
|
|
1545
|
+
subcategory of ``C.A()``. If there is equality, then `E` and
|
|
1546
|
+
``C.A()`` must have the same class, and therefore, `E` must be
|
|
1547
|
+
directly constructed as ``C.A()``. However the join construction
|
|
1548
|
+
explicitly prevents this call.
|
|
1549
|
+
|
|
1550
|
+
Note that a call to ``D.with_axiom_as_tuple('B')`` does not trigger
|
|
1551
|
+
a direct join calculation; but of course, if `D` implements `B`,
|
|
1552
|
+
the construction of the implemented category ``E = D.B()`` will
|
|
1553
|
+
involve a strictly smaller join calculation.
|
|
1554
|
+
|
|
1555
|
+
|
|
1556
|
+
Conclusion
|
|
1557
|
+
==========
|
|
1558
|
+
|
|
1559
|
+
This is the end of the axioms documentation. Congratulations on
|
|
1560
|
+
having read that far!
|
|
1561
|
+
|
|
1562
|
+
|
|
1563
|
+
Tests
|
|
1564
|
+
=====
|
|
1565
|
+
|
|
1566
|
+
.. NOTE::
|
|
1567
|
+
|
|
1568
|
+
Quite a few categories with axioms are constructed early on during
|
|
1569
|
+
Sage's startup. Therefore, when playing around with the
|
|
1570
|
+
implementation of the axiom infrastructure, it is easy to break
|
|
1571
|
+
Sage. The following sequence of tests is designed to test the
|
|
1572
|
+
infrastructure from the ground up even in a partially broken
|
|
1573
|
+
Sage. Please don't remove the imports!
|
|
1574
|
+
|
|
1575
|
+
TESTS:
|
|
1576
|
+
|
|
1577
|
+
::
|
|
1578
|
+
|
|
1579
|
+
sage: Magmas()
|
|
1580
|
+
Category of magmas
|
|
1581
|
+
sage: Magmas().Finite()
|
|
1582
|
+
Category of finite magmas
|
|
1583
|
+
|
|
1584
|
+
sage: Magmas().Unital()
|
|
1585
|
+
Category of unital magmas
|
|
1586
|
+
sage: Magmas().Commutative().Unital()
|
|
1587
|
+
Category of commutative unital magmas
|
|
1588
|
+
sage: Magmas().Associative()
|
|
1589
|
+
Category of semigroups
|
|
1590
|
+
sage: Magmas().Associative() & Magmas().Unital().Inverse() & Sets().Finite()
|
|
1591
|
+
Category of finite groups
|
|
1592
|
+
sage: _ is Groups().Finite()
|
|
1593
|
+
True
|
|
1594
|
+
|
|
1595
|
+
sage: from sage.categories.semigroups import Semigroups
|
|
1596
|
+
sage: Semigroups()
|
|
1597
|
+
Category of semigroups
|
|
1598
|
+
sage: Semigroups().Finite()
|
|
1599
|
+
Category of finite semigroups
|
|
1600
|
+
|
|
1601
|
+
sage: from sage.categories.modules_with_basis import ModulesWithBasis
|
|
1602
|
+
sage: ModulesWithBasis(QQ) is Modules(QQ).WithBasis()
|
|
1603
|
+
True
|
|
1604
|
+
sage: ModulesWithBasis(ZZ) is Modules(ZZ).WithBasis()
|
|
1605
|
+
True
|
|
1606
|
+
|
|
1607
|
+
sage: Semigroups().Unital()
|
|
1608
|
+
Category of monoids
|
|
1609
|
+
sage: Semigroups().Unital().Commutative()
|
|
1610
|
+
Category of commutative monoids
|
|
1611
|
+
sage: Semigroups().Commutative()
|
|
1612
|
+
Category of commutative semigroups
|
|
1613
|
+
sage: Semigroups().Commutative().Unital()
|
|
1614
|
+
Category of commutative monoids
|
|
1615
|
+
sage: Semigroups().Commutative().Unital().super_categories()
|
|
1616
|
+
[Category of monoids, Category of commutative magmas]
|
|
1617
|
+
|
|
1618
|
+
sage: AdditiveMagmas().AdditiveAssociative().AdditiveCommutative()
|
|
1619
|
+
Category of commutative additive semigroups
|
|
1620
|
+
|
|
1621
|
+
sage: from sage.categories.magmas_and_additive_magmas import MagmasAndAdditiveMagmas
|
|
1622
|
+
sage: C = CommutativeAdditiveMonoids() & Monoids() & MagmasAndAdditiveMagmas().Distributive(); C
|
|
1623
|
+
Category of semirings
|
|
1624
|
+
sage: C is (CommutativeAdditiveMonoids() & Monoids()).Distributive()
|
|
1625
|
+
True
|
|
1626
|
+
sage: C.AdditiveInverse()
|
|
1627
|
+
Category of rings
|
|
1628
|
+
sage: Rings().axioms()
|
|
1629
|
+
frozenset({'AdditiveAssociative',
|
|
1630
|
+
'AdditiveCommutative',
|
|
1631
|
+
'AdditiveInverse',
|
|
1632
|
+
'AdditiveUnital',
|
|
1633
|
+
'Associative',
|
|
1634
|
+
'Distributive',
|
|
1635
|
+
'Unital'})
|
|
1636
|
+
sage: sorted(Rings().axioms())
|
|
1637
|
+
['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse',
|
|
1638
|
+
'AdditiveUnital', 'Associative', 'Distributive', 'Unital']
|
|
1639
|
+
|
|
1640
|
+
sage: Domains().Commutative()
|
|
1641
|
+
Category of integral domains
|
|
1642
|
+
|
|
1643
|
+
sage: DivisionRings().Finite() # Wedderburn's theorem
|
|
1644
|
+
Category of finite enumerated fields
|
|
1645
|
+
|
|
1646
|
+
sage: FiniteMonoids().Algebras(QQ)
|
|
1647
|
+
Join of Category of monoid algebras over Rational Field
|
|
1648
|
+
and Category of finite dimensional algebras with basis over Rational Field
|
|
1649
|
+
and Category of finite set algebras over Rational Field
|
|
1650
|
+
sage: FiniteGroups().Algebras(QQ)
|
|
1651
|
+
Category of finite group algebras over Rational Field
|
|
1652
|
+
"""
|
|
1653
|
+
# ****************************************************************************
|
|
1654
|
+
# Copyright (C) 2011-2014 Nicolas M. Thiery <nthiery at users.sf.net>
|
|
1655
|
+
#
|
|
1656
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
1657
|
+
# https://www.gnu.org/licenses/
|
|
1658
|
+
# ****************************************************************************
|
|
1659
|
+
|
|
1660
|
+
import importlib
|
|
1661
|
+
import re
|
|
1662
|
+
from sage.misc.cachefunc import cached_method, cached_function
|
|
1663
|
+
from sage.misc.lazy_attribute import lazy_class_attribute
|
|
1664
|
+
from sage.misc.lazy_import import LazyImport
|
|
1665
|
+
from sage.misc.call import call_method
|
|
1666
|
+
from sage.categories.category import Category
|
|
1667
|
+
from sage.categories.category_singleton import Category_singleton
|
|
1668
|
+
from sage.categories.category_types import Category_over_base_ring
|
|
1669
|
+
from sage.structure.dynamic_class import DynamicMetaclass
|
|
1670
|
+
from sage.categories.category_cy_helper import AxiomContainer, canonicalize_axioms
|
|
1671
|
+
|
|
1672
|
+
# The order of the axioms in this lists implies that
|
|
1673
|
+
# Magmas().Commutative().Unital() is printed as
|
|
1674
|
+
# ``Category of commutative unital magmas''
|
|
1675
|
+
|
|
1676
|
+
all_axioms = AxiomContainer()
|
|
1677
|
+
all_axioms += ("Flying", "Blue",
|
|
1678
|
+
"Compact",
|
|
1679
|
+
"Differentiable", "Smooth", "Analytic", "AlmostComplex",
|
|
1680
|
+
"FinitelyGeneratedAsMagma",
|
|
1681
|
+
"WellGenerated",
|
|
1682
|
+
"Facade", "Finite", "Infinite","Enumerated",
|
|
1683
|
+
"Complete",
|
|
1684
|
+
"Nilpotent",
|
|
1685
|
+
"FiniteDimensional", "FinitelyPresented", "Connected",
|
|
1686
|
+
"FinitelyGeneratedAsLambdaBracketAlgebra",
|
|
1687
|
+
"WithBasis",
|
|
1688
|
+
"Irreducible",
|
|
1689
|
+
"Supercommutative", "Supercocommutative",
|
|
1690
|
+
"Commutative", "Cocommutative", "Associative", "Inverse", "Unital", "Division", "NoZeroDivisors", "Cellular",
|
|
1691
|
+
"AdditiveCommutative", "AdditiveAssociative", "AdditiveInverse", "AdditiveUnital",
|
|
1692
|
+
"Distributive",
|
|
1693
|
+
"Endset",
|
|
1694
|
+
"Pointed",
|
|
1695
|
+
"Stratified",
|
|
1696
|
+
)
|
|
1697
|
+
|
|
1698
|
+
|
|
1699
|
+
def uncamelcase(s, separator=" "):
|
|
1700
|
+
"""
|
|
1701
|
+
EXAMPLES::
|
|
1702
|
+
|
|
1703
|
+
sage: sage.categories.category_with_axiom.uncamelcase("FiniteDimensionalAlgebras")
|
|
1704
|
+
'finite dimensional algebras'
|
|
1705
|
+
sage: sage.categories.category_with_axiom.uncamelcase("JTrivialMonoids")
|
|
1706
|
+
'j trivial monoids'
|
|
1707
|
+
sage: sage.categories.category_with_axiom.uncamelcase("FiniteDimensionalAlgebras", "_")
|
|
1708
|
+
'finite_dimensional_algebras'
|
|
1709
|
+
"""
|
|
1710
|
+
return re.sub("(?!^)[A-Z]", lambda match: separator+match.group()[0], s).lower()
|
|
1711
|
+
|
|
1712
|
+
|
|
1713
|
+
def base_category_class_and_axiom(cls):
|
|
1714
|
+
"""
|
|
1715
|
+
Try to deduce the base category and the axiom from the name of ``cls``.
|
|
1716
|
+
|
|
1717
|
+
The heuristic is to try to decompose the name as the concatenation
|
|
1718
|
+
of the name of a category and the name of an axiom, and looking up
|
|
1719
|
+
that category in the standard location (i.e. in
|
|
1720
|
+
:mod:`sage.categories.hopf_algebras` for :class:`HopfAlgebras`,
|
|
1721
|
+
and in :mod:`sage.categories.sets_cat` as a special case
|
|
1722
|
+
for :class:`Sets`).
|
|
1723
|
+
|
|
1724
|
+
If the heuristic succeeds, the result is guaranteed to be
|
|
1725
|
+
correct. Otherwise, an error is raised.
|
|
1726
|
+
|
|
1727
|
+
EXAMPLES::
|
|
1728
|
+
|
|
1729
|
+
sage: from sage.categories.category_with_axiom import base_category_class_and_axiom, CategoryWithAxiom
|
|
1730
|
+
sage: base_category_class_and_axiom(FiniteSets)
|
|
1731
|
+
(<class 'sage.categories.sets_cat.Sets'>, 'Finite')
|
|
1732
|
+
sage: Sets.Finite
|
|
1733
|
+
<class 'sage.categories.finite_sets.FiniteSets'>
|
|
1734
|
+
sage: base_category_class_and_axiom(Sets.Finite)
|
|
1735
|
+
(<class 'sage.categories.sets_cat.Sets'>, 'Finite')
|
|
1736
|
+
|
|
1737
|
+
sage: base_category_class_and_axiom(FiniteDimensionalHopfAlgebrasWithBasis)
|
|
1738
|
+
(<class 'sage.categories.hopf_algebras_with_basis.HopfAlgebrasWithBasis'>,
|
|
1739
|
+
'FiniteDimensional')
|
|
1740
|
+
|
|
1741
|
+
sage: base_category_class_and_axiom(HopfAlgebrasWithBasis)
|
|
1742
|
+
(<class 'sage.categories.hopf_algebras.HopfAlgebras'>, 'WithBasis')
|
|
1743
|
+
|
|
1744
|
+
Along the way, this does some sanity checks::
|
|
1745
|
+
|
|
1746
|
+
sage: class FacadeSemigroups(CategoryWithAxiom):
|
|
1747
|
+
....: pass
|
|
1748
|
+
sage: base_category_class_and_axiom(FacadeSemigroups)
|
|
1749
|
+
Traceback (most recent call last):
|
|
1750
|
+
...
|
|
1751
|
+
AssertionError: Missing (lazy import) link
|
|
1752
|
+
for <class 'sage.categories.semigroups.Semigroups'>
|
|
1753
|
+
to <class '__main__.FacadeSemigroups'> for axiom Facade?
|
|
1754
|
+
|
|
1755
|
+
sage: Semigroups.Facade = FacadeSemigroups
|
|
1756
|
+
sage: base_category_class_and_axiom(FacadeSemigroups)
|
|
1757
|
+
(<class 'sage.categories.semigroups.Semigroups'>, 'Facade')
|
|
1758
|
+
|
|
1759
|
+
.. NOTE::
|
|
1760
|
+
|
|
1761
|
+
In the following example, we could possibly retrieve ``Sets``
|
|
1762
|
+
from the class name. However this cannot be implemented
|
|
1763
|
+
robustly until :issue:`9107` is fixed. Anyway this feature
|
|
1764
|
+
has not been needed so far::
|
|
1765
|
+
|
|
1766
|
+
sage: Sets.Infinite
|
|
1767
|
+
<class 'sage.categories.sets_cat.Sets.Infinite'>
|
|
1768
|
+
sage: base_category_class_and_axiom(Sets.Infinite)
|
|
1769
|
+
Traceback (most recent call last):
|
|
1770
|
+
...
|
|
1771
|
+
TypeError: Could not retrieve the base category class and axiom
|
|
1772
|
+
for <class 'sage.categories.sets_cat.Sets.Infinite'>.
|
|
1773
|
+
...
|
|
1774
|
+
"""
|
|
1775
|
+
if "." in cls.__name__:
|
|
1776
|
+
# Case 1: class name of the form Sets.Infinite
|
|
1777
|
+
# Start of implementation when #9107 will be fixed:
|
|
1778
|
+
# axiom = cls.__name__.split(".")[-1]
|
|
1779
|
+
# ...
|
|
1780
|
+
pass
|
|
1781
|
+
else:
|
|
1782
|
+
# Case 2: class name of the form FiniteSets or AlgebrasWithBasis,
|
|
1783
|
+
# with the base class (say Algebras) being implemented in the
|
|
1784
|
+
# standard location (sage.categories.algebras)
|
|
1785
|
+
name = cls.__name__
|
|
1786
|
+
for axiom in all_axioms:
|
|
1787
|
+
if axiom == "WithBasis" and name.endswith(axiom):
|
|
1788
|
+
base_name = name[:-len(axiom)]
|
|
1789
|
+
elif name.startswith(axiom):
|
|
1790
|
+
base_name = name[len(axiom):]
|
|
1791
|
+
else:
|
|
1792
|
+
continue
|
|
1793
|
+
if base_name == "Sets": # Special case for Sets which is in sets_cat
|
|
1794
|
+
base_module_name = "sets_cat"
|
|
1795
|
+
else:
|
|
1796
|
+
base_module_name = uncamelcase(base_name, "_")
|
|
1797
|
+
try:
|
|
1798
|
+
base_module = importlib.import_module("sage.categories."+base_module_name)
|
|
1799
|
+
base_category_class = getattr(base_module, base_name)
|
|
1800
|
+
assert getattr(base_category_class, axiom, None) is cls, \
|
|
1801
|
+
"Missing (lazy import) link for {} to {} for axiom {}?".format(base_category_class, cls, axiom)
|
|
1802
|
+
return base_category_class, axiom
|
|
1803
|
+
except (ImportError,AttributeError):
|
|
1804
|
+
pass
|
|
1805
|
+
raise TypeError("""Could not retrieve the base category class and axiom for {}.
|
|
1806
|
+
Please specify it explicitly using the attribute _base_category_class_and_axiom.
|
|
1807
|
+
See CategoryWithAxiom for details.""".format(cls))
|
|
1808
|
+
|
|
1809
|
+
|
|
1810
|
+
@cached_function
|
|
1811
|
+
def axiom_of_nested_class(cls, nested_cls):
|
|
1812
|
+
r"""
|
|
1813
|
+
Given a class and a nested axiom class, return the axiom.
|
|
1814
|
+
|
|
1815
|
+
EXAMPLES:
|
|
1816
|
+
|
|
1817
|
+
This uses some heuristics like checking if the nested_cls carries
|
|
1818
|
+
the name of the axiom, or is built by appending or prepending the
|
|
1819
|
+
name of the axiom to that of the class::
|
|
1820
|
+
|
|
1821
|
+
sage: from sage.categories.category_with_axiom import TestObjects, axiom_of_nested_class
|
|
1822
|
+
sage: axiom_of_nested_class(TestObjects, TestObjects.FiniteDimensional)
|
|
1823
|
+
'FiniteDimensional'
|
|
1824
|
+
sage: axiom_of_nested_class(TestObjects.FiniteDimensional,
|
|
1825
|
+
....: TestObjects.FiniteDimensional.Finite)
|
|
1826
|
+
'Finite'
|
|
1827
|
+
sage: axiom_of_nested_class(Sets, FiniteSets)
|
|
1828
|
+
'Finite'
|
|
1829
|
+
sage: axiom_of_nested_class(Algebras, AlgebrasWithBasis)
|
|
1830
|
+
'WithBasis'
|
|
1831
|
+
|
|
1832
|
+
In all other cases, the nested class should provide an attribute
|
|
1833
|
+
``_base_category_class_and_axiom``::
|
|
1834
|
+
|
|
1835
|
+
sage: Semigroups._base_category_class_and_axiom
|
|
1836
|
+
(<class 'sage.categories.magmas.Magmas'>, 'Associative')
|
|
1837
|
+
sage: axiom_of_nested_class(Magmas, Semigroups)
|
|
1838
|
+
'Associative'
|
|
1839
|
+
"""
|
|
1840
|
+
try:
|
|
1841
|
+
axiom = nested_cls.__dict__["_base_category_class_and_axiom"][1]
|
|
1842
|
+
except KeyError:
|
|
1843
|
+
assert not isinstance(cls, DynamicMetaclass)
|
|
1844
|
+
nested_cls_name = nested_cls.__name__.split(".")[-1]
|
|
1845
|
+
if nested_cls_name in all_axioms:
|
|
1846
|
+
axiom = nested_cls_name
|
|
1847
|
+
else:
|
|
1848
|
+
cls_name = cls.__name__.split(".")[-1]
|
|
1849
|
+
if nested_cls_name.startswith(cls_name):
|
|
1850
|
+
axiom = nested_cls_name[len(cls_name):]
|
|
1851
|
+
elif nested_cls_name.endswith(cls_name):
|
|
1852
|
+
axiom = nested_cls_name[:-len(cls_name)]
|
|
1853
|
+
else:
|
|
1854
|
+
raise ValueError("could not infer axiom for the nested class {} of {}".format(nested_cls, cls))
|
|
1855
|
+
assert axiom in all_axioms, \
|
|
1856
|
+
"Incorrect deduction ({}) for the name of the axiom for the nested class {} of {}".format(axiom, nested_cls, cls)
|
|
1857
|
+
assert axiom in cls.__dict__ and cls.__dict__[axiom] == nested_cls, \
|
|
1858
|
+
"{} not a nested axiom class of {} for axiom {}".format(nested_cls, cls, axiom)
|
|
1859
|
+
return axiom
|
|
1860
|
+
|
|
1861
|
+
|
|
1862
|
+
class CategoryWithAxiom(Category):
|
|
1863
|
+
r"""
|
|
1864
|
+
An abstract class for categories obtained by adding an axiom
|
|
1865
|
+
to a base category.
|
|
1866
|
+
|
|
1867
|
+
See the :mod:`category primer <sage.categories.primer>`, and in
|
|
1868
|
+
particular its :ref:`section about axioms <category-primer-axioms>`
|
|
1869
|
+
for an introduction to axioms, and :class:`CategoryWithAxiom` for
|
|
1870
|
+
how to implement axioms and the documentation of the axiom
|
|
1871
|
+
infrastructure.
|
|
1872
|
+
|
|
1873
|
+
.. automethod:: CategoryWithAxiom.__classcall__
|
|
1874
|
+
.. automethod:: CategoryWithAxiom.__classget__
|
|
1875
|
+
.. automethod:: CategoryWithAxiom.__init__
|
|
1876
|
+
.. automethod:: CategoryWithAxiom._repr_object_names
|
|
1877
|
+
.. automethod:: CategoryWithAxiom._repr_object_names_static
|
|
1878
|
+
.. automethod:: CategoryWithAxiom._test_category_with_axiom
|
|
1879
|
+
.. automethod:: CategoryWithAxiom._without_axioms
|
|
1880
|
+
"""
|
|
1881
|
+
|
|
1882
|
+
@lazy_class_attribute
|
|
1883
|
+
def _base_category_class_and_axiom(cls):
|
|
1884
|
+
r"""
|
|
1885
|
+
The class of the base category and the axiom for this class.
|
|
1886
|
+
|
|
1887
|
+
By default, and when possible, this attribute is deduced from
|
|
1888
|
+
the name of this class (see
|
|
1889
|
+
:func:`base_category_class_and_axiom`). For a nested class,
|
|
1890
|
+
when the category is first created from its base category as
|
|
1891
|
+
in e.g. ``Sets().Infinite()``, this attribute is instead set
|
|
1892
|
+
explicitly by :meth:`__classget__`.
|
|
1893
|
+
|
|
1894
|
+
When this is not sufficient, that is when ``cls`` is not
|
|
1895
|
+
implemented as a nested class and the base category and the
|
|
1896
|
+
axiom cannot be deduced from the name of ``cls``, this
|
|
1897
|
+
attribute should be set explicitly by ``cls``.
|
|
1898
|
+
|
|
1899
|
+
The origin of the attribute is stored in the attribute
|
|
1900
|
+
``_base_category_class_and_axiom_origin``.
|
|
1901
|
+
|
|
1902
|
+
.. SEEALSO:: :meth:`_axiom`
|
|
1903
|
+
|
|
1904
|
+
EXAMPLES:
|
|
1905
|
+
|
|
1906
|
+
``CommutativeRings`` is not a nested class, but the name of
|
|
1907
|
+
the base category and the axiom can be deduced::
|
|
1908
|
+
|
|
1909
|
+
sage: CommutativeRings()._base_category_class_and_axiom
|
|
1910
|
+
(<class 'sage.categories.rings.Rings'>, 'Commutative')
|
|
1911
|
+
sage: CommutativeRings()._base_category_class_and_axiom_origin
|
|
1912
|
+
'set by __classget__'
|
|
1913
|
+
|
|
1914
|
+
``Sets.Infinite`` is a nested class, so the attribute is set
|
|
1915
|
+
by :meth:`CategoryWithAxiom.__classget__` the first time
|
|
1916
|
+
``Sets().Infinite()`` is called::
|
|
1917
|
+
|
|
1918
|
+
sage: Sets().Infinite()
|
|
1919
|
+
Category of infinite sets
|
|
1920
|
+
sage: Sets.Infinite._base_category_class_and_axiom
|
|
1921
|
+
(<class 'sage.categories.sets_cat.Sets'>, 'Infinite')
|
|
1922
|
+
sage: Sets.Infinite._base_category_class_and_axiom_origin
|
|
1923
|
+
'set by __classget__'
|
|
1924
|
+
|
|
1925
|
+
``Fields`` is not a nested class, and the name of the base
|
|
1926
|
+
category and axioms cannot be deduced from the name
|
|
1927
|
+
``Fields``; so this attributes needs to be set explicitly in
|
|
1928
|
+
the ``Fields`` class::
|
|
1929
|
+
|
|
1930
|
+
sage: Fields()._base_category_class_and_axiom
|
|
1931
|
+
(<class 'sage.categories.division_rings.DivisionRings'>, 'Commutative')
|
|
1932
|
+
sage: Fields()._base_category_class_and_axiom_origin
|
|
1933
|
+
'hardcoded'
|
|
1934
|
+
|
|
1935
|
+
.. NOTE::
|
|
1936
|
+
|
|
1937
|
+
The base category class is often another category with
|
|
1938
|
+
axiom, therefore having a special ``__classget__`` method.
|
|
1939
|
+
Storing the base category class and the axiom in a single
|
|
1940
|
+
tuple attribute -- instead of two separate attributes --
|
|
1941
|
+
has the advantage of not triggering, for example,
|
|
1942
|
+
``Semigroups.__classget__`` upon
|
|
1943
|
+
``Monoids._base_category_class``.
|
|
1944
|
+
"""
|
|
1945
|
+
base_category_class, axiom = base_category_class_and_axiom(cls)
|
|
1946
|
+
cls._base_category_class_and_axiom_origin = "deduced by base_category_class_and_axiom"
|
|
1947
|
+
return (base_category_class, axiom)
|
|
1948
|
+
|
|
1949
|
+
_base_category_class_and_axiom_origin = "hardcoded"
|
|
1950
|
+
|
|
1951
|
+
@lazy_class_attribute
|
|
1952
|
+
def _axiom(cls):
|
|
1953
|
+
r"""
|
|
1954
|
+
The axiom for this category with axiom.
|
|
1955
|
+
|
|
1956
|
+
.. SEEALSO:: :meth:`_base_category_class_and_axiom`
|
|
1957
|
+
|
|
1958
|
+
EXAMPLES::
|
|
1959
|
+
|
|
1960
|
+
sage: FiniteSets._axiom
|
|
1961
|
+
'Finite'
|
|
1962
|
+
sage: Sets.Finite._axiom
|
|
1963
|
+
'Finite'
|
|
1964
|
+
sage: Algebras.Commutative._axiom
|
|
1965
|
+
'Commutative'
|
|
1966
|
+
|
|
1967
|
+
The result can be less obvious::
|
|
1968
|
+
|
|
1969
|
+
sage: Semigroups._axiom
|
|
1970
|
+
'Associative'
|
|
1971
|
+
sage: Rings._axiom
|
|
1972
|
+
'Unital'
|
|
1973
|
+
sage: Fields._axiom
|
|
1974
|
+
'Commutative'
|
|
1975
|
+
"""
|
|
1976
|
+
return cls._base_category_class_and_axiom[1]
|
|
1977
|
+
|
|
1978
|
+
@staticmethod
|
|
1979
|
+
def __classcall__(cls, *args, **options):
|
|
1980
|
+
"""
|
|
1981
|
+
Make ``FoosBar(**)`` an alias for ``Foos(**)._with_axiom("Bar")``.
|
|
1982
|
+
|
|
1983
|
+
EXAMPLES::
|
|
1984
|
+
|
|
1985
|
+
sage: FiniteGroups()
|
|
1986
|
+
Category of finite groups
|
|
1987
|
+
sage: ModulesWithBasis(ZZ)
|
|
1988
|
+
Category of modules with basis over Integer Ring
|
|
1989
|
+
sage: AlgebrasWithBasis(QQ)
|
|
1990
|
+
Category of algebras with basis over Rational Field
|
|
1991
|
+
|
|
1992
|
+
This is relevant when e.g. ``Foos(**)`` does some non trivial
|
|
1993
|
+
transformations::
|
|
1994
|
+
|
|
1995
|
+
sage: Modules(QQ) is VectorSpaces(QQ)
|
|
1996
|
+
True
|
|
1997
|
+
sage: type(Modules(QQ))
|
|
1998
|
+
<class 'sage.categories.vector_spaces.VectorSpaces_with_category'>
|
|
1999
|
+
|
|
2000
|
+
sage: ModulesWithBasis(QQ) is VectorSpaces(QQ).WithBasis()
|
|
2001
|
+
True
|
|
2002
|
+
sage: type(ModulesWithBasis(QQ))
|
|
2003
|
+
<class 'sage.categories.vector_spaces.VectorSpaces.WithBasis_with_category'>
|
|
2004
|
+
"""
|
|
2005
|
+
(base_category_class, axiom) = cls._base_category_class_and_axiom
|
|
2006
|
+
if len(args) == 1 and not options and isinstance(args[0], base_category_class):
|
|
2007
|
+
return super().__classcall__(cls, args[0])
|
|
2008
|
+
else:
|
|
2009
|
+
# The "obvious" idiom
|
|
2010
|
+
## return cls(base_category_class(*args, **options))
|
|
2011
|
+
# fails with ModulesWithBasis(QQ) as follows: The
|
|
2012
|
+
# base_category_class is Modules, but Modules(QQ) is an instance
|
|
2013
|
+
# of VectorSpaces and not of Modules. Hence,
|
|
2014
|
+
# ModulesWithBasis.__classcall__ will not accept this instance as
|
|
2015
|
+
# the first argument. Instead, we apply the axiom to the instance:
|
|
2016
|
+
return base_category_class(*args, **options)._with_axiom(axiom)
|
|
2017
|
+
|
|
2018
|
+
@staticmethod
|
|
2019
|
+
def __classget__(cls, base_category, base_category_class):
|
|
2020
|
+
r"""
|
|
2021
|
+
Implement the binding behavior for categories with axioms.
|
|
2022
|
+
|
|
2023
|
+
This method implements a binding behavior on category with
|
|
2024
|
+
axioms so that, when a category ``Cs`` implements an axiom
|
|
2025
|
+
``A`` with a nested class ``Cs.A``, the expression ``Cs().A``
|
|
2026
|
+
evaluates to the method defining the axiom ``A`` and not the
|
|
2027
|
+
nested class. See `those design notes
|
|
2028
|
+
<category-with-axiom-design>`_ for the rationale behind this
|
|
2029
|
+
behavior.
|
|
2030
|
+
|
|
2031
|
+
EXAMPLES::
|
|
2032
|
+
|
|
2033
|
+
sage: Sets().Infinite()
|
|
2034
|
+
Category of infinite sets
|
|
2035
|
+
sage: Sets().Infinite
|
|
2036
|
+
Cached version of <function ...Infinite at ...>
|
|
2037
|
+
sage: Sets().Infinite.f == Sets.SubcategoryMethods.Infinite.f
|
|
2038
|
+
True
|
|
2039
|
+
|
|
2040
|
+
We check that this also works when the class is implemented in
|
|
2041
|
+
a separate file, and lazy imported::
|
|
2042
|
+
|
|
2043
|
+
sage: Sets().Finite
|
|
2044
|
+
Cached version of <function ...Finite at ...>
|
|
2045
|
+
|
|
2046
|
+
There is no binding behavior when accessing ``Finite`` or
|
|
2047
|
+
``Infinite`` from the class of the category instead of the
|
|
2048
|
+
category itself::
|
|
2049
|
+
|
|
2050
|
+
sage: Sets.Finite
|
|
2051
|
+
<class 'sage.categories.finite_sets.FiniteSets'>
|
|
2052
|
+
sage: Sets.Infinite
|
|
2053
|
+
<class 'sage.categories.sets_cat.Sets.Infinite'>
|
|
2054
|
+
|
|
2055
|
+
This method also initializes the attribute
|
|
2056
|
+
``_base_category_class_and_axiom`` if not already set::
|
|
2057
|
+
|
|
2058
|
+
sage: Sets.Infinite._base_category_class_and_axiom
|
|
2059
|
+
(<class 'sage.categories.sets_cat.Sets'>, 'Infinite')
|
|
2060
|
+
sage: Sets.Infinite._base_category_class_and_axiom_origin
|
|
2061
|
+
'set by __classget__'
|
|
2062
|
+
"""
|
|
2063
|
+
# TODO: this is super paranoid; see if this can be simplified a bit
|
|
2064
|
+
if base_category is not None:
|
|
2065
|
+
assert base_category.__class__ is base_category_class
|
|
2066
|
+
assert isinstance(base_category_class, DynamicMetaclass)
|
|
2067
|
+
if isinstance(base_category_class, DynamicMetaclass):
|
|
2068
|
+
base_category_class = base_category_class.__base__
|
|
2069
|
+
if "_base_category_class_and_axiom" not in cls.__dict__:
|
|
2070
|
+
cls._base_category_class_and_axiom = (base_category_class, axiom_of_nested_class(base_category_class, cls))
|
|
2071
|
+
cls._base_category_class_and_axiom_origin = "set by __classget__"
|
|
2072
|
+
else:
|
|
2073
|
+
assert cls._base_category_class_and_axiom[0] is base_category_class, \
|
|
2074
|
+
"base category class for {} mismatch; expected {}, got {}".format(
|
|
2075
|
+
cls, cls._base_category_class_and_axiom[0], base_category_class)
|
|
2076
|
+
|
|
2077
|
+
# Workaround #15648: if Rings.Finite is a LazyImport object,
|
|
2078
|
+
# this forces the substitution of the object back into Rings
|
|
2079
|
+
# to avoid resolving the lazy import over and over
|
|
2080
|
+
if isinstance(base_category_class.__dict__[cls._axiom], LazyImport):
|
|
2081
|
+
setattr(base_category_class, cls._axiom, cls)
|
|
2082
|
+
|
|
2083
|
+
if base_category is None:
|
|
2084
|
+
return cls
|
|
2085
|
+
# For Rings().Finite, this returns the method
|
|
2086
|
+
# Sets.SubcategoryMethods.Finite, with its first argument bound to Rings()
|
|
2087
|
+
return getattr(super(base_category.__class__.__base__, base_category), cls._axiom)
|
|
2088
|
+
|
|
2089
|
+
def __init__(self, base_category):
|
|
2090
|
+
"""
|
|
2091
|
+
TESTS::
|
|
2092
|
+
|
|
2093
|
+
sage: C = Sets.Finite(); C
|
|
2094
|
+
Category of finite sets
|
|
2095
|
+
sage: type(C)
|
|
2096
|
+
<class 'sage.categories.finite_sets.FiniteSets_with_category'>
|
|
2097
|
+
sage: type(C).__base__.__base__
|
|
2098
|
+
<class 'sage.categories.category_with_axiom.CategoryWithAxiom_singleton'>
|
|
2099
|
+
|
|
2100
|
+
sage: TestSuite(C).run()
|
|
2101
|
+
"""
|
|
2102
|
+
# A hack to upgrade axiom categories of singleton categories
|
|
2103
|
+
# to be singleton categories themselves
|
|
2104
|
+
if isinstance(base_category, Category_singleton) and not isinstance(self, CategoryWithAxiom_singleton):
|
|
2105
|
+
cls = self.__class__
|
|
2106
|
+
assert cls.__base__ == CategoryWithAxiom
|
|
2107
|
+
cls.__bases__ = (CategoryWithAxiom_singleton,)+cls.__bases__[1:]
|
|
2108
|
+
|
|
2109
|
+
self._base_category = base_category
|
|
2110
|
+
Category.__init__(self)
|
|
2111
|
+
|
|
2112
|
+
def _test_category_with_axiom(self, **options):
|
|
2113
|
+
r"""
|
|
2114
|
+
Run generic tests on this category with axioms.
|
|
2115
|
+
|
|
2116
|
+
.. SEEALSO:: :class:`TestSuite`.
|
|
2117
|
+
|
|
2118
|
+
This check that an axiom category of a
|
|
2119
|
+
:class:`Category_singleton` is a singleton category, and
|
|
2120
|
+
similarwise for :class:`Category_over_base_ring`.
|
|
2121
|
+
|
|
2122
|
+
EXAMPLES::
|
|
2123
|
+
|
|
2124
|
+
sage: Sets().Finite()._test_category_with_axiom()
|
|
2125
|
+
sage: Modules(ZZ).FiniteDimensional()._test_category_with_axiom()
|
|
2126
|
+
"""
|
|
2127
|
+
tester = self._tester(**options)
|
|
2128
|
+
base = self.base_category()
|
|
2129
|
+
if isinstance(base, Category_singleton):
|
|
2130
|
+
tester.assertIsInstance(self, CategoryWithAxiom_singleton)
|
|
2131
|
+
if isinstance(base, Category_over_base_ring):
|
|
2132
|
+
tester.assertIsInstance(self, CategoryWithAxiom_over_base_ring)
|
|
2133
|
+
|
|
2134
|
+
def extra_super_categories(self):
|
|
2135
|
+
"""
|
|
2136
|
+
Return the extra super categories of a category with axiom.
|
|
2137
|
+
|
|
2138
|
+
Default implementation which returns ``[]``.
|
|
2139
|
+
|
|
2140
|
+
EXAMPLES::
|
|
2141
|
+
|
|
2142
|
+
sage: FiniteSets().extra_super_categories()
|
|
2143
|
+
[]
|
|
2144
|
+
"""
|
|
2145
|
+
return []
|
|
2146
|
+
|
|
2147
|
+
@cached_method
|
|
2148
|
+
def super_categories(self):
|
|
2149
|
+
"""
|
|
2150
|
+
Return a list of the (immediate) super categories of
|
|
2151
|
+
``self``, as per :meth:`Category.super_categories`.
|
|
2152
|
+
|
|
2153
|
+
This implements the property that if ``As`` is a subcategory
|
|
2154
|
+
of ``Bs``, then the intersection of ``As`` with ``FiniteSets()``
|
|
2155
|
+
is a subcategory of ``As`` and of the intersection of ``Bs``
|
|
2156
|
+
with ``FiniteSets()``.
|
|
2157
|
+
|
|
2158
|
+
EXAMPLES:
|
|
2159
|
+
|
|
2160
|
+
A finite magma is both a magma and a finite set::
|
|
2161
|
+
|
|
2162
|
+
sage: Magmas().Finite().super_categories()
|
|
2163
|
+
[Category of magmas, Category of finite sets]
|
|
2164
|
+
|
|
2165
|
+
Variants::
|
|
2166
|
+
|
|
2167
|
+
sage: Sets().Finite().super_categories()
|
|
2168
|
+
[Category of sets]
|
|
2169
|
+
|
|
2170
|
+
sage: Monoids().Finite().super_categories()
|
|
2171
|
+
[Category of monoids, Category of finite semigroups]
|
|
2172
|
+
|
|
2173
|
+
EXAMPLES:
|
|
2174
|
+
|
|
2175
|
+
TESTS::
|
|
2176
|
+
|
|
2177
|
+
sage: from sage.categories.category_with_axiom import TestObjects
|
|
2178
|
+
sage: C = TestObjects().FiniteDimensional().Unital().Commutative().Finite()
|
|
2179
|
+
sage: sorted(C.super_categories(), key=str)
|
|
2180
|
+
[Category of finite commutative test objects,
|
|
2181
|
+
Category of finite dimensional commutative unital test objects,
|
|
2182
|
+
Category of finite finite dimensional test objects]
|
|
2183
|
+
"""
|
|
2184
|
+
base_category = self._base_category
|
|
2185
|
+
axiom = self._axiom
|
|
2186
|
+
return Category.join((base_category,) +
|
|
2187
|
+
tuple(cat
|
|
2188
|
+
for category in base_category._super_categories
|
|
2189
|
+
for cat in category._with_axiom_as_tuple(axiom)) +
|
|
2190
|
+
tuple(self.extra_super_categories()),
|
|
2191
|
+
ignore_axioms=((base_category, axiom),),
|
|
2192
|
+
as_list=True)
|
|
2193
|
+
|
|
2194
|
+
def additional_structure(self):
|
|
2195
|
+
r"""
|
|
2196
|
+
Return the additional structure defined by ``self``.
|
|
2197
|
+
|
|
2198
|
+
OUTPUT: ``None``
|
|
2199
|
+
|
|
2200
|
+
By default, a category with axiom defines no additional
|
|
2201
|
+
structure.
|
|
2202
|
+
|
|
2203
|
+
.. SEEALSO:: :meth:`Category.additional_structure`.
|
|
2204
|
+
|
|
2205
|
+
EXAMPLES::
|
|
2206
|
+
|
|
2207
|
+
sage: Sets().Finite().additional_structure()
|
|
2208
|
+
sage: Monoids().additional_structure()
|
|
2209
|
+
|
|
2210
|
+
TESTS::
|
|
2211
|
+
|
|
2212
|
+
sage: Sets().Finite().additional_structure.__module__
|
|
2213
|
+
'sage.categories.category_with_axiom'
|
|
2214
|
+
"""
|
|
2215
|
+
return None
|
|
2216
|
+
|
|
2217
|
+
@staticmethod
|
|
2218
|
+
def _repr_object_names_static(category, axioms):
|
|
2219
|
+
r"""
|
|
2220
|
+
INPUT:
|
|
2221
|
+
|
|
2222
|
+
- ``base_category`` -- a category
|
|
2223
|
+
- ``axioms`` -- list or iterable of strings
|
|
2224
|
+
|
|
2225
|
+
EXAMPLES::
|
|
2226
|
+
|
|
2227
|
+
sage: from sage.categories.category_with_axiom import CategoryWithAxiom
|
|
2228
|
+
sage: CategoryWithAxiom._repr_object_names_static(Semigroups(), ["Flying", "Blue"])
|
|
2229
|
+
'flying blue semigroups'
|
|
2230
|
+
sage: CategoryWithAxiom._repr_object_names_static(Algebras(QQ), ["Flying", "WithBasis", "Blue"])
|
|
2231
|
+
'flying blue algebras with basis over Rational Field'
|
|
2232
|
+
sage: CategoryWithAxiom._repr_object_names_static(Algebras(QQ), ["WithBasis"])
|
|
2233
|
+
'algebras with basis over Rational Field'
|
|
2234
|
+
sage: CategoryWithAxiom._repr_object_names_static(Sets().Finite().Subquotients(), ["Finite"])
|
|
2235
|
+
'subquotients of finite sets'
|
|
2236
|
+
sage: CategoryWithAxiom._repr_object_names_static(Monoids(), ["Unital"])
|
|
2237
|
+
'monoids'
|
|
2238
|
+
sage: CategoryWithAxiom._repr_object_names_static(Algebras(QQ['x']['y']), ["Flying", "WithBasis", "Blue"])
|
|
2239
|
+
'flying blue algebras with basis over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field'
|
|
2240
|
+
|
|
2241
|
+
If the axioms is a set or frozen set, then they are first
|
|
2242
|
+
sorted using :func:`canonicalize_axioms`::
|
|
2243
|
+
|
|
2244
|
+
sage: CategoryWithAxiom._repr_object_names_static(Semigroups(), set(["Finite", "Commutative", "Facade"]))
|
|
2245
|
+
'facade finite commutative semigroups'
|
|
2246
|
+
|
|
2247
|
+
.. SEEALSO:: :meth:`_repr_object_names`
|
|
2248
|
+
|
|
2249
|
+
.. NOTE::
|
|
2250
|
+
|
|
2251
|
+
The logic here is shared between :meth:`_repr_object_names`
|
|
2252
|
+
and :meth:`.category.JoinCategory._repr_object_names`
|
|
2253
|
+
|
|
2254
|
+
TESTS::
|
|
2255
|
+
|
|
2256
|
+
sage: from sage.categories.homsets import Homsets
|
|
2257
|
+
sage: CategoryWithAxiom._repr_object_names_static(Homsets(), ["Endset"])
|
|
2258
|
+
'endsets'
|
|
2259
|
+
sage: CategoryWithAxiom._repr_object_names_static(PermutationGroups(), ["FinitelyGeneratedAsMagma"])
|
|
2260
|
+
'finitely generated permutation groups'
|
|
2261
|
+
sage: CategoryWithAxiom._repr_object_names_static(Rings(), ["FinitelyGeneratedAsMagma"])
|
|
2262
|
+
'finitely generated as magma rings'
|
|
2263
|
+
"""
|
|
2264
|
+
from sage.categories.additive_magmas import AdditiveMagmas
|
|
2265
|
+
axioms = canonicalize_axioms(all_axioms,axioms)
|
|
2266
|
+
base_category = category._without_axioms(named=True)
|
|
2267
|
+
if isinstance(base_category, CategoryWithAxiom): # Smelly runtime type checking
|
|
2268
|
+
result = super(CategoryWithAxiom, base_category)._repr_object_names()
|
|
2269
|
+
else:
|
|
2270
|
+
result = base_category._repr_object_names()
|
|
2271
|
+
for axiom in reversed(axioms):
|
|
2272
|
+
# TODO: find a more generic way to handle the special cases below
|
|
2273
|
+
if axiom in base_category.axioms():
|
|
2274
|
+
# If the base category already has this axiom, we
|
|
2275
|
+
# need not repeat it here. See the example with
|
|
2276
|
+
# Sets().Finite().Subquotients() or Monoids()
|
|
2277
|
+
continue
|
|
2278
|
+
base_category = base_category._with_axiom(axiom)
|
|
2279
|
+
if axiom == "WithBasis":
|
|
2280
|
+
result = result.replace(" over ", " with basis over ", 1)
|
|
2281
|
+
elif axiom == "Connected" and "graded " in result:
|
|
2282
|
+
result = result.replace("graded ", "graded connected ", 1)
|
|
2283
|
+
elif axiom == "Connected" and "filtered " in result:
|
|
2284
|
+
result = result.replace("filtered ", "filtered connected ", 1)
|
|
2285
|
+
elif axiom == "Stratified" and "graded " in result:
|
|
2286
|
+
result = result.replace("graded ", "stratified ", 1)
|
|
2287
|
+
elif axiom == "Nilpotent" and "finite dimensional " in result:
|
|
2288
|
+
# We need to put nilpotent before finite dimensional in the
|
|
2289
|
+
# axioms ordering so we do not (unnecessarily) display
|
|
2290
|
+
# 'nilpotent' in 'finite dimensional nilpotent stratified'.
|
|
2291
|
+
# So we need to swap the order here.
|
|
2292
|
+
result = result.replace("finite dimensional ", "finite dimensional nilpotent ", 1)
|
|
2293
|
+
elif axiom == "Endset" and "homsets" in result:
|
|
2294
|
+
# Without the space at the end to handle Homsets().Endset()
|
|
2295
|
+
result = result.replace("homsets", "endsets", 1)
|
|
2296
|
+
elif axiom == "FinitelyGeneratedAsMagma" and \
|
|
2297
|
+
not base_category.is_subcategory(AdditiveMagmas()):
|
|
2298
|
+
result = "finitely generated " + result
|
|
2299
|
+
elif axiom == "FinitelyGeneratedAsLambdaBracketAlgebra":
|
|
2300
|
+
result = "finitely generated " + result
|
|
2301
|
+
else:
|
|
2302
|
+
result = uncamelcase(axiom) + " " + result
|
|
2303
|
+
return result
|
|
2304
|
+
|
|
2305
|
+
def _repr_object_names(self):
|
|
2306
|
+
r"""
|
|
2307
|
+
The names of the objects of this category, as used by ``_repr_``.
|
|
2308
|
+
|
|
2309
|
+
.. SEEALSO:: :meth:`Category._repr_object_names`
|
|
2310
|
+
|
|
2311
|
+
EXAMPLES::
|
|
2312
|
+
|
|
2313
|
+
sage: FiniteSets()._repr_object_names()
|
|
2314
|
+
'finite sets'
|
|
2315
|
+
sage: AlgebrasWithBasis(QQ).FiniteDimensional()._repr_object_names()
|
|
2316
|
+
'finite dimensional algebras with basis over Rational Field'
|
|
2317
|
+
sage: Monoids()._repr_object_names()
|
|
2318
|
+
'monoids'
|
|
2319
|
+
sage: Semigroups().Unital().Finite()._repr_object_names()
|
|
2320
|
+
'finite monoids'
|
|
2321
|
+
sage: Algebras(QQ).Commutative()._repr_object_names()
|
|
2322
|
+
'commutative algebras over Rational Field'
|
|
2323
|
+
|
|
2324
|
+
.. NOTE::
|
|
2325
|
+
|
|
2326
|
+
This is implemented by taking _repr_object_names from
|
|
2327
|
+
self._without_axioms(named=True), and adding the names
|
|
2328
|
+
of the relevant axioms in appropriate order.
|
|
2329
|
+
"""
|
|
2330
|
+
return CategoryWithAxiom._repr_object_names_static(self, self.axioms())
|
|
2331
|
+
|
|
2332
|
+
def base_category(self):
|
|
2333
|
+
r"""
|
|
2334
|
+
Return the base category of ``self``.
|
|
2335
|
+
|
|
2336
|
+
EXAMPLES::
|
|
2337
|
+
|
|
2338
|
+
sage: C = Sets.Finite(); C
|
|
2339
|
+
Category of finite sets
|
|
2340
|
+
sage: C.base_category()
|
|
2341
|
+
Category of sets
|
|
2342
|
+
sage: C._without_axioms()
|
|
2343
|
+
Category of sets
|
|
2344
|
+
|
|
2345
|
+
TESTS::
|
|
2346
|
+
|
|
2347
|
+
sage: from sage.categories.category_with_axiom import TestObjects, CategoryWithAxiom
|
|
2348
|
+
sage: C = TestObjects().Commutative().Facade()
|
|
2349
|
+
sage: assert isinstance(C, CategoryWithAxiom)
|
|
2350
|
+
sage: C._without_axioms()
|
|
2351
|
+
Category of test objects
|
|
2352
|
+
"""
|
|
2353
|
+
return self._base_category
|
|
2354
|
+
|
|
2355
|
+
def __reduce__(self):
|
|
2356
|
+
r"""
|
|
2357
|
+
Implement the pickle protocol.
|
|
2358
|
+
|
|
2359
|
+
This overrides the implementation in
|
|
2360
|
+
:meth:`UniqueRepresentation.__reduce__` in order to not
|
|
2361
|
+
exposes the implementation detail that, for example, the
|
|
2362
|
+
category of magmas which distribute over an associative
|
|
2363
|
+
additive magma is implemented as
|
|
2364
|
+
``MagmasAndAdditiveMagmas.Distributive.AdditiveAssociative.AdditiveCommutative``
|
|
2365
|
+
and not
|
|
2366
|
+
``MagmasAndAdditiveMagmas.Distributive.AdditiveCommutative.AdditiveAssociative``.
|
|
2367
|
+
|
|
2368
|
+
EXAMPLES::
|
|
2369
|
+
|
|
2370
|
+
sage: C = Semigroups()
|
|
2371
|
+
sage: reduction = C.__reduce__(); reduction
|
|
2372
|
+
(<function call_method at ...>, (Category of magmas, '_with_axiom', 'Associative'))
|
|
2373
|
+
sage: loads(dumps(C)) is C
|
|
2374
|
+
True
|
|
2375
|
+
sage: FiniteSets().__reduce__()
|
|
2376
|
+
(<function call_method at ...>, (Category of sets, '_with_axiom', 'Finite'))
|
|
2377
|
+
|
|
2378
|
+
sage: from sage.categories.magmas_and_additive_magmas import MagmasAndAdditiveMagmas
|
|
2379
|
+
sage: C = MagmasAndAdditiveMagmas().Distributive().AdditiveAssociative().AdditiveCommutative()
|
|
2380
|
+
sage: C.__class__
|
|
2381
|
+
<class 'sage.categories.distributive_magmas_and_additive_magmas.DistributiveMagmasAndAdditiveMagmas.AdditiveAssociative.AdditiveCommutative_with_category'>
|
|
2382
|
+
sage: C.__reduce__()
|
|
2383
|
+
(<function call_method at ...>, (Category of additive associative distributive magmas and additive magmas, '_with_axiom', 'AdditiveCommutative'))
|
|
2384
|
+
"""
|
|
2385
|
+
return (call_method, (self._base_category, "_with_axiom", self._axiom))
|
|
2386
|
+
|
|
2387
|
+
@cached_method
|
|
2388
|
+
def _without_axiom(self, axiom):
|
|
2389
|
+
r"""
|
|
2390
|
+
Return this category, with axiom ``axiom`` removed.
|
|
2391
|
+
|
|
2392
|
+
OUTPUT:
|
|
2393
|
+
|
|
2394
|
+
A category ``C`` which does not have axiom ``axiom`` and such
|
|
2395
|
+
that either ``C`` is ``self``, or adding back all the axioms
|
|
2396
|
+
of ``self`` gives back ``self``.
|
|
2397
|
+
|
|
2398
|
+
.. SEEALSO:: :meth:`Category._without_axiom`
|
|
2399
|
+
|
|
2400
|
+
.. WARNING:: This is not guaranteed to be robust.
|
|
2401
|
+
|
|
2402
|
+
EXAMPLES::
|
|
2403
|
+
|
|
2404
|
+
sage: Groups()._without_axiom("Unital")
|
|
2405
|
+
Category of semigroups
|
|
2406
|
+
sage: Groups()._without_axiom("Associative")
|
|
2407
|
+
Category of inverse unital magmas
|
|
2408
|
+
sage: Groups().Commutative()._without_axiom("Unital")
|
|
2409
|
+
Category of commutative semigroups
|
|
2410
|
+
"""
|
|
2411
|
+
axioms = self.axioms().difference([axiom])
|
|
2412
|
+
return self._without_axioms()._with_axioms(axioms)
|
|
2413
|
+
|
|
2414
|
+
@cached_method
|
|
2415
|
+
def _without_axioms(self, named=False):
|
|
2416
|
+
"""
|
|
2417
|
+
Return the category without the axioms that have been
|
|
2418
|
+
added to create it.
|
|
2419
|
+
|
|
2420
|
+
EXAMPLES::
|
|
2421
|
+
|
|
2422
|
+
sage: Sets().Finite()._without_axioms()
|
|
2423
|
+
Category of sets
|
|
2424
|
+
sage: Monoids().Finite()._without_axioms()
|
|
2425
|
+
Category of magmas
|
|
2426
|
+
|
|
2427
|
+
This is because::
|
|
2428
|
+
|
|
2429
|
+
sage: Semigroups().Unital() is Monoids()
|
|
2430
|
+
True
|
|
2431
|
+
|
|
2432
|
+
If ``named`` is ``True``, then ``_without_axioms`` stops at the
|
|
2433
|
+
first category that has an explicit name of its own::
|
|
2434
|
+
|
|
2435
|
+
sage: Sets().Finite()._without_axioms(named=True)
|
|
2436
|
+
Category of sets
|
|
2437
|
+
sage: Monoids().Finite()._without_axioms(named=True)
|
|
2438
|
+
Category of monoids
|
|
2439
|
+
|
|
2440
|
+
Technically we test this by checking if the class specifies
|
|
2441
|
+
explicitly the attribute ``_base_category_class_and_axiom``
|
|
2442
|
+
by looking up ``_base_category_class_and_axiom_origin``.
|
|
2443
|
+
|
|
2444
|
+
Some more examples::
|
|
2445
|
+
|
|
2446
|
+
sage: Algebras(QQ).Commutative()._without_axioms()
|
|
2447
|
+
Category of magmatic algebras over Rational Field
|
|
2448
|
+
sage: Algebras(QQ).Commutative()._without_axioms(named=True)
|
|
2449
|
+
Category of algebras over Rational Field
|
|
2450
|
+
"""
|
|
2451
|
+
if named and self._base_category_class_and_axiom_origin == "hardcoded":
|
|
2452
|
+
return self
|
|
2453
|
+
return self._base_category._without_axioms(named=named)
|
|
2454
|
+
|
|
2455
|
+
@cached_method
|
|
2456
|
+
def axioms(self):
|
|
2457
|
+
r"""
|
|
2458
|
+
Return the axioms known to be satisfied by all the
|
|
2459
|
+
objects of ``self``.
|
|
2460
|
+
|
|
2461
|
+
.. SEEALSO:: :meth:`Category.axioms`
|
|
2462
|
+
|
|
2463
|
+
EXAMPLES::
|
|
2464
|
+
|
|
2465
|
+
sage: C = Sets.Finite(); C
|
|
2466
|
+
Category of finite sets
|
|
2467
|
+
sage: C.axioms()
|
|
2468
|
+
frozenset({'Finite'})
|
|
2469
|
+
|
|
2470
|
+
sage: C = Modules(GF(5)).FiniteDimensional(); C
|
|
2471
|
+
Category of finite dimensional vector spaces over Finite Field of size 5
|
|
2472
|
+
sage: sorted(C.axioms())
|
|
2473
|
+
['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse',
|
|
2474
|
+
'AdditiveUnital', 'Finite', 'FiniteDimensional']
|
|
2475
|
+
|
|
2476
|
+
sage: sorted(FiniteMonoids().Algebras(QQ).axioms())
|
|
2477
|
+
['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse',
|
|
2478
|
+
'AdditiveUnital', 'Associative', 'Distributive',
|
|
2479
|
+
'FiniteDimensional', 'Unital', 'WithBasis']
|
|
2480
|
+
sage: sorted(FiniteMonoids().Algebras(GF(3)).axioms())
|
|
2481
|
+
['AdditiveAssociative', 'AdditiveCommutative', 'AdditiveInverse',
|
|
2482
|
+
'AdditiveUnital', 'Associative', 'Distributive', 'Finite',
|
|
2483
|
+
'FiniteDimensional', 'Unital', 'WithBasis']
|
|
2484
|
+
|
|
2485
|
+
sage: from sage.categories.magmas_and_additive_magmas import MagmasAndAdditiveMagmas
|
|
2486
|
+
sage: MagmasAndAdditiveMagmas().Distributive().Unital().axioms()
|
|
2487
|
+
frozenset({'Distributive', 'Unital'})
|
|
2488
|
+
|
|
2489
|
+
sage: D = MagmasAndAdditiveMagmas().Distributive()
|
|
2490
|
+
sage: X = D.AdditiveAssociative().AdditiveCommutative().Associative()
|
|
2491
|
+
sage: X.Unital().super_categories()[1]
|
|
2492
|
+
Category of monoids
|
|
2493
|
+
sage: X.Unital().super_categories()[1] is Monoids()
|
|
2494
|
+
True
|
|
2495
|
+
"""
|
|
2496
|
+
# We would want to write the following line:
|
|
2497
|
+
# return super(CategoryWithAxiom, self).axioms() | {self._axiom}
|
|
2498
|
+
# However one currently can't use super to call a cached
|
|
2499
|
+
# method in a super class. So we dup the code from there ...
|
|
2500
|
+
return frozenset(axiom
|
|
2501
|
+
for category in self._super_categories
|
|
2502
|
+
for axiom in category.axioms()) | {self._axiom}
|
|
2503
|
+
|
|
2504
|
+
def _lean_init_(self):
|
|
2505
|
+
"""
|
|
2506
|
+
|
|
2507
|
+
EXAMPLES::
|
|
2508
|
+
|
|
2509
|
+
sage: Rings().Commutative().Finite()
|
|
2510
|
+
Category of finite commutative rings
|
|
2511
|
+
sage: _._lean_init_()
|
|
2512
|
+
'finite comm_ring'
|
|
2513
|
+
"""
|
|
2514
|
+
# adapted from _repr_object_names_static
|
|
2515
|
+
category = self
|
|
2516
|
+
axioms = self.axioms()
|
|
2517
|
+
|
|
2518
|
+
axioms = canonicalize_axioms(all_axioms, axioms)
|
|
2519
|
+
|
|
2520
|
+
base_category = category
|
|
2521
|
+
while True:
|
|
2522
|
+
try:
|
|
2523
|
+
result = base_category.__lean_init__()
|
|
2524
|
+
except (AttributeError, NotImplementedError):
|
|
2525
|
+
base_category = base_category.base_category()
|
|
2526
|
+
else:
|
|
2527
|
+
break
|
|
2528
|
+
|
|
2529
|
+
for axiom in reversed(axioms):
|
|
2530
|
+
if axiom in base_category.axioms():
|
|
2531
|
+
# If the base category already has this axiom, we
|
|
2532
|
+
# need not repeat it here. See the example with
|
|
2533
|
+
# Sets().Finite().Subquotients() or Monoids()
|
|
2534
|
+
continue
|
|
2535
|
+
base_category = base_category._with_axiom(axiom)
|
|
2536
|
+
|
|
2537
|
+
if axiom == "Finite":
|
|
2538
|
+
result = "finite" + " " + result
|
|
2539
|
+
elif axiom == "Commutative":
|
|
2540
|
+
result = "is_commutative" + " " + result
|
|
2541
|
+
|
|
2542
|
+
# TODO: Handle more of all_axioms here.
|
|
2543
|
+
|
|
2544
|
+
return result
|
|
2545
|
+
|
|
2546
|
+
|
|
2547
|
+
class CategoryWithAxiom_over_base_ring(CategoryWithAxiom, Category_over_base_ring):
|
|
2548
|
+
|
|
2549
|
+
def __init__(self, base_category):
|
|
2550
|
+
"""
|
|
2551
|
+
TESTS::
|
|
2552
|
+
|
|
2553
|
+
sage: C = Modules(ZZ).FiniteDimensional(); C
|
|
2554
|
+
Category of finite dimensional modules over Integer Ring
|
|
2555
|
+
sage: type(C)
|
|
2556
|
+
<class 'sage.categories.modules.Modules.FiniteDimensional_with_category'>
|
|
2557
|
+
sage: type(C).__base__.__base__
|
|
2558
|
+
<class 'sage.categories.category_with_axiom.CategoryWithAxiom_over_base_ring'>
|
|
2559
|
+
|
|
2560
|
+
sage: TestSuite(C).run()
|
|
2561
|
+
"""
|
|
2562
|
+
# FIXME: this basically duplicates the code from
|
|
2563
|
+
# CategoryWithAxiom.__init__; but we can't call the latter without
|
|
2564
|
+
# calling Category.__init__ twice. One could instead set
|
|
2565
|
+
# "self.__base", which is done in Category_over_base_ring.__init__,
|
|
2566
|
+
# but then one has to take into account Python's name mangling.
|
|
2567
|
+
self._base_category = base_category
|
|
2568
|
+
Category_over_base_ring.__init__(self, base_category.base_ring())
|
|
2569
|
+
|
|
2570
|
+
|
|
2571
|
+
class CategoryWithAxiom_singleton(Category_singleton, CategoryWithAxiom): # Category_singleton, FastHashable_class):
|
|
2572
|
+
pass
|
|
2573
|
+
|
|
2574
|
+
|
|
2575
|
+
"""
|
|
2576
|
+
The following workaround is needed until any :class:`CategoryWithAxiom` of a
|
|
2577
|
+
:class:`Category_over_base_ring` becomes automatically a
|
|
2578
|
+
:class:`CategoryWithAxiom_over_base_ring`::
|
|
2579
|
+
|
|
2580
|
+
sage: from sage.categories.category_with_axiom import TestObjectsOverBaseRing, Category_over_base_ring
|
|
2581
|
+
sage: from sage.categories.category import JoinCategory
|
|
2582
|
+
sage: isinstance(TestObjectsOverBaseRing(QQ), Category_over_base_ring)
|
|
2583
|
+
True
|
|
2584
|
+
sage: C = TestObjectsOverBaseRing(QQ).Commutative()
|
|
2585
|
+
sage: isinstance(C, Category_over_base_ring) # todo: not implemented
|
|
2586
|
+
True
|
|
2587
|
+
sage: C.FiniteDimensional()
|
|
2588
|
+
Category of finite dimensional commutative test objects over base ring over Rational Field
|
|
2589
|
+
sage: C.Commutative()
|
|
2590
|
+
Category of commutative test objects over base ring over Rational Field
|
|
2591
|
+
sage: C.Unital()
|
|
2592
|
+
Category of commutative unital test objects over base ring over Rational Field
|
|
2593
|
+
|
|
2594
|
+
sage: C = TestObjectsOverBaseRing(IntegerModRing(2)).Connected()
|
|
2595
|
+
sage: isinstance(C, JoinCategory)
|
|
2596
|
+
True
|
|
2597
|
+
sage: isinstance(C, Category_over_base_ring) # todo: not implemented
|
|
2598
|
+
True
|
|
2599
|
+
sage: C.FiniteDimensional()
|
|
2600
|
+
Category of finite dimensional connected test objects
|
|
2601
|
+
over base ring over Ring of integers modulo 2
|
|
2602
|
+
sage: C.Connected()
|
|
2603
|
+
Category of connected test objects over base ring over Ring of integers modulo 2
|
|
2604
|
+
"""
|
|
2605
|
+
|
|
2606
|
+
##############################################################################
|
|
2607
|
+
# Utilities and tests tools
|
|
2608
|
+
|
|
2609
|
+
|
|
2610
|
+
def axiom(axiom):
|
|
2611
|
+
"""
|
|
2612
|
+
Return a function/method ``self -> self._with_axiom(axiom)``.
|
|
2613
|
+
|
|
2614
|
+
This can used as a shorthand to define axioms, in particular in
|
|
2615
|
+
the tests below. Usually one will want to attach documentation to
|
|
2616
|
+
an axiom, so the need for such a shorthand in real life might not
|
|
2617
|
+
be that clear, unless we start creating lots of axioms.
|
|
2618
|
+
|
|
2619
|
+
In the long run maybe this could evolve into an ``@axiom`` decorator.
|
|
2620
|
+
|
|
2621
|
+
EXAMPLES::
|
|
2622
|
+
|
|
2623
|
+
sage: from sage.categories.category_with_axiom import axiom
|
|
2624
|
+
sage: axiom("Finite")(Semigroups())
|
|
2625
|
+
Category of finite semigroups
|
|
2626
|
+
|
|
2627
|
+
Upon assigning the result to a class this becomes a method::
|
|
2628
|
+
|
|
2629
|
+
sage: class As:
|
|
2630
|
+
....: def _with_axiom(self, axiom): return self, axiom
|
|
2631
|
+
....: Finite = axiom("Finite")
|
|
2632
|
+
sage: As().Finite()
|
|
2633
|
+
(<__main__.As ... at ...>, 'Finite')
|
|
2634
|
+
"""
|
|
2635
|
+
def with_axiom(self):
|
|
2636
|
+
return self._with_axiom(axiom)
|
|
2637
|
+
with_axiom.__name__ = axiom
|
|
2638
|
+
return with_axiom
|
|
2639
|
+
|
|
2640
|
+
|
|
2641
|
+
class Blahs(Category_singleton):
|
|
2642
|
+
r"""
|
|
2643
|
+
A toy singleton category, for testing purposes.
|
|
2644
|
+
|
|
2645
|
+
This is the root of a hierarchy of mathematically meaningless
|
|
2646
|
+
categories, used for testing Sage's category framework:
|
|
2647
|
+
|
|
2648
|
+
- :class:`Bars`
|
|
2649
|
+
- :class:`TestObjects`
|
|
2650
|
+
- :class:`TestObjectsOverBaseRing`
|
|
2651
|
+
"""
|
|
2652
|
+
|
|
2653
|
+
def super_categories(self):
|
|
2654
|
+
"""
|
|
2655
|
+
TESTS::
|
|
2656
|
+
|
|
2657
|
+
sage: from sage.categories.category_with_axiom import Blahs
|
|
2658
|
+
sage: Blahs().super_categories()
|
|
2659
|
+
[Category of sets]
|
|
2660
|
+
sage: TestSuite(Blahs()).run()
|
|
2661
|
+
"""
|
|
2662
|
+
from sage.categories.sets_cat import Sets
|
|
2663
|
+
return [Sets()]
|
|
2664
|
+
|
|
2665
|
+
class SubcategoryMethods:
|
|
2666
|
+
FiniteDimensional = axiom("FiniteDimensional")
|
|
2667
|
+
Commutative = axiom("Commutative")
|
|
2668
|
+
Unital = axiom("Unital")
|
|
2669
|
+
Connected = axiom("Connected")
|
|
2670
|
+
Flying = axiom("Flying")
|
|
2671
|
+
Blue = axiom("Blue")
|
|
2672
|
+
|
|
2673
|
+
class FiniteDimensional(CategoryWithAxiom):
|
|
2674
|
+
pass
|
|
2675
|
+
|
|
2676
|
+
class Commutative(CategoryWithAxiom):
|
|
2677
|
+
pass
|
|
2678
|
+
|
|
2679
|
+
class Connected(CategoryWithAxiom):
|
|
2680
|
+
pass
|
|
2681
|
+
|
|
2682
|
+
class Unital(CategoryWithAxiom):
|
|
2683
|
+
class Blue(CategoryWithAxiom):
|
|
2684
|
+
pass
|
|
2685
|
+
|
|
2686
|
+
class Flying(CategoryWithAxiom):
|
|
2687
|
+
def extra_super_categories(self):
|
|
2688
|
+
"""
|
|
2689
|
+
This illustrates a way to have an axiom imply another one.
|
|
2690
|
+
|
|
2691
|
+
Here, we want ``Flying`` to imply ``Unital``, and to put
|
|
2692
|
+
the class for the category of unital flying blahs in
|
|
2693
|
+
``Blahs.Flying`` rather than ``Blahs.Unital.Flying``.
|
|
2694
|
+
|
|
2695
|
+
TESTS::
|
|
2696
|
+
|
|
2697
|
+
sage: from sage.categories.category_with_axiom import Blahs, TestObjects, Bars
|
|
2698
|
+
sage: Blahs().Flying().extra_super_categories()
|
|
2699
|
+
[Category of unital blahs]
|
|
2700
|
+
sage: Blahs().Flying()
|
|
2701
|
+
Category of flying unital blahs
|
|
2702
|
+
"""
|
|
2703
|
+
return [Blahs().Unital()]
|
|
2704
|
+
|
|
2705
|
+
def Blue_extra_super_categories(self):
|
|
2706
|
+
"""
|
|
2707
|
+
Illustrates a current limitation in the way to have an axiom
|
|
2708
|
+
imply another one.
|
|
2709
|
+
|
|
2710
|
+
Here, we would want ``Blue`` to imply ``Unital``, and to put
|
|
2711
|
+
the class for the category of unital blue blahs in
|
|
2712
|
+
``Blahs.Unital.Blue`` rather than ``Blahs.Blue``.
|
|
2713
|
+
|
|
2714
|
+
This currently fails because ``Blahs`` is the category where
|
|
2715
|
+
the axiom ``Blue`` is defined, and the specifications
|
|
2716
|
+
currently impose that a category defining an axiom should also
|
|
2717
|
+
implement it (here in a category with axiom
|
|
2718
|
+
``Blahs.Blue``). In practice, due to this violation of the
|
|
2719
|
+
specifications, the axiom is lost during the join calculation.
|
|
2720
|
+
|
|
2721
|
+
.. TODO::
|
|
2722
|
+
|
|
2723
|
+
Decide whether we care about this feature. In such a
|
|
2724
|
+
situation, we are not really defining a new axiom, but
|
|
2725
|
+
just defining an axiom as an alias for a couple others,
|
|
2726
|
+
which might not be that useful.
|
|
2727
|
+
|
|
2728
|
+
.. TODO::
|
|
2729
|
+
|
|
2730
|
+
Improve the infrastructure to detect and report this
|
|
2731
|
+
violation of the specifications, if this is
|
|
2732
|
+
easy. Otherwise, it's not so bad: when defining an axiom A
|
|
2733
|
+
in a category ``Cs`` the first thing one is supposed to
|
|
2734
|
+
doctest is that ``Cs().A()`` works. So the problem should
|
|
2735
|
+
not go unnoticed.
|
|
2736
|
+
|
|
2737
|
+
TESTS::
|
|
2738
|
+
|
|
2739
|
+
sage: from sage.categories.category_with_axiom import Blahs, TestObjects, Bars
|
|
2740
|
+
sage: Blahs().Blue_extra_super_categories()
|
|
2741
|
+
[Category of unital blahs]
|
|
2742
|
+
sage: Blahs().Blue() # todo: not implemented
|
|
2743
|
+
Category of blue unital blahs
|
|
2744
|
+
"""
|
|
2745
|
+
return [Blahs().Unital()]
|
|
2746
|
+
|
|
2747
|
+
|
|
2748
|
+
class Bars(Category_singleton):
|
|
2749
|
+
r"""
|
|
2750
|
+
A toy singleton category, for testing purposes.
|
|
2751
|
+
|
|
2752
|
+
.. SEEALSO:: :class:`Blahs`
|
|
2753
|
+
"""
|
|
2754
|
+
|
|
2755
|
+
def super_categories(self):
|
|
2756
|
+
"""
|
|
2757
|
+
TESTS::
|
|
2758
|
+
|
|
2759
|
+
sage: from sage.categories.category_with_axiom import Bars
|
|
2760
|
+
sage: Bars().super_categories()
|
|
2761
|
+
[Category of blahs]
|
|
2762
|
+
sage: TestSuite(Bars()).run()
|
|
2763
|
+
"""
|
|
2764
|
+
return [Blahs()]
|
|
2765
|
+
|
|
2766
|
+
def Unital_extra_super_categories(self):
|
|
2767
|
+
"""
|
|
2768
|
+
Return extraneous super categories for the unital objects of ``self``.
|
|
2769
|
+
|
|
2770
|
+
This method specifies that a unital bar is a test object.
|
|
2771
|
+
Thus, the categories of unital bars and of unital test objects
|
|
2772
|
+
coincide.
|
|
2773
|
+
|
|
2774
|
+
EXAMPLES::
|
|
2775
|
+
|
|
2776
|
+
sage: from sage.categories.category_with_axiom import Bars, TestObjects
|
|
2777
|
+
sage: Bars().Unital_extra_super_categories()
|
|
2778
|
+
[Category of test objects]
|
|
2779
|
+
sage: Bars().Unital()
|
|
2780
|
+
Category of unital test objects
|
|
2781
|
+
sage: TestObjects().Unital().all_super_categories()
|
|
2782
|
+
[Category of unital test objects,
|
|
2783
|
+
Category of unital blahs,
|
|
2784
|
+
Category of test objects,
|
|
2785
|
+
Category of bars,
|
|
2786
|
+
Category of blahs,
|
|
2787
|
+
Category of sets,
|
|
2788
|
+
Category of sets with partial maps,
|
|
2789
|
+
Category of objects]
|
|
2790
|
+
"""
|
|
2791
|
+
return [TestObjects()]
|
|
2792
|
+
|
|
2793
|
+
|
|
2794
|
+
class TestObjects(Category_singleton):
|
|
2795
|
+
r"""
|
|
2796
|
+
A toy singleton category, for testing purposes.
|
|
2797
|
+
|
|
2798
|
+
.. SEEALSO:: :class:`Blahs`
|
|
2799
|
+
"""
|
|
2800
|
+
|
|
2801
|
+
def super_categories(self):
|
|
2802
|
+
"""
|
|
2803
|
+
TESTS::
|
|
2804
|
+
|
|
2805
|
+
sage: from sage.categories.category_with_axiom import TestObjects
|
|
2806
|
+
sage: TestObjects().super_categories()
|
|
2807
|
+
[Category of bars]
|
|
2808
|
+
sage: TestSuite(TestObjects()).run()
|
|
2809
|
+
"""
|
|
2810
|
+
return [Bars()]
|
|
2811
|
+
|
|
2812
|
+
class FiniteDimensional(CategoryWithAxiom):
|
|
2813
|
+
class Finite(CategoryWithAxiom):
|
|
2814
|
+
pass
|
|
2815
|
+
|
|
2816
|
+
class Unital(CategoryWithAxiom):
|
|
2817
|
+
class Commutative(CategoryWithAxiom):
|
|
2818
|
+
pass
|
|
2819
|
+
|
|
2820
|
+
class Commutative(CategoryWithAxiom):
|
|
2821
|
+
class Facade(CategoryWithAxiom):
|
|
2822
|
+
pass
|
|
2823
|
+
|
|
2824
|
+
class FiniteDimensional(CategoryWithAxiom):
|
|
2825
|
+
pass
|
|
2826
|
+
|
|
2827
|
+
class Finite(CategoryWithAxiom):
|
|
2828
|
+
pass
|
|
2829
|
+
|
|
2830
|
+
class Unital(CategoryWithAxiom):
|
|
2831
|
+
pass
|
|
2832
|
+
|
|
2833
|
+
|
|
2834
|
+
class TestObjectsOverBaseRing(Category_over_base_ring):
|
|
2835
|
+
r"""
|
|
2836
|
+
A toy singleton category, for testing purposes.
|
|
2837
|
+
|
|
2838
|
+
.. SEEALSO:: :class:`Blahs`
|
|
2839
|
+
"""
|
|
2840
|
+
|
|
2841
|
+
def super_categories(self):
|
|
2842
|
+
"""
|
|
2843
|
+
TESTS::
|
|
2844
|
+
|
|
2845
|
+
sage: from sage.categories.category_with_axiom import TestObjectsOverBaseRing
|
|
2846
|
+
sage: TestObjectsOverBaseRing(QQ).super_categories()
|
|
2847
|
+
[Category of test objects]
|
|
2848
|
+
sage: TestObjectsOverBaseRing.Unital.an_instance()
|
|
2849
|
+
Category of unital test objects over base ring over Rational Field
|
|
2850
|
+
sage: TestObjectsOverBaseRing.FiniteDimensional.Unital.an_instance()
|
|
2851
|
+
Category of finite dimensional unital test objects over base ring over Rational Field
|
|
2852
|
+
sage: C = TestObjectsOverBaseRing(QQ).FiniteDimensional().Unital().Commutative()
|
|
2853
|
+
sage: TestSuite(C).run()
|
|
2854
|
+
"""
|
|
2855
|
+
return [TestObjects()]
|
|
2856
|
+
|
|
2857
|
+
class FiniteDimensional(CategoryWithAxiom_over_base_ring):
|
|
2858
|
+
class Finite(CategoryWithAxiom_over_base_ring):
|
|
2859
|
+
pass
|
|
2860
|
+
|
|
2861
|
+
class Unital(CategoryWithAxiom_over_base_ring):
|
|
2862
|
+
class Commutative(CategoryWithAxiom_over_base_ring):
|
|
2863
|
+
pass
|
|
2864
|
+
|
|
2865
|
+
class Commutative(CategoryWithAxiom_over_base_ring):
|
|
2866
|
+
class Facade(CategoryWithAxiom_over_base_ring):
|
|
2867
|
+
pass
|
|
2868
|
+
|
|
2869
|
+
class FiniteDimensional(CategoryWithAxiom_over_base_ring):
|
|
2870
|
+
pass
|
|
2871
|
+
|
|
2872
|
+
class Finite(CategoryWithAxiom_over_base_ring):
|
|
2873
|
+
pass
|
|
2874
|
+
|
|
2875
|
+
class Unital(CategoryWithAxiom_over_base_ring):
|
|
2876
|
+
pass
|