Morphisms
AUTHORS:
Bases: sage.categories.morphism.Morphism
INPUT:
There can be one or two arguments of this init method. If it is one argument, it must be a hom space. If it is two arguments, it must be two parent structures that will be domain and codomain of the map-to-be-created.
TESTS:
sage: from sage.categories.map import Map
Using a hom space:
sage: Map(Hom(QQ, ZZ, Rings()))
Generic map:
From: Rational Field
To: Integer Ring
Using domain and codomain:
sage: Map(QQ['x'], SymmetricGroup(6))
Generic map:
From: Univariate Polynomial Ring in x over Rational Field
To: Symmetric group of order 6! as a permutation group
Bases: sage.categories.map.Map
INPUT:
There can be one or two arguments of this init method. If it is one argument, it must be a hom space. If it is two arguments, it must be two parent structures that will be domain and codomain of the map-to-be-created.
TESTS:
sage: from sage.categories.map import Map
Using a hom space:
sage: Map(Hom(QQ, ZZ, Rings()))
Generic map:
From: Rational Field
To: Integer Ring
Using domain and codomain:
sage: Map(QQ['x'], SymmetricGroup(6))
Generic map:
From: Univariate Polynomial Ring in x over Rational Field
To: Symmetric group of order 6! as a permutation group
Return true if this morphism is the identity morphism.
Note
Implemented only when the domain has a method gens()
EXAMPLES:
sage: R.<t> = ZZ[] sage: f = R.hom([t]) sage: f.is_identity() True sage: g = R.hom([t+1]) sage: g.is_identity() False
A morphism between two different spaces can’t be the identity:
sage: R2.<t2> = QQ[]
sage: h = R.hom([t2])
sage: h.is_identity()
False
AUTHOR:
Register this morphism as a coercion to Sage’s coercion model (see sage.structure.coerce).
EXAMPLES:
By default, adding polynomials over different variables triggers an error:
sage: X.<x> = ZZ[]
sage: Y.<y> = ZZ[]
sage: x^2 + y
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for '+': 'Univariate Polynomial Ring in x over Integer Ring' and 'Univariate Polynomial Ring in y over Integer Ring'
Let us declare a coercion from to
:
sage: Z.<z> = ZZ[]
sage: phi = Hom(X, Z)(z)
sage: phi(x^2+1)
z^2 + 1
sage: phi.register_as_coercion()
Now we can add elements from and
, because
the elements of the former are allowed to be implicitly
coerced into the later:
sage: x^2 + z
z^2 + z
Caveat: the registration of the coercion must be done before any other coercion is registered or discovered:
sage: phi = Hom(X, Y)(y)
sage: phi.register_as_coercion()
Traceback (most recent call last):
...
AssertionError: coercion from Univariate Polynomial Ring in x over Integer Ring to Univariate Polynomial Ring in y over Integer Ring already registered or discovered
Register this morphism as a conversion to Sage’s coercion model
(see sage.structure.coerce).
EXAMPLES:
Let us declare a conversion from the symmetric group to
through the sign map:
sage: S = SymmetricGroup(4)
sage: phi = Hom(S, ZZ)(lambda x: ZZ(x.sign()))
sage: x = S.an_element(); x
(1,2,3,4)
sage: phi(x)
-1
sage: phi.register_as_conversion()
sage: ZZ(x)
-1
Bases: sage.categories.morphism.Morphism
INPUT:
- parent – a Homset
- function – a Python function that takes elements of the domain as input and returns elements of the domain.
EXAMPLES:
sage: from sage.categories.morphism import SetMorphism
sage: f = SetMorphism(Hom(QQ, ZZ, Sets()), numerator) # could use Monoids() once the categories will be in
sage: f.parent()
Set of Morphisms from Rational Field to Integer Ring in Category of sets
sage: f.domain()
Rational Field
sage: f.codomain()
Integer Ring
sage: TestSuite(f).run()