Path: blob/master/src/sage/schemes/plane_curves/constructor.py
8820 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.polynomial.multi_polynomial_element import is_MPolynomial26from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing27from sage.rings.finite_rings.constructor import is_FiniteField2829from sage.structure.all import Sequence3031from sage.schemes.generic.all import (is_AmbientSpace, is_AlgebraicScheme)3233from sage.schemes.affine.all import AffineSpace3435from sage.schemes.projective.all import ProjectiveSpace363738from projective_curve import (ProjectiveCurve_generic,39ProjectiveSpaceCurve_generic,40ProjectiveCurve_finite_field,41ProjectiveCurve_prime_finite_field)4243from affine_curve import (AffineCurve_generic,44AffineSpaceCurve_generic,45AffineCurve_finite_field,46AffineCurve_prime_finite_field)4748from sage.schemes.plane_conics.constructor import Conic4950def Curve(F):51"""52Return the plane or space curve defined by `F`, where53`F` can be either a multivariate polynomial, a list or54tuple of polynomials, or an algebraic scheme.5556If `F` is in two variables the curve is affine, and if it57is homogenous in `3` variables, then the curve is58projective.5960EXAMPLE: A projective plane curve6162::6364sage: x,y,z = QQ['x,y,z'].gens()65sage: C = Curve(x^3 + y^3 + z^3); C66Projective Curve over Rational Field defined by x^3 + y^3 + z^367sage: C.genus()6816970EXAMPLE: Affine plane curves7172::7374sage: x,y = GF(7)['x,y'].gens()75sage: C = Curve(y^2 + x^3 + x^10); C76Affine Curve over Finite Field of size 7 defined by x^10 + x^3 + y^277sage: C.genus()78079sage: x, y = QQ['x,y'].gens()80sage: Curve(x^3 + y^3 + 1)81Affine Curve over Rational Field defined by x^3 + y^3 + 18283EXAMPLE: A projective space curve8485::8687sage: x,y,z,w = QQ['x,y,z,w'].gens()88sage: C = Curve([x^3 + y^3 - z^3 - w^3, x^5 - y*z^4]); C89Projective Space Curve over Rational Field defined by x^3 + y^3 - z^3 - w^3, x^5 - y*z^490sage: C.genus()91139293EXAMPLE: An affine space curve9495::9697sage: x,y,z = QQ['x,y,z'].gens()98sage: C = Curve([y^2 + x^3 + x^10 + z^7, x^2 + y^2]); C99Affine Space Curve over Rational Field defined by x^10 + z^7 + x^3 + y^2, x^2 + y^2100sage: C.genus()10147102103EXAMPLE: We can also make non-reduced non-irreducible curves.104105::106107sage: x,y,z = QQ['x,y,z'].gens()108sage: Curve((x-y)*(x+y))109Projective Conic Curve over Rational Field defined by x^2 - y^2110sage: Curve((x-y)^2*(x+y)^2)111Projective Curve over Rational Field defined by x^4 - 2*x^2*y^2 + y^4112113EXAMPLE: A union of curves is a curve.114115::116117sage: x,y,z = QQ['x,y,z'].gens()118sage: C = Curve(x^3 + y^3 + z^3)119sage: D = Curve(x^4 + y^4 + z^4)120sage: C.union(D)121Projective Curve over Rational Field defined by122x^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^7123124The intersection is not a curve, though it is a scheme.125126::127128sage: X = C.intersection(D); X129Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:130x^3 + y^3 + z^3,131x^4 + y^4 + z^4132133Note that the intersection has dimension `0`.134135::136137sage: X.dimension()1380139sage: I = X.defining_ideal(); I140Ideal (x^3 + y^3 + z^3, x^4 + y^4 + z^4) of Multivariate Polynomial Ring in x, y, z over Rational Field141142EXAMPLE: In three variables, the defining equation must be143homogeneous.144145If the parent polynomial ring is in three variables, then the146defining ideal must be homogeneous.147148::149150sage: x,y,z = QQ['x,y,z'].gens()151sage: Curve(x^2+y^2)152Projective Conic Curve over Rational Field defined by x^2 + y^2153sage: Curve(x^2+y^2+z)154Traceback (most recent call last):155...156TypeError: x^2 + y^2 + z is not a homogeneous polynomial!157158The defining polynomial must always be nonzero::159160sage: P1.<x,y> = ProjectiveSpace(1,GF(5))161sage: Curve(0*x)162Traceback (most recent call last):163...164ValueError: defining polynomial of curve must be nonzero165"""166if is_AlgebraicScheme(F):167return Curve(F.defining_polynomials())168169if isinstance(F, (list, tuple)):170if len(F) == 1:171return Curve(F[0])172F = Sequence(F)173P = F.universe()174if not is_MPolynomialRing(P):175raise TypeError, "universe of F must be a multivariate polynomial ring"176177for f in F:178if not f.is_homogeneous():179A = AffineSpace(P.ngens(), P.base_ring())180A._coordinate_ring = P181return AffineSpaceCurve_generic(A, F)182183A = ProjectiveSpace(P.ngens()-1, P.base_ring())184A._coordinate_ring = P185return ProjectiveSpaceCurve_generic(A, F)186187if not is_MPolynomial(F):188raise TypeError, "F (=%s) must be a multivariate polynomial"%F189190P = F.parent()191k = F.base_ring()192if F.parent().ngens() == 2:193if F == 0:194raise ValueError, "defining polynomial of curve must be nonzero"195A2 = AffineSpace(2, P.base_ring())196A2._coordinate_ring = P197198if is_FiniteField(k):199if k.is_prime_field():200return AffineCurve_prime_finite_field(A2, F)201else:202return AffineCurve_finite_field(A2, F)203else:204return AffineCurve_generic(A2, F)205206elif F.parent().ngens() == 3:207if F == 0:208raise ValueError, "defining polynomial of curve must be nonzero"209P2 = ProjectiveSpace(2, P.base_ring())210P2._coordinate_ring = P211212if F.total_degree() == 2 and k.is_field():213return Conic(F)214215if is_FiniteField(k):216if k.is_prime_field():217return ProjectiveCurve_prime_finite_field(P2, F)218else:219return ProjectiveCurve_finite_field(P2, F)220else:221return ProjectiveCurve_generic(P2, F)222223224else:225226raise TypeError, "Number of variables of F (=%s) must be 2 or 3"%F227228229230231