Kernel: SageMath 6.10
Infrastructure for generic code in Sage: categories, axioms, constructions
In [5]:
Parents, Elements, and generic code, the plain Python way
In [49]:
In [50]:
Stroumph coquet
In [51]:
Stroumph costaud
In [52]:
Stroumph costaud
In [53]:
Stroumph coquet
In [118]:
In [44]:
Stroumph coquet
Stroumph costaud
Grand stroumph
A hierarchy of abstract classes the usual way
In [119]:
Refactoring as a category
In [120]:
In [60]:
[Category of magmas]
In [63]:
In [65]:
[<class '__main__.MySemigroups.parent_class'>,
<class 'sage.categories.magmas.Magmas.parent_class'>,
<class 'sage.categories.sets_cat.Sets.parent_class'>,
<class 'sage.categories.sets_with_partial_maps.SetsWithPartialMaps.parent_class'>,
<class 'sage.categories.objects.Objects.parent_class'>,
<type 'object'>]
A complete Parent, written the Sage way
In [84]:
In [85]:
In [92]:
'Stroumph coquet'
In [91]:
<bound method BandOfStroumphs_with_category.list of <class '__main__.BandOfStroumphs_with_category'>>
In [87]:
'Stroumph coquet'
In [88]:
In [112]:
running ._test_an_element() . . . pass
running ._test_associativity() . . . pass
running ._test_cardinality() . . . pass
running ._test_category() . . . pass
running ._test_elements() . . .
Running the test suite of self.an_element()
running ._test_category() . . . pass
running ._test_eq() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . fail
Traceback (most recent call last):
File "/opt/sage-git/local/lib/python2.7/site-packages/sage/misc/sage_unittest.py", line 283, in run
test_method(tester = tester)
File "sage/structure/sage_object.pyx", line 665, in sage.structure.sage_object.SageObject._test_pickling (/opt/sage-git/src/build/cythonized/sage/structure/sage_object.c:5231)
tester.assertEqual(loads(dumps(self)), self)
File "sage/structure/sage_object.pyx", line 1130, in sage.structure.sage_object.dumps (/opt/sage-git/src/build/cythonized/sage/structure/sage_object.c:12525)
return obj.dumps(compress)
File "sage/structure/sage_object.pyx", line 488, in sage.structure.sage_object.SageObject.dumps (/opt/sage-git/src/build/cythonized/sage/structure/sage_object.c:3912)
s = cPickle.dumps(self, protocol=2)
PicklingError: Can't pickle <class '__main__.Element'>: attribute lookup __main__.Element failed
------------------------------------------------------------
The following tests failed: _test_pickling
running ._test_elements_eq_reflexive() . . . pass
running ._test_elements_eq_symmetric() . . . pass
running ._test_elements_eq_transitive() . . . pass
running ._test_elements_neq() . . . pass
running ._test_enumerated_set_contains() . . . pass
running ._test_enumerated_set_iter_cardinality() . . . pass
running ._test_enumerated_set_iter_list() . . . pass
running ._test_eq() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_some_elements() . . . pass
The following tests failed: _test_elements
In [93]:
Join of Category of finite semigroups and Category of finite enumerated sets
In [94]:
[Join of Category of finite semigroups and Category of finite enumerated sets,
Category of finite semigroups,
Category of semigroups,
Category of magmas,
Category of finite enumerated sets,
Category of enumerated sets,
Category of finite sets,
Category of sets,
Category of sets with partial maps,
Category of objects]
In [95]:
[<class '__main__.BandOfStroumphs_with_category'>,
<class '__main__.BandOfStroumphs'>,
<type 'sage.structure.parent.Parent'>,
<type 'sage.structure.category_object.CategoryObject'>,
<type 'sage.structure.sage_object.SageObject'>,
<class 'sage.categories.category.JoinCategory.parent_class'>,
<class 'sage.categories.finite_semigroups.FiniteSemigroups.parent_class'>,
<class 'sage.categories.semigroups.Semigroups.parent_class'>,
<class 'sage.categories.magmas.Magmas.parent_class'>,
<class 'sage.categories.finite_enumerated_sets.FiniteEnumeratedSets.parent_class'>,
<class 'sage.categories.enumerated_sets.EnumeratedSets.parent_class'>,
<class 'sage.categories.finite_sets.FiniteSets.parent_class'>,
<class 'sage.categories.sets_cat.Sets.parent_class'>,
<class 'sage.categories.sets_with_partial_maps.SetsWithPartialMaps.parent_class'>,
<class 'sage.categories.objects.Objects.parent_class'>,
<type 'object'>]
Side benefits of having categories as first class objects
In [37]:
In [38]:
Category of semigroups
In [40]:
In [ ]:
In [42]:
frozenset({'Associative'})
In [117]:
frozenset({Category of additive unital additive magmas,
Category of additive magmas,
Category of euclidean domains,
Category of unital magmas,
Category of magmas,
Category of sets with partial maps,
Category of sets})
In [114]:
Category of fields
In [116]:
frozenset({Category of additive unital additive magmas,
Category of additive magmas,
Category of euclidean domains,
Category of unital magmas,
Category of magmas,
Category of sets with partial maps,
Category of sets})
In [115]:
frozenset({'AdditiveAssociative',
'AdditiveCommutative',
'AdditiveInverse',
'AdditiveUnital',
'Associative',
'Commutative',
'Distributive',
'Division',
'NoZeroDivisors',
'Unital'})
In [217]:
In [218]:
frozenset({Category of additive unital additive magmas,
Category of additive magmas,
Category of coalgebras over Rational Field,
Category of filtered modules over Rational Field,
Category of graded modules over Rational Field,
Category of hopf algebras over Rational Field,
Category of left modules over Rational Field,
Category of unital magmas,
Category of magmas,
Category of right modules over Rational Field,
Category of sets with partial maps,
Category of sets})
In [219]:
frozenset({'AdditiveAssociative',
'AdditiveCommutative',
'AdditiveInverse',
'AdditiveUnital',
'Associative',
'Commutative',
'Connected',
'Distributive',
'Unital',
'WithBasis'})
Operations on categories
Adding an axiom
In [98]:
Category of commutative magmas
In [99]:
Category of commutative rings
Intersection
In [100]:
Category of finite groups
In [101]:
Category of distributive magmas and additive magmas
In [102]:
Category of additive commutative additive associative additive unital distributive magmas and additive magmas
In [103]:
Category of semirings
In [104]:
Category of rings
In [105]:
Category of division rings
In [106]:
Category of finite fields
In [107]:
frozenset({'AdditiveAssociative',
'AdditiveCommutative',
'AdditiveInverse',
'AdditiveUnital',
'Associative',
'Commutative',
'Distributive',
'Division',
'Finite',
'NoZeroDivisors',
'Unital'})
In [108]:
frozenset({Category of additive unital additive magmas,
Category of additive magmas,
Category of euclidean domains,
Category of unital magmas,
Category of magmas,
Category of sets with partial maps,
Category of sets})