Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/schemes/plane_curves/constructor.py
4097 views
1
"""
2
Plane curve constructors
3
4
AUTHORS:
5
6
- William Stein (2005-11-13)
7
8
- David Kohel (2006-01)
9
"""
10
11
#*****************************************************************************
12
# Copyright (C) 2005 William Stein <[email protected]>
13
#
14
# Distributed under the terms of the GNU General Public License (GPL)
15
#
16
# This code is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
# General Public License for more details.
20
#
21
# The full text of the GPL is available at:
22
#
23
# http://www.gnu.org/licenses/
24
#*****************************************************************************
25
26
from sage.rings.all import is_MPolynomial, is_MPolynomialRing, is_FiniteField
27
28
from sage.structure.all import Sequence
29
30
from sage.schemes.generic.all import (is_AmbientSpace, is_AlgebraicScheme,
31
AffineSpace, ProjectiveSpace)
32
33
34
from projective_curve import (ProjectiveCurve_generic,
35
ProjectiveSpaceCurve_generic,
36
ProjectiveCurve_finite_field,
37
ProjectiveCurve_prime_finite_field)
38
39
from affine_curve import (AffineCurve_generic,
40
AffineSpaceCurve_generic,
41
AffineCurve_finite_field,
42
AffineCurve_prime_finite_field)
43
44
from sage.schemes.plane_conics.constructor import Conic
45
46
def Curve(F):
47
"""
48
Return the plane or space curve defined by `F`, where
49
`F` can be either a multivariate polynomial, a list or
50
tuple of polynomials, or an algebraic scheme.
51
52
If `F` is in two variables the curve is affine, and if it
53
is homogenous in `3` variables, then the curve is
54
projective.
55
56
EXAMPLE: A projective plane curve
57
58
::
59
60
sage: x,y,z = QQ['x,y,z'].gens()
61
sage: C = Curve(x^3 + y^3 + z^3); C
62
Projective Curve over Rational Field defined by x^3 + y^3 + z^3
63
sage: C.genus()
64
1
65
66
EXAMPLE: Affine plane curves
67
68
::
69
70
sage: x,y = GF(7)['x,y'].gens()
71
sage: C = Curve(y^2 + x^3 + x^10); C
72
Affine Curve over Finite Field of size 7 defined by x^10 + x^3 + y^2
73
sage: C.genus()
74
0
75
sage: x, y = QQ['x,y'].gens()
76
sage: Curve(x^3 + y^3 + 1)
77
Affine Curve over Rational Field defined by x^3 + y^3 + 1
78
79
EXAMPLE: A projective space curve
80
81
::
82
83
sage: x,y,z,w = QQ['x,y,z,w'].gens()
84
sage: C = Curve([x^3 + y^3 - z^3 - w^3, x^5 - y*z^4]); C
85
Projective Space Curve over Rational Field defined by x^3 + y^3 - z^3 - w^3, x^5 - y*z^4
86
sage: C.genus()
87
13
88
89
EXAMPLE: An affine space curve
90
91
::
92
93
sage: x,y,z = QQ['x,y,z'].gens()
94
sage: C = Curve([y^2 + x^3 + x^10 + z^7, x^2 + y^2]); C
95
Affine Space Curve over Rational Field defined by x^10 + z^7 + x^3 + y^2, x^2 + y^2
96
sage: C.genus()
97
47
98
99
EXAMPLE: We can also make non-reduced non-irreducible curves.
100
101
::
102
103
sage: x,y,z = QQ['x,y,z'].gens()
104
sage: Curve((x-y)*(x+y))
105
Projective Conic Curve over Rational Field defined by x^2 - y^2
106
sage: Curve((x-y)^2*(x+y)^2)
107
Projective Curve over Rational Field defined by x^4 - 2*x^2*y^2 + y^4
108
109
EXAMPLE: A union of curves is a curve.
110
111
::
112
113
sage: x,y,z = QQ['x,y,z'].gens()
114
sage: C = Curve(x^3 + y^3 + z^3)
115
sage: D = Curve(x^4 + y^4 + z^4)
116
sage: C.union(D)
117
Projective Curve over Rational Field defined by
118
x^7 + x^4*y^3 + x^3*y^4 + y^7 + x^4*z^3 + y^4*z^3 + x^3*z^4 + y^3*z^4 + z^7
119
120
The intersection is not a curve, though it is a scheme.
121
122
::
123
124
sage: X = C.intersection(D); X
125
Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
126
x^3 + y^3 + z^3,
127
x^4 + y^4 + z^4
128
129
Note that the intersection has dimension `0`.
130
131
::
132
133
sage: X.dimension()
134
0
135
sage: I = X.defining_ideal(); I
136
Ideal (x^3 + y^3 + z^3, x^4 + y^4 + z^4) of Multivariate Polynomial Ring in x, y, z over Rational Field
137
138
EXAMPLE: In three variables, the defining equation must be
139
homogeneous.
140
141
If the parent polynomial ring is in three variables, then the
142
defining ideal must be homogeneous.
143
144
::
145
146
sage: x,y,z = QQ['x,y,z'].gens()
147
sage: Curve(x^2+y^2)
148
Projective Conic Curve over Rational Field defined by x^2 + y^2
149
sage: Curve(x^2+y^2+z)
150
Traceback (most recent call last):
151
...
152
TypeError: x^2 + y^2 + z is not a homogeneous polynomial!
153
154
The defining polynomial must always be nonzero::
155
156
sage: P1.<x,y> = ProjectiveSpace(1,GF(5))
157
sage: Curve(0*x)
158
Traceback (most recent call last):
159
...
160
ValueError: defining polynomial of curve must be nonzero
161
"""
162
if is_AlgebraicScheme(F):
163
return Curve(F.defining_polynomials())
164
165
if isinstance(F, (list, tuple)):
166
if len(F) == 1:
167
return Curve(F[0])
168
F = Sequence(F)
169
P = F.universe()
170
if not is_MPolynomialRing(P):
171
raise TypeError, "universe of F must be a multivariate polynomial ring"
172
173
for f in F:
174
if not f.is_homogeneous():
175
A = AffineSpace(P.ngens(), P.base_ring())
176
A._coordinate_ring = P
177
return AffineSpaceCurve_generic(A, F)
178
179
A = ProjectiveSpace(P.ngens()-1, P.base_ring())
180
A._coordinate_ring = P
181
return ProjectiveSpaceCurve_generic(A, F)
182
183
if not is_MPolynomial(F):
184
raise TypeError, "F (=%s) must be a multivariate polynomial"%F
185
186
P = F.parent()
187
k = F.base_ring()
188
if F.parent().ngens() == 2:
189
if F == 0:
190
raise ValueError, "defining polynomial of curve must be nonzero"
191
A2 = AffineSpace(2, P.base_ring())
192
A2._coordinate_ring = P
193
194
if is_FiniteField(k):
195
if k.is_prime_field():
196
return AffineCurve_prime_finite_field(A2, F)
197
else:
198
return AffineCurve_finite_field(A2, F)
199
else:
200
return AffineCurve_generic(A2, F)
201
202
elif F.parent().ngens() == 3:
203
if F == 0:
204
raise ValueError, "defining polynomial of curve must be nonzero"
205
P2 = ProjectiveSpace(2, P.base_ring())
206
P2._coordinate_ring = P
207
208
if F.total_degree() == 2 and k.is_field():
209
return Conic(F)
210
211
if is_FiniteField(k):
212
if k.is_prime_field():
213
return ProjectiveCurve_prime_finite_field(P2, F)
214
else:
215
return ProjectiveCurve_finite_field(P2, F)
216
else:
217
return ProjectiveCurve_generic(P2, F)
218
219
220
else:
221
222
raise TypeError, "Number of variables of F (=%s) must be 2 or 3"%F
223
224
225
226