Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/categories/finite_fields.py
4057 views
1
r"""
2
Finite Fields
3
"""
4
#*****************************************************************************
5
# Copyright (C) 2005 David Kohel <[email protected]>
6
# William Stein <[email protected]>
7
# 2008 Teresa Gomez-Diaz (CNRS) <[email protected]>
8
# 2008-2009 Nicolas M. Thiery <nthiery at users.sf.net>
9
#
10
# Distributed under the terms of the GNU General Public License (GPL)
11
# http://www.gnu.org/licenses/
12
#******************************************************************************
13
14
from sage.misc.cachefunc import cached_method
15
from sage.categories.category import Category
16
from sage.rings.field import is_Field
17
18
class FiniteFields(Category):
19
"""
20
The category of finite fields
21
22
EXAMPLES::
23
24
sage: K = FiniteFields()
25
sage: K
26
Category of finite fields
27
sage: FiniteField(17) in K
28
True
29
sage: RationalField() in K
30
False
31
sage: K(RationalField())
32
Traceback (most recent call last):
33
...
34
TypeError: unable to canonically associate a finite field to Rational Field
35
36
TESTS::
37
38
sage: TestSuite(FiniteFields()).run()
39
"""
40
41
@cached_method
42
def super_categories(self):
43
"""
44
EXAMPLES::
45
46
sage: FiniteFields().super_categories()
47
[Category of fields, Category of finite enumerated sets]
48
"""
49
from sage.categories.all import Fields, FiniteEnumeratedSets
50
return [Fields(), FiniteEnumeratedSets()]
51
52
def __contains__(self, x):
53
"""
54
EXAMPLES::
55
56
sage: GF(4, "a") in FiniteFields()
57
True
58
sage: QQ in FiniteFields()
59
False
60
sage: IntegerModRing(4) in FiniteFields()
61
False
62
"""
63
return is_Field(x) and x.is_finite()
64
65
# As is, this does no more than the usual __call__ of Category, but for the error message
66
def _call_(self, x):
67
"""
68
EXAMPLES::
69
70
sage: FiniteFields()(GF(4, "a"))
71
Finite Field in a of size 2^2
72
sage: FiniteFields()(RationalField()) # indirect doctest
73
Traceback (most recent call last):
74
...
75
TypeError: unable to canonically associate a finite field to Rational Field
76
"""
77
raise TypeError, "unable to canonically associate a finite field to %s"%x
78
# TODO: local dvr ring?
79
80
#@lazy_attribute
81
#def element_class(self):
82
# """
83
# A common super class for all elements of finite fields
84
#
85
# EXAMPLES::
86
#
87
# sage: C = FiniteFields().element_class; C
88
# <type 'sage.rings.finite_rings.element_base.FiniteFieldElement'>
89
# sage: type(C)
90
# <type 'type'>
91
# """
92
# from sage.rings.finite_rings.element_base import FiniteFieldElement
93
# return FiniteFieldElement
94
95
class ParentMethods:
96
pass
97
98
class ElementMethods:
99
pass
100
101