Sets¶
-
exception
sage.categories.sets_cat.
EmptySetError
¶ Bases:
ValueError
Exception raised when some operation can’t be performed on the empty set.
EXAMPLES:
sage: def first_element(st): ....: if not st: raise EmptySetError("no elements") ....: else: return st[0] sage: first_element(Set((1,2,3))) 1 sage: first_element(Set([])) Traceback (most recent call last): ... EmptySetError: no elements
-
sage.categories.sets_cat.
Sets
¶ The category of sets.
The base category for collections of elements with = (equality).
This is also the category whose objects are all parents.
EXAMPLES:
sage: Sets() Category of sets sage: Sets().super_categories() [Category of sets with partial maps] sage: Sets().all_super_categories() [Category of sets, Category of sets with partial maps, Category of objects]
Let us consider an example of set:
sage: P = Sets().example("inherits") sage: P Set of prime numbers
See
P??
for the code.P is in the category of sets:
sage: P.category() Category of sets
and therefore gets its methods from the following classes:
sage: for cl in P.__class__.mro(): print(cl) <class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits_with_category'> <class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits'> <class 'sage.categories.examples.sets_cat.PrimeNumbers_Abstract'> <class 'sage.structure.unique_representation.UniqueRepresentation'> <class 'sage.structure.unique_representation.CachedRepresentation'> <type 'sage.misc.fast_methods.WithEqualityById'> <type 'sage.structure.parent.Parent'> <type 'sage.structure.category_object.CategoryObject'> <type 'sage.structure.sage_object.SageObject'> <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'> <... 'object'>
We run some generic checks on P:
sage: TestSuite(P).run(verbose=True) running ._test_an_element() . . . 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_new() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass pass 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_eq() . . . pass running ._test_new() . . . pass running ._test_not_implemented_methods() . . . pass running ._test_pickling() . . . pass running ._test_some_elements() . . . pass
Now, we manipulate some elements of P:
sage: P.an_element() 47 sage: x = P(3) sage: x.parent() Set of prime numbers sage: x in P, 4 in P (True, False) sage: x.is_prime() True
They get their methods from the following classes:
sage: for cl in x.__class__.mro(): print(cl) <class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits_with_category.element_class'> <class 'sage.categories.examples.sets_cat.PrimeNumbers_Inherits.Element'> <type 'sage.rings.integer.IntegerWrapper'> <type 'sage.rings.integer.Integer'> <type 'sage.structure.element.EuclideanDomainElement'> <type 'sage.structure.element.PrincipalIdealDomainElement'> <type 'sage.structure.element.DedekindDomainElement'> <type 'sage.structure.element.IntegralDomainElement'> <type 'sage.structure.element.CommutativeRingElement'> <type 'sage.structure.element.RingElement'> <type 'sage.structure.element.ModuleElement'> <class 'sage.categories.examples.sets_cat.PrimeNumbers_Abstract.Element'> <type 'sage.structure.element.Element'> <type 'sage.structure.sage_object.SageObject'> <class 'sage.categories.sets_cat.Sets.element_class'> <class 'sage.categories.sets_with_partial_maps.SetsWithPartialMaps.element_class'> <class 'sage.categories.objects.Objects.element_class'> <... 'object'>
FIXME: Objects.element_class is not very meaningful …
-
sage.categories.sets_cat.
print_compare
(x, y)¶ Helper method used in
Sets.ParentMethods._test_elements_eq_symmetric()
,Sets.ParentMethods._test_elements_eq_tranisitive()
.INPUT:
x
– an elementy
– an element
EXAMPLES:
sage: from sage.categories.sets_cat import print_compare sage: print_compare(1,2) 1 != 2 sage: print_compare(1,1) 1 == 1