r"""
Finite Fields
"""
from sage.misc.cachefunc import cached_method
from sage.categories.category import Category
from sage.rings.field import is_Field
class FiniteFields(Category):
"""
The category of finite fields
EXAMPLES::
sage: K = FiniteFields()
sage: K
Category of finite fields
sage: FiniteField(17) in K
True
sage: RationalField() in K
False
sage: K(RationalField())
Traceback (most recent call last):
...
TypeError: unable to canonically associate a finite field to Rational Field
TESTS::
sage: TestSuite(FiniteFields()).run()
"""
@cached_method
def super_categories(self):
"""
EXAMPLES::
sage: FiniteFields().super_categories()
[Category of fields, Category of finite enumerated sets]
"""
from sage.categories.all import Fields, FiniteEnumeratedSets
return [Fields(), FiniteEnumeratedSets()]
def __contains__(self, x):
"""
EXAMPLES::
sage: GF(4, "a") in FiniteFields()
True
sage: QQ in FiniteFields()
False
sage: IntegerModRing(4) in FiniteFields()
False
"""
return is_Field(x) and x.is_finite()
def _call_(self, x):
"""
EXAMPLES::
sage: FiniteFields()(GF(4, "a"))
Finite Field in a of size 2^2
sage: FiniteFields()(RationalField()) # indirect doctest
Traceback (most recent call last):
...
TypeError: unable to canonically associate a finite field to Rational Field
"""
raise TypeError, "unable to canonically associate a finite field to %s"%x
class ParentMethods:
pass
class ElementMethods:
pass