This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
finite_fields.py
113 lines (93 loc) · 3.4 KB
/
finite_fields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
r"""
Finite Fields
"""
#*****************************************************************************
# Copyright (C) 2005 David Kohel <kohel@maths.usyd.edu>
# William Stein <wstein@math.ucsd.edu>
# 2008 Teresa Gomez-Diaz (CNRS) <Teresa.Gomez-Diaz@univ-mlv.fr>
# 2008-2009 Nicolas M. Thiery <nthiery at users.sf.net>
#
# Distributed under the terms of the GNU General Public License (GPL)
# http://www.gnu.org/licenses/
#******************************************************************************
from sage.categories.category_with_axiom import CategoryWithAxiom
from sage.categories.enumerated_sets import EnumeratedSets
class FiniteFields(CategoryWithAxiom):
"""
The category of finite fields.
EXAMPLES::
sage: K = FiniteFields(); K
Category of finite fields
A finite field is a finite monoid with the structure of a field;
it is currently assumed to be enumerated::
sage: K.super_categories()
[Category of fields,
Category of finite commutative rings,
Category of finite enumerated sets]
Some examples of membership testing and coercion::
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: K is Fields().Finite()
True
sage: TestSuite(K).run()
"""
def extra_super_categories(self):
r"""
Any finite field is assumed to be endowed with an enumeration.
TESTS::
sage: Fields().Finite().extra_super_categories()
[Category of finite enumerated sets]
sage: FiniteFields().is_subcategory(FiniteEnumeratedSets())
True
"""
return [EnumeratedSets().Finite()]
def __contains__(self, x):
"""
EXAMPLES::
sage: GF(4, "a") in FiniteFields()
True
sage: QQ in FiniteFields()
False
sage: IntegerModRing(4) in FiniteFields()
False
"""
from sage.categories.fields import Fields
return x in Fields() and x.is_finite()
# As is, this does no more than the usual __call__ of Category, but for the error message
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)
# TODO: local dvr ring?
#@lazy_attribute
#def element_class(self):
# """
# A common super class for all elements of finite fields
#
# EXAMPLES::
#
# sage: C = FiniteFields().element_class; C
# <type 'sage.rings.finite_rings.element_base.FiniteFieldElement'>
# sage: type(C)
# <type 'type'>
# """
# from sage.rings.finite_rings.element_base import FiniteFieldElement
# return FiniteFieldElement
class ParentMethods:
pass
class ElementMethods:
pass