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