This module implements parents modeling the set of all maps between two finite sets. At the user level, any such parent should be constructed using the factory class FiniteSetMaps which properly selects which of its subclasses to use.
AUTHORS:
Bases: sage.sets.finite_set_maps.FiniteSetMaps_MN
The sets of all maps from to itself
Users should use the factory class FiniteSetMaps to create instances of this class.
INPUT:
alias of FiniteSetEndoMap_N
Returns a map in self
EXAMPLES:
sage: M = FiniteSetMaps(4)
sage: M.an_element()
[3, 2, 1, 0]
EXAMPLES:
sage: M = FiniteSetMaps(4)
sage: M.one()
[0, 1, 2, 3]
Bases: sage.sets.finite_set_maps.FiniteSetMaps_Set, sage.sets.finite_set_maps.FiniteSetEndoMaps_N
The sets of all maps from a set to itself
Users should use the factory class FiniteSetMaps to create instances of this class.
INPUT:
alias of FiniteSetEndoMap_Set
Bases: sage.structure.unique_representation.UniqueRepresentation, sage.structure.parent.Parent
Maps between finite sets
Constructs the set of all maps between two sets. The sets can be given using any of the three following ways:
INPUT:
OUTPUT:
an instance of a subclass of FiniteSetMaps modeling the set of all maps between domain and codomain.
EXAMPLES:
We construct the set M of all maps from to
:
sage: M = FiniteSetMaps(["a", "b"], [3, 4, 5]); M
Maps from {'a', 'b'} to {3, 4, 5}
sage: M.cardinality()
9
sage: M.domain()
{'a', 'b'}
sage: M.codomain()
{3, 4, 5}
sage: for f in M: print f
map: a -> 3, b -> 3
map: a -> 3, b -> 4
map: a -> 3, b -> 5
map: a -> 4, b -> 3
map: a -> 4, b -> 4
map: a -> 4, b -> 5
map: a -> 5, b -> 3
map: a -> 5, b -> 4
map: a -> 5, b -> 5
Elements can be constructed from functions and dictionaries:
sage: M(lambda c: ord(c)-94)
map: a -> 3, b -> 4
sage: M.from_dict({'a':3, 'b':5})
map: a -> 3, b -> 5
If the domain is equal to the codomain, then maps can be composed:
sage: M = FiniteSetMaps([1, 2, 3])
sage: f = M.from_dict({1:2, 2:1, 3:3}); f
map: 1 -> 2, 2 -> 1, 3 -> 3
sage: g = M.from_dict({1:2, 2:3, 3:1}); g
map: 1 -> 2, 2 -> 3, 3 -> 1
sage: f * g
map: 1 -> 1, 2 -> 3, 3 -> 2
This makes into a monoid:
sage: M.category()
Category of finite monoids
sage: M.one()
map: 1 -> 1, 2 -> 2, 3 -> 3
By default, composition is from right to left, which corresponds to an action on the left. If one specifies action to right, then the composition is from left to right:
sage: M = FiniteSetMaps([1, 2, 3], action = 'right')
sage: f = M.from_dict({1:2, 2:1, 3:3})
sage: g = M.from_dict({1:2, 2:3, 3:1})
sage: f * g
map: 1 -> 3, 2 -> 2, 3 -> 1
If the domains and codomains are both of the form ,
then one can use the shortcut:
sage: M = FiniteSetMaps(2,3); M
Maps from {0, 1} to {0, 1, 2}
sage: M.cardinality()
9
For a compact notation, the elements are then printed as lists
:
sage: list(M)
[[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2]]
TESTS:
sage: TestSuite(FiniteSetMaps(0)).run()
sage: TestSuite(FiniteSetMaps(0, 2)).run()
sage: TestSuite(FiniteSetMaps(2, 0)).run()
sage: TestSuite(FiniteSetMaps([], [])).run()
sage: TestSuite(FiniteSetMaps([1, 2], [])).run()
sage: TestSuite(FiniteSetMaps([], [1, 2])).run()
The cardinality of self
EXAMPLES:
sage: FiniteSetMaps(4, 3).cardinality()
81
Bases: sage.sets.finite_set_maps.FiniteSetMaps
The set of all maps from to
.
Users should use the factory class FiniteSetMaps to create instances of this class.
INPUT:
alias of FiniteSetMap_MN
Returns a map in self
EXAMPLES:
sage: M = FiniteSetMaps(4, 2)
sage: M.an_element()
[0, 0, 0, 0]
sage: M = FiniteSetMaps(0, 0)
sage: M.an_element()
[]
An exception EmptySetError is raised if this set is empty, that is if the codomain is empty and the domain is not.
sage: M = FiniteSetMaps(4, 0) sage: M.cardinality() 0 sage: M.an_element() Traceback (most recent call last): ... EmptySetError
The codomain of self
EXAMPLES:
sage: FiniteSetMaps(3,2).codomain()
{0, 1}
The domain of self
EXAMPLES:
sage: FiniteSetMaps(3,2).domain()
{0, 1, 2}
Bases: sage.sets.finite_set_maps.FiniteSetMaps_MN
The sets of all maps between two sets
Users should use the factory class FiniteSetMaps to create instances of this class.
INPUT:
alias of FiniteSetMap_Set
The codomain of self
EXAMPLES:
sage: FiniteSetMaps(["a", "b"], [3, 4, 5]).codomain()
{3, 4, 5}
The domain of self
EXAMPLES:
sage: FiniteSetMaps(["a", "b"], [3, 4, 5]).domain()
{'a', 'b'}
Create a map from a dictionary
EXAMPLES:
sage: M = FiniteSetMaps(["a", "b"], [3, 4, 5])
sage: M.from_dict({"a": 4, "b": 3})
map: a -> 4, b -> 3