Path: blob/master/sage/schemes/plane_curves/constructor.py
4097 views
"""1Plane curve constructors23AUTHORS:45- William Stein (2005-11-13)67- David Kohel (2006-01)8"""910#*****************************************************************************11# Copyright (C) 2005 William Stein <[email protected]>12#13# Distributed under the terms of the GNU General Public License (GPL)14#15# This code is distributed in the hope that it will be useful,16# but WITHOUT ANY WARRANTY; without even the implied warranty of17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU18# General Public License for more details.19#20# The full text of the GPL is available at:21#22# http://www.gnu.org/licenses/23#*****************************************************************************2425from sage.rings.all import is_MPolynomial, is_MPolynomialRing, is_FiniteField2627from sage.structure.all import Sequence2829from sage.schemes.generic.all import (is_AmbientSpace, is_AlgebraicScheme,30AffineSpace, ProjectiveSpace)313233from projective_curve import (ProjectiveCurve_generic,34ProjectiveSpaceCurve_generic,35ProjectiveCurve_finite_field,36ProjectiveCurve_prime_finite_field)3738from affine_curve import (AffineCurve_generic,39AffineSpaceCurve_generic,40AffineCurve_finite_field,41AffineCurve_prime_finite_field)4243from sage.schemes.plane_conics.constructor import Conic4445def Curve(F):46"""47Return the plane or space curve defined by `F`, where48`F` can be either a multivariate polynomial, a list or49tuple of polynomials, or an algebraic scheme.5051If `F` is in two variables the curve is affine, and if it52is homogenous in `3` variables, then the curve is53projective.5455EXAMPLE: A projective plane curve5657::5859sage: x,y,z = QQ['x,y,z'].gens()60sage: C = Curve(x^3 + y^3 + z^3); C61Projective Curve over Rational Field defined by x^3 + y^3 + z^362sage: C.genus()6316465EXAMPLE: Affine plane curves6667::6869sage: x,y = GF(7)['x,y'].gens()70sage: C = Curve(y^2 + x^3 + x^10); C71Affine Curve over Finite Field of size 7 defined by x^10 + x^3 + y^272sage: C.genus()73074sage: x, y = QQ['x,y'].gens()75sage: Curve(x^3 + y^3 + 1)76Affine Curve over Rational Field defined by x^3 + y^3 + 17778EXAMPLE: A projective space curve7980::8182sage: x,y,z,w = QQ['x,y,z,w'].gens()83sage: C = Curve([x^3 + y^3 - z^3 - w^3, x^5 - y*z^4]); C84Projective Space Curve over Rational Field defined by x^3 + y^3 - z^3 - w^3, x^5 - y*z^485sage: C.genus()86138788EXAMPLE: An affine space curve8990::9192sage: x,y,z = QQ['x,y,z'].gens()93sage: C = Curve([y^2 + x^3 + x^10 + z^7, x^2 + y^2]); C94Affine Space Curve over Rational Field defined by x^10 + z^7 + x^3 + y^2, x^2 + y^295sage: C.genus()96479798EXAMPLE: We can also make non-reduced non-irreducible curves.99100::101102sage: x,y,z = QQ['x,y,z'].gens()103sage: Curve((x-y)*(x+y))104Projective Conic Curve over Rational Field defined by x^2 - y^2105sage: Curve((x-y)^2*(x+y)^2)106Projective Curve over Rational Field defined by x^4 - 2*x^2*y^2 + y^4107108EXAMPLE: A union of curves is a curve.109110::111112sage: x,y,z = QQ['x,y,z'].gens()113sage: C = Curve(x^3 + y^3 + z^3)114sage: D = Curve(x^4 + y^4 + z^4)115sage: C.union(D)116Projective Curve over Rational Field defined by117x^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^7118119The intersection is not a curve, though it is a scheme.120121::122123sage: X = C.intersection(D); X124Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:125x^3 + y^3 + z^3,126x^4 + y^4 + z^4127128Note that the intersection has dimension `0`.129130::131132sage: X.dimension()1330134sage: I = X.defining_ideal(); I135Ideal (x^3 + y^3 + z^3, x^4 + y^4 + z^4) of Multivariate Polynomial Ring in x, y, z over Rational Field136137EXAMPLE: In three variables, the defining equation must be138homogeneous.139140If the parent polynomial ring is in three variables, then the141defining ideal must be homogeneous.142143::144145sage: x,y,z = QQ['x,y,z'].gens()146sage: Curve(x^2+y^2)147Projective Conic Curve over Rational Field defined by x^2 + y^2148sage: Curve(x^2+y^2+z)149Traceback (most recent call last):150...151TypeError: x^2 + y^2 + z is not a homogeneous polynomial!152153The defining polynomial must always be nonzero::154155sage: P1.<x,y> = ProjectiveSpace(1,GF(5))156sage: Curve(0*x)157Traceback (most recent call last):158...159ValueError: defining polynomial of curve must be nonzero160"""161if is_AlgebraicScheme(F):162return Curve(F.defining_polynomials())163164if isinstance(F, (list, tuple)):165if len(F) == 1:166return Curve(F[0])167F = Sequence(F)168P = F.universe()169if not is_MPolynomialRing(P):170raise TypeError, "universe of F must be a multivariate polynomial ring"171172for f in F:173if not f.is_homogeneous():174A = AffineSpace(P.ngens(), P.base_ring())175A._coordinate_ring = P176return AffineSpaceCurve_generic(A, F)177178A = ProjectiveSpace(P.ngens()-1, P.base_ring())179A._coordinate_ring = P180return ProjectiveSpaceCurve_generic(A, F)181182if not is_MPolynomial(F):183raise TypeError, "F (=%s) must be a multivariate polynomial"%F184185P = F.parent()186k = F.base_ring()187if F.parent().ngens() == 2:188if F == 0:189raise ValueError, "defining polynomial of curve must be nonzero"190A2 = AffineSpace(2, P.base_ring())191A2._coordinate_ring = P192193if is_FiniteField(k):194if k.is_prime_field():195return AffineCurve_prime_finite_field(A2, F)196else:197return AffineCurve_finite_field(A2, F)198else:199return AffineCurve_generic(A2, F)200201elif F.parent().ngens() == 3:202if F == 0:203raise ValueError, "defining polynomial of curve must be nonzero"204P2 = ProjectiveSpace(2, P.base_ring())205P2._coordinate_ring = P206207if F.total_degree() == 2 and k.is_field():208return Conic(F)209210if is_FiniteField(k):211if k.is_prime_field():212return ProjectiveCurve_prime_finite_field(P2, F)213else:214return ProjectiveCurve_finite_field(P2, F)215else:216return ProjectiveCurve_generic(P2, F)217218219else:220221raise TypeError, "Number of variables of F (=%s) must be 2 or 3"%F222223224225226