Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/schemes/plane_conics/constructor.py
4073 views
1
r"""
2
Plane conic constructor
3
4
AUTHORS:
5
6
- Marco Streng (2010-07-20)
7
8
- Nick Alexander (2008-01-08)
9
10
"""
11
#*****************************************************************************
12
# Copyright (C) 2008 Nick Alexander <[email protected]>
13
# Copyright (C) 2009/2010 Marco Streng <[email protected]>
14
#
15
# Distributed under the terms of the GNU General Public License (GPL)
16
#
17
# This code is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
# General Public License for more details.
21
#
22
# The full text of the GPL is available at:
23
#
24
# http://www.gnu.org/licenses/
25
#*****************************************************************************
26
27
from sage.matrix.constructor import Matrix
28
from sage.modules.free_module_element import vector
29
from sage.quadratic_forms.all import is_QuadraticForm
30
from sage.rings.all import (is_MPolynomial, PolynomialRing,
31
is_IntegralDomain, is_FiniteField,
32
is_PrimeFiniteField,
33
is_RationalField)
34
from sage.rings.number_field.number_field import is_NumberField
35
from sage.schemes.generic.all import ProjectiveSpace
36
from sage.schemes.generic.morphism import (
37
SchemeMorphism_point_affine, SchemeMorphism_point_projective_field)
38
from sage.structure.all import Sequence
39
from sage.structure.element import is_Matrix
40
41
from con_field import ProjectiveConic_field
42
from con_finite_field import ProjectiveConic_finite_field
43
from con_prime_finite_field import ProjectiveConic_prime_finite_field
44
from con_number_field import ProjectiveConic_number_field
45
from con_rational_field import ProjectiveConic_rational_field
46
47
def Conic(base_field, F=None, names=None, unique=True):
48
r"""
49
Return the plane projective conic curve defined by ``F``
50
over ``base_field``.
51
52
The input form ``Conic(F, names=None)`` is also accepted,
53
in which case the fraction field of the base ring of ``F``
54
is used as base field.
55
56
INPUT:
57
58
- ``base_field`` -- The base field of the conic.
59
60
- ``names`` -- a list, tuple, or comma separated string
61
of three variable names specifying the names
62
of the coordinate functions of the ambient
63
space `\Bold{P}^3`. If not specified or read
64
off from ``F``, then this defaults to ``'x,y,z'``.
65
66
- ``F`` -- a polynomial, list, matrix, ternary quadratic form,
67
or list or tuple of 5 points in the plane.
68
69
If ``F`` is a polynomial or quadratic form,
70
then the output is the curve in the projective plane
71
defined by ``F = 0``.
72
73
If ``F`` is a polynomial, then it must be a polynomial
74
of degree at most 2 in 2 variables, or a homogeneous
75
polynomial in of degree 2 in 3 variables.
76
77
If ``F`` is a matrix, then the output is the zero locus
78
of `(x,y,z) F (x,y,z)^t`.
79
80
If ``F`` is a list of coefficients, then it has
81
length 3 or 6 and gives the coefficients of
82
the monomials `x^2, y^2, z^2` or all 6 monomials
83
`x^2, xy, xz, y^2, yz, z^2` in lexicographic order.
84
85
If ``F`` is a list of 5 points in the plane, then the output
86
is a conic through those points.
87
88
- ``unique`` -- Used only if ``F`` is a list of points in the plane.
89
If the conic through the points is not unique, then
90
raise ``ValueError`` if and only if ``unique`` is True
91
92
OUTPUT:
93
94
A plane projective conic curve defined by ``F`` over a field.
95
96
EXAMPLES:
97
98
Conic curves given by polynomials ::
99
100
sage: X,Y,Z = QQ['X,Y,Z'].gens()
101
sage: Conic(X^2 - X*Y + Y^2 - Z^2)
102
Projective Conic Curve over Rational Field defined by X^2 - X*Y + Y^2 - Z^2
103
sage: x,y = GF(7)['x,y'].gens()
104
sage: Conic(x^2 - x + 2*y^2 - 3, 'U,V,W')
105
Projective Conic Curve over Finite Field of size 7 defined by U^2 + 2*V^2 - U*W - 3*W^2
106
107
Conic curves given by matrices ::
108
109
sage: Conic(matrix(QQ, [[1, 2, 0], [4, 0, 0], [7, 0, 9]]), 'x,y,z')
110
Projective Conic Curve over Rational Field defined by x^2 + 6*x*y + 7*x*z + 9*z^2
111
112
sage: x,y,z = GF(11)['x,y,z'].gens()
113
sage: C = Conic(x^2+y^2-2*z^2); C
114
Projective Conic Curve over Finite Field of size 11 defined by x^2 + y^2 - 2*z^2
115
sage: Conic(C.symmetric_matrix(), 'x,y,z')
116
Projective Conic Curve over Finite Field of size 11 defined by x^2 + y^2 - 2*z^2
117
118
Conics given by coefficients ::
119
120
sage: Conic(QQ, [1,2,3])
121
Projective Conic Curve over Rational Field defined by x^2 + 2*y^2 + 3*z^2
122
sage: Conic(GF(7), [1,2,3,4,5,6], 'X')
123
Projective Conic Curve over Finite Field of size 7 defined by X0^2 + 2*X0*X1 - 3*X1^2 + 3*X0*X2 - 2*X1*X2 - X2^2
124
125
The conic through a set of points ::
126
127
sage: C = Conic(QQ, [[10,2],[3,4],[-7,6],[7,8],[9,10]]); C
128
Projective Conic Curve over Rational Field defined by x^2 + 13/4*x*y - 17/4*y^2 - 35/2*x*z + 91/4*y*z - 37/2*z^2
129
sage: C.rational_point()
130
(10 : 2 : 1)
131
sage: C.point([3,4])
132
(3 : 4 : 1)
133
134
sage: a=AffineSpace(GF(13),2)
135
sage: Conic([a([x,x^2]) for x in range(5)])
136
Projective Conic Curve over Finite Field of size 13 defined by x^2 - y*z
137
"""
138
if not (is_IntegralDomain(base_field) or base_field == None):
139
if names is None:
140
names = F
141
F = base_field
142
base_field = None
143
if isinstance(F, (list,tuple)):
144
if len(F) == 1:
145
return Conic(base_field, F[0], names)
146
if names == None:
147
names = 'x,y,z'
148
if len(F) == 5:
149
L=[]
150
for f in F:
151
if isinstance(f, SchemeMorphism_point_affine):
152
C = Sequence(f, universe = base_field)
153
if len(C) != 2:
154
raise TypeError, "points in F (=%s) must be planar"%F
155
C.append(1)
156
elif isinstance(f, SchemeMorphism_point_projective_field):
157
C = Sequence(f, universe = base_field)
158
elif isinstance(f, (list, tuple)):
159
C = Sequence(f, universe = base_field)
160
if len(C) == 2:
161
C.append(1)
162
else:
163
raise TypeError, "F (=%s) must be a sequence of planar " \
164
"points" % F
165
if len(C) != 3:
166
raise TypeError, "points in F (=%s) must be planar" % F
167
P = C.universe()
168
if not is_IntegralDomain(P):
169
raise TypeError, "coordinates of points in F (=%s) must " \
170
"be in an integral domain" % F
171
L.append(Sequence([C[0]**2, C[0]*C[1], C[0]*C[2], C[1]**2,
172
C[1]*C[2], C[2]**2], P.fraction_field()))
173
M=Matrix(L)
174
if unique and M.rank() != 5:
175
raise ValueError, "points in F (=%s) do not define a unique " \
176
"conic" % F
177
con = Conic(base_field, Sequence(M.right_kernel().gen()), names)
178
con.point(F[0])
179
return con
180
F = Sequence(F, universe = base_field)
181
base_field = F.universe().fraction_field()
182
temp_ring = PolynomialRing(base_field, 3, names)
183
(x,y,z) = temp_ring.gens()
184
if len(F) == 3:
185
return Conic(F[0]*x**2 + F[1]*y**2 + F[2]*z**2)
186
if len(F) == 6:
187
return Conic(F[0]*x**2 + F[1]*x*y + F[2]*x*z + F[3]*y**2 + \
188
F[4]*y*z + F[5]*z**2)
189
raise TypeError, "F (=%s) must be a sequence of 3 or 6" \
190
"coefficients" % F
191
if is_QuadraticForm(F):
192
F = F.matrix()
193
if is_Matrix(F) and F.is_square() and F.ncols() == 3:
194
if names == None:
195
names = 'x,y,z'
196
temp_ring = PolynomialRing(F.base_ring(), 3, names)
197
F = vector(temp_ring.gens()) * F * vector(temp_ring.gens())
198
199
if not is_MPolynomial(F):
200
raise TypeError, "F (=%s) must be a three-variable polynomial or " \
201
"a sequence of points or coefficients" % F
202
203
if F.total_degree() != 2:
204
raise TypeError, "F (=%s) must have degree 2" % F
205
206
if base_field == None:
207
base_field = F.base_ring()
208
if not is_IntegralDomain(base_field):
209
raise ValueError, "Base field (=%s) must be a field" % base_field
210
base_field = base_field.fraction_field()
211
if names == None:
212
names = F.parent().variable_names()
213
pol_ring = PolynomialRing(base_field, 3, names)
214
215
if F.parent().ngens() == 2:
216
(x,y,z) = pol_ring.gens()
217
F = pol_ring(F(x/z,y/z)*z**2)
218
219
if F == 0:
220
raise ValueError, "F must be nonzero over base field %s" % base_field
221
222
if F.total_degree() != 2:
223
raise TypeError, "F (=%s) must have degree 2 over base field %s" % \
224
(F, base_field)
225
226
if F.parent().ngens() == 3:
227
P2 = ProjectiveSpace(2, base_field, names)
228
if is_PrimeFiniteField(base_field):
229
return ProjectiveConic_prime_finite_field(P2, F)
230
if is_FiniteField(base_field):
231
return ProjectiveConic_finite_field(P2, F)
232
if is_RationalField(base_field):
233
return ProjectiveConic_rational_field(P2, F)
234
if is_NumberField(base_field):
235
return ProjectiveConic_number_field(P2, F)
236
return ProjectiveConic_field(P2, F)
237
238
raise TypeError, "Number of variables of F (=%s) must be 2 or 3" % F
239
240