AUTHORS:
Construct the forgetful function from one category to another.
INPUT:
C, D - two categories
OUTPUT:
A functor that returns the corresponding object of D for any element of C, by forgetting the extra structure.
ASSUMPTION:
The category C must be a sub-category of D.
EXAMPLES:
sage: rings = Rings()
sage: abgrps = CommutativeAdditiveGroups()
sage: F = ForgetfulFunctor(rings, abgrps)
sage: F
The forgetful functor from Category of rings to Category of commutative additive groups
It would be a mistake to call it in opposite order:
sage: F = ForgetfulFunctor(abgrps, rings)
Traceback (most recent call last):
...
ValueError: Forgetful functor not supported for domain Category of commutative additive groups
If both categories are equal, the forgetful functor is the same as the identity functor:
sage: ForgetfulFunctor(abgrps, abgrps) == IdentityFunctor(abgrps)
True
Bases: sage.categories.functor.Functor
The forgetful functor, i.e., embedding of a subcategory.
NOTE:
Forgetful functors should be created using ForgetfulFunctor(), since the init method of this class does not check whether the domain is a subcategory of the codomain.
EXAMPLES:
sage: F = ForgetfulFunctor(FiniteFields(),Fields()) #indirect doctest
sage: F
The forgetful functor from Category of finite fields to Category of fields
sage: F(GF(3))
Finite Field of size 3
Bases: sage.structure.sage_object.SageObject
A class for functors between two categories
NOTE:
EXAMPLES:
sage: rings = Rings()
sage: abgrps = CommutativeAdditiveGroups()
sage: F = ForgetfulFunctor(rings, abgrps)
sage: F.domain()
Category of rings
sage: F.codomain()
Category of commutative additive groups
sage: from sage.categories.functor import is_Functor
sage: is_Functor(F)
True
sage: I = IdentityFunctor(abgrps)
sage: I
The identity functor on Category of commutative additive groups
sage: I.domain()
Category of commutative additive groups
sage: is_Functor(I)
True
Note that by default, an instance of the class Functor is coercion from the domain into the codomain. The above subclasses overloaded this behaviour. Here we illustrate the default:
sage: from sage.categories.functor import Functor
sage: F = Functor(Rings(),Fields())
sage: F
Functor from Category of rings to Category of fields
sage: F(ZZ)
Rational Field
sage: F(GF(2))
Finite Field of size 2
Functors are not only about the objects of a category, but also about their morphisms. We illustrate it, again, with the coercion functor from rings to fields.
sage: R1.<x> = ZZ[]
sage: R2.<a,b> = QQ[]
sage: f = R1.hom([a+b],R2)
sage: f
Ring morphism:
From: Univariate Polynomial Ring in x over Integer Ring
To: Multivariate Polynomial Ring in a, b over Rational Field
Defn: x |--> a + b
sage: F(f)
Ring morphism:
From: Fraction Field of Univariate Polynomial Ring in x over Integer Ring
To: Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field
Defn: x |--> a + b
sage: F(f)(1/x)
1/(a + b)
We can also apply a polynomial ring construction functor to our homomorphism. The result is a homomorphism that is defined on the base ring:
sage: F = QQ['t'].construction()[0]
sage: F
Poly[t]
sage: F(f)
Ring morphism:
From: Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring
To: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field
Defn: Induced from base ring by
Ring morphism:
From: Univariate Polynomial Ring in x over Integer Ring
To: Multivariate Polynomial Ring in a, b over Rational Field
Defn: x |--> a + b
sage: p = R1['t']('(-x^2 + x)*t^2 + (x^2 - x)*t - 4*x^2 - x + 1')
sage: F(f)(p)
(-a^2 - 2*a*b - b^2 + a + b)*t^2 + (a^2 + 2*a*b + b^2 - a - b)*t - 4*a^2 - 8*a*b - 4*b^2 - a - b + 1
The codomain of self
EXAMPLE:
sage: F = ForgetfulFunctor(FiniteFields(),Fields())
sage: F.codomain()
Category of fields
The domain of self
EXAMPLE:
sage: F = ForgetfulFunctor(FiniteFields(),Fields())
sage: F.domain()
Category of finite fields
Construct the identity functor of the given category.
INPUT:
A category, C.
OUTPUT:
The identity functor in C.
EXAPLES:
sage: rings = Rings()
sage: F = IdentityFunctor(rings)
sage: F(ZZ['x','y']) is ZZ['x','y']
True
Bases: sage.categories.functor.ForgetfulFunctor_generic
Generic identity functor on any category
NOTE:
This usually is created using IdentityFunctor().
EXAMPLES:
sage: F = IdentityFunctor(Fields()) #indirect doctest
sage: F
The identity functor on Category of fields
sage: F(RR) is RR
True
sage: F(ZZ)
Traceback (most recent call last):
...
TypeError: x (=Integer Ring) is not in Category of fields
TESTS:
sage: R = IdentityFunctor(Rings())
sage: P, _ = QQ['t'].construction()
sage: R == P
False
sage: P == R
False
sage: R == QQ
False
Test whether the argument is a functor
NOTE:
There is a deprecation warning when using it from top level. Therefore we import it in our doc test.
EXAMPLES:
sage: from sage.categories.functor import is_Functor
sage: F1 = QQ.construction()[0]
sage: F1
FractionField
sage: is_Functor(F1)
True
sage: is_Functor(FractionField)
False
sage: F2 = ForgetfulFunctor(Fields(), Rings())
sage: F2
The forgetful functor from Category of fields to Category of rings
sage: is_Functor(F2)
True