From 9cbdab3fdfa24144e1aacdf2b7c29d032f016049 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Sat, 28 May 2016 14:51:24 -0400 Subject: [PATCH 1/3] 20698: revised initialization of generic curves. --- src/sage/schemes/affine/affine_space.py | 18 +++++ src/sage/schemes/plane_curves/affine_curve.py | 1 - src/sage/schemes/plane_curves/constructor.py | 66 +++++++++++++++++-- .../schemes/projective/projective_space.py | 18 +++++ 4 files changed, 97 insertions(+), 6 deletions(-) diff --git a/src/sage/schemes/affine/affine_space.py b/src/sage/schemes/affine/affine_space.py index 1b98542ebf7..1e66c867d3d 100644 --- a/src/sage/schemes/affine/affine_space.py +++ b/src/sage/schemes/affine/affine_space.py @@ -859,6 +859,24 @@ def weil_restriction(self): self.__weil_restriction = X return X + def curve(self,F): + r""" + Return a curve defined by `F` in this affine space. + + INPUT: + + - ``F`` -- a polynomial, or a list or tuple of polynomials in the coorinate ring + of this affine space. + + EXAMPLES:: + + sage: A. = AffineSpace(QQ, 3) + sage: A.curve([y - x^4, z - y^5]) + Affine Space Curve over Rational Field defined by -x^4 + y, -y^5 + z + """ + from sage.schemes.plane_curves.constructor import Curve + return Curve(F, self) + class AffineSpace_finite_field(AffineSpace_field): def _point(self, *args, **kwds): """ diff --git a/src/sage/schemes/plane_curves/affine_curve.py b/src/sage/schemes/plane_curves/affine_curve.py index d080ac7db89..af053e2d91b 100644 --- a/src/sage/schemes/plane_curves/affine_curve.py +++ b/src/sage/schemes/plane_curves/affine_curve.py @@ -48,7 +48,6 @@ def __init__(self, A, X): class AffineCurve_generic(Curve_generic): def __init__(self, A, f): - P = f.parent() if not (is_AffineSpace(A) and A.dimension != 2): raise TypeError("Argument A (= %s) must be an affine plane."%A) Curve_generic.__init__(self, A, [f]) diff --git a/src/sage/schemes/plane_curves/constructor.py b/src/sage/schemes/plane_curves/constructor.py index 43f1dca2fe4..95d698f18ea 100644 --- a/src/sage/schemes/plane_curves/constructor.py +++ b/src/sage/schemes/plane_curves/constructor.py @@ -29,8 +29,10 @@ from sage.structure.all import Sequence +from sage.schemes.affine.affine_space import is_AffineSpace from sage.schemes.generic.ambient_space import is_AmbientSpace from sage.schemes.generic.algebraic_scheme import is_AlgebraicScheme +from sage.schemes.projective.projective_space import is_ProjectiveSpace from sage.schemes.affine.all import AffineSpace @@ -49,15 +51,25 @@ from sage.schemes.plane_conics.constructor import Conic -def Curve(F): +def Curve(F, A=None): """ Return the plane or space curve defined by `F`, where `F` can be either a multivariate polynomial, a list or tuple of polynomials, or an algebraic scheme. - If `F` is in two variables the curve is affine, and if it - is homogenous in `3` variables, then the curve is - projective. + If no ambient space is passed in for `A`, and if `F` is not + an algebraic scheme, a new ambient space is constructed. + + Also not specifying an ambient space will cause the curve to be defined + in either affine or projective space based on properties of `F`. In + particular, if `F` contains a nonhomogenous polynomial, the curve is + affine, and if `F` consists of homogenous polynomials, then the curve + is projective. + + INPUT: + - `F` -- a multivariate polynomial, or a list or tuple of polynomials, + or an algebraic scheme. + - `A` -- (default: None) an ambient space in which to create the curve. EXAMPLE: A projective plane curve @@ -164,9 +176,53 @@ def Curve(F): Traceback (most recent call last): ... ValueError: defining polynomial of curve must be nonzero + + :: + + sage: A. = AffineSpace(QQ, 3) + sage: C = Curve([y - x^2, z - x^3], A) + sage: A == C.ambient_space() + True """ + if not A is None: + if not isinstance(F, (list, tuple)): + return Curve([F], A) + if not is_AmbientSpace(A): + raise TypeError("A (=%s) must be either an affine or projective space"%A) + if not all([f.parent() == A.coordinate_ring() for f in F]): + raise TypeError("F (=%s) must be a list or tuple of polynomials of the coordinate ring of \ + A (=%s)"%(F, A)) + n = A.dimension_relative() + if n < 2: + raise TypeError("A (=%s) must be either an affine or projective space of dimension > 1"%A) + # there is no dimension check when initializing a plane curve, so check here that F is consists + # of a single nonconstant polynomial + if n == 2: + if len(F) != 1 or F[0] == 0 or not is_MPolynomial(F[0]): + raise TypeError("F (=%s) must consist of a single nonconstant polynomial to define a plane curve"%F) + if is_AffineSpace(A): + if n > 2: + return AffineSpaceCurve_generic(A, F) + k = A.base_ring() + if is_FiniteField(k): + if k.is_prime_field(): + return AffineCurve_prime_finite_field(A, F[0]) + return AffineCurve_finite_field(A, F[0]) + return AffineCurve_generic(A, F[0]) + elif is_ProjectiveSpace(A): + if not all([f.is_homogeneous() for f in F]): + raise TypeError("polynomials defining a curve in a projective space must be homogeneous") + if n > 2: + return ProjectiveSpaceCurve_generic(A, F) + k = A.base_ring() + if is_FiniteField(k): + if k.is_prime_field(): + return ProjectiveCurve_prime_finite_field(A, F[0]) + return ProjectiveCurve_finite_field(A, F[0]) + return ProjectiveCurve_generic(A, F[0]) + if is_AlgebraicScheme(F): - return Curve(F.defining_polynomials()) + return Curve(F.defining_polynomials(), F.ambient_space()) if isinstance(F, (list, tuple)): if len(F) == 1: diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index a3468077b9c..a830c2b1aed 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -1167,6 +1167,24 @@ def point_transformation_matrix(self, points_source, points_target): w = v.rational_points() return matrix(r, n+1, n+1, list(w[0])) + def curve(self,F): + r""" + Return a curve defined by `F` in this projective space. + + INPUT: + + - ``F`` -- a polynomial, or a list or tuple of polynomials in the coorinate ring + of this projective space. + + EXAMPLES:: + + sage: P. = ProjectiveSpace(QQ, 2) + sage: P.curve([y^2 - x*z]) + Projective Curve over Rational Field defined by y^2 - x*z + """ + from sage.schemes.plane_curves.constructor import Curve + return Curve(F, self) + class ProjectiveSpace_finite_field(ProjectiveSpace_field): def _point(self, *args, **kwds): """ From b718afabfb2e2233c67aca3ba92cb0150c28e100 Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Sat, 28 May 2016 17:57:46 -0400 Subject: [PATCH 2/3] 20698: documentation and error formatting fixes. --- src/sage/schemes/affine/affine_space.py | 2 +- src/sage/schemes/plane_curves/constructor.py | 28 +++++++++---------- .../schemes/projective/projective_space.py | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/sage/schemes/affine/affine_space.py b/src/sage/schemes/affine/affine_space.py index 1e66c867d3d..09db696631b 100644 --- a/src/sage/schemes/affine/affine_space.py +++ b/src/sage/schemes/affine/affine_space.py @@ -861,7 +861,7 @@ def weil_restriction(self): def curve(self,F): r""" - Return a curve defined by `F` in this affine space. + Return a curve defined by ``F`` in this affine space. INPUT: diff --git a/src/sage/schemes/plane_curves/constructor.py b/src/sage/schemes/plane_curves/constructor.py index 95d698f18ea..c835a38cff9 100644 --- a/src/sage/schemes/plane_curves/constructor.py +++ b/src/sage/schemes/plane_curves/constructor.py @@ -53,23 +53,23 @@ def Curve(F, A=None): """ - Return the plane or space curve defined by `F`, where - `F` can be either a multivariate polynomial, a list or + Return the plane or space curve defined by ``F``, where + ``F`` can be either a multivariate polynomial, a list or tuple of polynomials, or an algebraic scheme. - If no ambient space is passed in for `A`, and if `F` is not + If no ambient space is passed in for ``A``, and if ``F`` is not an algebraic scheme, a new ambient space is constructed. - + Also not specifying an ambient space will cause the curve to be defined - in either affine or projective space based on properties of `F`. In - particular, if `F` contains a nonhomogenous polynomial, the curve is - affine, and if `F` consists of homogenous polynomials, then the curve + in either affine or projective space based on properties of ``F``. In + particular, if ``F`` contains a nonhomogenous polynomial, the curve is + affine, and if ``F`` consists of homogenous polynomials, then the curve is projective. INPUT: - - `F` -- a multivariate polynomial, or a list or tuple of polynomials, - or an algebraic scheme. - - `A` -- (default: None) an ambient space in which to create the curve. + - ``F`` -- a multivariate polynomial, or a list or tuple of polynomials, + or an algebraic scheme. + - ``A`` -- (default: None) an ambient space in which to create the curve. EXAMPLE: A projective plane curve @@ -190,16 +190,16 @@ def Curve(F, A=None): if not is_AmbientSpace(A): raise TypeError("A (=%s) must be either an affine or projective space"%A) if not all([f.parent() == A.coordinate_ring() for f in F]): - raise TypeError("F (=%s) must be a list or tuple of polynomials of the coordinate ring of \ - A (=%s)"%(F, A)) + raise TypeError("F (=%s) must be a list or tuple of polynomials of the coordinate ring of " \ + "A (=%s)"%(F, A)) n = A.dimension_relative() if n < 2: raise TypeError("A (=%s) must be either an affine or projective space of dimension > 1"%A) - # there is no dimension check when initializing a plane curve, so check here that F is consists + # there is no dimension check when initializing a plane curve, so check here that F consists # of a single nonconstant polynomial if n == 2: if len(F) != 1 or F[0] == 0 or not is_MPolynomial(F[0]): - raise TypeError("F (=%s) must consist of a single nonconstant polynomial to define a plane curve"%F) + raise TypeError("F (=%s) must consist of a single nonconstant polynomial to define a plane curve"%(F,)) if is_AffineSpace(A): if n > 2: return AffineSpaceCurve_generic(A, F) diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index a830c2b1aed..fe480ab2171 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -1169,7 +1169,7 @@ def point_transformation_matrix(self, points_source, points_target): def curve(self,F): r""" - Return a curve defined by `F` in this projective space. + Return a curve defined by ``F`` in this projective space. INPUT: From d4eb8d44b2e878582e19eafae0261b0214704a6c Mon Sep 17 00:00:00 2001 From: Grayson Jorgenson Date: Sat, 28 May 2016 21:07:16 -0400 Subject: [PATCH 3/3] 20698: documentation spacing fixes. --- src/sage/schemes/affine/affine_space.py | 2 +- src/sage/schemes/plane_curves/constructor.py | 5 +++-- src/sage/schemes/projective/projective_space.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/schemes/affine/affine_space.py b/src/sage/schemes/affine/affine_space.py index 09db696631b..516d15e63ef 100644 --- a/src/sage/schemes/affine/affine_space.py +++ b/src/sage/schemes/affine/affine_space.py @@ -866,7 +866,7 @@ def curve(self,F): INPUT: - ``F`` -- a polynomial, or a list or tuple of polynomials in the coorinate ring - of this affine space. + of this affine space. EXAMPLES:: diff --git a/src/sage/schemes/plane_curves/constructor.py b/src/sage/schemes/plane_curves/constructor.py index c835a38cff9..7ce6d958955 100644 --- a/src/sage/schemes/plane_curves/constructor.py +++ b/src/sage/schemes/plane_curves/constructor.py @@ -67,8 +67,9 @@ def Curve(F, A=None): is projective. INPUT: - - ``F`` -- a multivariate polynomial, or a list or tuple of polynomials, - or an algebraic scheme. + + - ``F`` -- a multivariate polynomial, or a list or tuple of polynomials, or an algebraic scheme. + - ``A`` -- (default: None) an ambient space in which to create the curve. EXAMPLE: A projective plane curve diff --git a/src/sage/schemes/projective/projective_space.py b/src/sage/schemes/projective/projective_space.py index fe480ab2171..b10c24e7477 100644 --- a/src/sage/schemes/projective/projective_space.py +++ b/src/sage/schemes/projective/projective_space.py @@ -1174,7 +1174,7 @@ def curve(self,F): INPUT: - ``F`` -- a polynomial, or a list or tuple of polynomials in the coorinate ring - of this projective space. + of this projective space. EXAMPLES::