Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/schemes/plane_conics/con_finite_field.py
4108 views
1
r"""
2
Projective plane conics over finite fields
3
4
AUTHORS:
5
6
- Marco Streng (2010-07-20)
7
8
"""
9
#*****************************************************************************
10
# Copyright (C) 2009/2010 Marco Streng <[email protected]>
11
#
12
# Distributed under the terms of the GNU General Public License (GPL)
13
#
14
# This code is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# General Public License for more details.
18
#
19
# The full text of the GPL is available at:
20
#
21
# http://www.gnu.org/licenses/
22
#*****************************************************************************
23
24
from sage.rings.all import PolynomialRing
25
from sage.schemes.plane_curves.projective_curve import ProjectiveCurve_finite_field
26
from con_field import ProjectiveConic_field
27
28
class ProjectiveConic_finite_field(ProjectiveConic_field, ProjectiveCurve_finite_field):
29
r"""
30
Create a projective plane conic curve over a finite field.
31
See ``Conic`` for full documentation.
32
33
EXAMPLES::
34
35
sage: K.<a> = FiniteField(9, 'a')
36
sage: P.<X, Y, Z> = K[]
37
sage: Conic(X^2 + Y^2 - a*Z^2)
38
Projective Conic Curve over Finite Field in a of size 3^2 defined by X^2 + Y^2 + (-a)*Z^2
39
40
TESTS::
41
42
sage: K.<a> = FiniteField(4, 'a')
43
sage: Conic([a, 1, -1])._test_pickling()
44
"""
45
def __init__(self, A, f):
46
r"""
47
See ``Conic`` for full documentation.
48
49
EXAMPLES ::
50
51
sage: Conic([GF(3)(1), 1, 1])
52
Projective Conic Curve over Finite Field of size 3 defined by x^2 + y^2 + z^2
53
"""
54
ProjectiveConic_field.__init__(self, A, f)
55
56
57
def count_points(self, n):
58
r"""
59
If the base field `B` of `self` is finite of order `q`,
60
then returns the number of points over `\GF{q}, ..., \GF{q^n}`.
61
62
EXAMPLES::
63
64
sage: P.<x,y,z> = GF(3)[]
65
sage: c = Curve(x^2+y^2+z^2); c
66
Projective Conic Curve over Finite Field of size 3 defined by x^2 + y^2 + z^2
67
sage: c.count_points(4)
68
[4, 10, 28, 82]
69
"""
70
F = self.base_ring()
71
q = F.cardinality()
72
return [q**i+1 for i in range(1, n+1)]
73
74
75
def has_rational_point(self, point = False, read_cache = True, \
76
algorithm = 'default'):
77
r"""
78
Always returns ``True`` because self has a point defined over
79
its finite base field `B`.
80
81
If ``point`` is True, then returns a second output `S`, which is a
82
rational point if one exists.
83
84
Points are cached. If ``read_cache`` is True, then cached information
85
is used for the output if available. If no cached point is available
86
or ``read_cache`` is False, then random `y`-coordinates are tried
87
if ``self`` is smooth and a singular point is returned otherwise.
88
89
EXAMPLES ::
90
91
sage: Conic(FiniteField(37), [1, 2, 3, 4, 5, 6]).has_rational_point()
92
True
93
94
sage: C = Conic(FiniteField(2), [1, 1, 1, 1, 1, 0]); C
95
Projective Conic Curve over Finite Field of size 2 defined by x^2 + x*y + y^2 + x*z + y*z
96
sage: C.has_rational_point(point = True) # output is random
97
(True, (0 : 0 : 1))
98
99
sage: p = next_prime(10^50)
100
sage: F = FiniteField(p)
101
sage: C = Conic(F, [1, 2, 3]); C
102
Projective Conic Curve over Finite Field of size 100000000000000000000000000000000000000000000000151 defined by x^2 + 2*y^2 + 3*z^2
103
sage: C.has_rational_point(point = True) # output is random
104
(True,
105
(14971942941468509742682168602989039212496867586852 : 75235465708017792892762202088174741054630437326388 : 1)
106
107
sage: F.<a> = FiniteField(7^20)
108
sage: C = Conic([1, a, -5]); C
109
Projective Conic Curve over Finite Field in a of size 7^20 defined by x^2 + (a)*y^2 + 2*z^2
110
sage: C.has_rational_point(point = True) # output is random
111
(True,
112
(a^18 + 2*a^17 + 4*a^16 + 6*a^13 + a^12 + 6*a^11 + 3*a^10 + 4*a^9 + 2*a^8 + 4*a^7 + a^6 + 4*a^4 + 6*a^2 + 3*a + 6 : 5*a^19 + 5*a^18 + 5*a^17 + a^16 + 2*a^15 + 3*a^14 + 4*a^13 + 5*a^12 + a^11 + 3*a^10 + 2*a^8 + 3*a^7 + 4*a^6 + 4*a^5 + 6*a^3 + 5*a^2 + 2*a + 4 : 1))
113
114
TESTS ::
115
116
sage: l = Sequence(cartesian_product_iterator([[0, 1] for i in range(6)]))
117
sage: bigF = GF(next_prime(2^100))
118
sage: bigF2 = GF(next_prime(2^50)^2, 'b')
119
sage: m = [[F(b) for b in a] for a in l for F in [GF(2), GF(4, 'a'), GF(5), GF(9, 'a'), bigF, bigF2]]
120
sage: m += [[F.random_element() for i in range(6)] for j in range(20) for F in [GF(5), bigF]]
121
sage: c = [Conic(a) for a in m if a != [0,0,0,0,0,0]]
122
sage: assert all([C.has_rational_point() for C in c])
123
sage: r = randrange(0, 5)
124
sage: assert all([C.defining_polynomial()(Sequence(C.has_rational_point(point = True)[1])) == 0 for C in c[r::5]]) # long time: 1.6 seconds
125
"""
126
if not point:
127
return True
128
if read_cache:
129
if self._rational_point is not None:
130
return True, self._rational_point
131
B = self.base_ring()
132
s, pt = self.has_singular_point(point = True)
133
if s:
134
return True, pt
135
while True:
136
x = B.random_element()
137
Y = PolynomialRing(B,'Y').gen()
138
r = self.defining_polynomial()([x,Y,1]).roots()
139
if len(r) > 0:
140
return True, self.point([x,r[0][0],B(1)])
141
142
143
144
145