Path: blob/master/sage/schemes/generic/hypersurface.py
4100 views
r"""1Hypersurfaces in affine and projective space23AUTHORS:45- William Stein <[email protected]> (2005-12-08)6- David Kohel <[email protected]> (2005-12-08)7- Alex Ghitza <[email protected]> (2009-04-17)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# The full text of the GPL is available at:16#17# http://www.gnu.org/licenses/18#*****************************************************************************1920from sage.rings.all import is_MPolynomial21from algebraic_scheme import AlgebraicScheme_subscheme_projective, AlgebraicScheme_subscheme_affine2223def is_Hypersurface(self):24"""25Return True if self is a hypersurface, i.e. an object of the type26ProjectiveHypersurface or AffineHypersurface.2728EXAMPLES::2930sage: from sage.schemes.generic.hypersurface import is_Hypersurface31sage: R.<x, y, z> = ZZ[]32sage: H = ProjectiveHypersurface(x*z+y^2)33sage: is_Hypersurface(H)34True3536::3738sage: H = AffineHypersurface(x*z+y^2)39sage: is_Hypersurface(H)40True4142::4344sage: H = ProjectiveSpace(QQ, 5)45sage: is_Hypersurface(H)46False47"""48return isinstance(self, (ProjectiveHypersurface, AffineHypersurface))4950class ProjectiveHypersurface(AlgebraicScheme_subscheme_projective):51"""52The projective hypersurface defined by the given polynomial.5354EXAMPLES::5556sage: P.<x, y, z> = ProjectiveSpace(ZZ, 2)57sage: ProjectiveHypersurface(x-y, P)58Projective hypersurface defined by x - y in Projective Space of dimension 2 over Integer Ring5960::6162sage: R.<x, y, z> = QQ[]63sage: ProjectiveHypersurface(x-y)64Projective hypersurface defined by x - y in Projective Space of dimension 2 over Rational Field65"""6667def __init__(self, poly, ambient=None):68"""69Return the projective hypersurface in the space ambient70defined by the polynomial poly.7172If ambient is not given, it will be constructed based on73poly.7475EXAMPLES::7677sage: P.<x, y, z> = ProjectiveSpace(ZZ, 2)78sage: ProjectiveHypersurface(x-y, P)79Projective hypersurface defined by x - y in Projective Space of dimension 2 over Integer Ring8081::8283sage: R.<x, y, z> = QQ[]84sage: ProjectiveHypersurface(x-y)85Projective hypersurface defined by x - y in Projective Space of dimension 2 over Rational Field8687TESTS::8889sage: H = ProjectiveHypersurface(x-y)90sage: H == loads(dumps(H))91True92"""93if not is_MPolynomial(poly):94raise TypeError, \95"Defining polynomial (=%s) must be a multivariate polynomial."%poly96if not poly.is_homogeneous():97raise TypeError, "Defining polynomial (=%s) must be homogeneous."%poly98if ambient == None:99R = poly.parent()100from projective_space import ProjectiveSpace101ambient = ProjectiveSpace(R.base_ring(), R.ngens()-1)102ambient._coordinate_ring = R103AlgebraicScheme_subscheme_projective.__init__(self, ambient, [poly])104105def _repr_(self):106"""107Return a string representation of this projective108hypersurface.109110EXAMPLES::111112sage: R.<x, y, z> = ZZ[]113sage: H = ProjectiveHypersurface(x*z+y^2)114sage: H115Projective hypersurface defined by y^2 + x*z in Projective Space of dimension 2 over Integer Ring116sage: H._repr_()117'Projective hypersurface defined by y^2 + x*z in Projective Space of dimension 2 over Integer Ring'118"""119return "Projective hypersurface defined by %s in %s"%(120self.defining_polynomial(), self.ambient_space())121122def defining_polynomial(self):123"""124Return the polynomial equation that cuts out this projective125hypersurface.126127EXAMPLES::128129sage: R.<x, y, z> = ZZ[]130sage: H = ProjectiveHypersurface(x*z+y^2)131sage: H.defining_polynomial()132y^2 + x*z133"""134return self.defining_polynomials()[0]135136137class AffineHypersurface(AlgebraicScheme_subscheme_affine):138"""139The affine hypersurface defined by the given polynomial.140141EXAMPLES::142143sage: A.<x, y, z> = AffineSpace(ZZ, 3)144sage: AffineHypersurface(x*y-z^3, A)145Affine hypersurface defined by -z^3 + x*y in Affine Space of dimension 3 over Integer Ring146147::148149sage: A.<x, y, z> = QQ[]150sage: AffineHypersurface(x*y-z^3)151Affine hypersurface defined by -z^3 + x*y in Affine Space of dimension 3 over Rational Field152"""153def __init__(self, poly, ambient=None):154"""155Return the affine hypersurface in the space ambient156defined by the polynomial poly.157158If ambient is not given, it will be constructed based on159poly.160161EXAMPLES::162163sage: A.<x, y, z> = AffineSpace(ZZ, 3)164sage: AffineHypersurface(x*y-z^3, A)165Affine hypersurface defined by -z^3 + x*y in Affine Space of dimension 3 over Integer Ring166167::168169sage: A.<x, y, z> = QQ[]170sage: AffineHypersurface(x*y-z^3)171Affine hypersurface defined by -z^3 + x*y in Affine Space of dimension 3 over Rational Field172173TESTS::174175sage: H = AffineHypersurface(x*y-z^3)176sage: H == loads(dumps(H))177True178"""179if not is_MPolynomial(poly):180raise TypeError, "Defining polynomial (= %s) must be a multivariate polynomial"%poly181if ambient == None:182R = poly.parent()183from affine_space import AffineSpace184ambient = AffineSpace(R.base_ring(), R.ngens())185ambient._coordinate_ring = R186AlgebraicScheme_subscheme_affine.__init__(self, ambient, [poly])187188def _repr_(self):189"""190Return a string representation of this affine191hypersurface.192193EXAMPLES::194195sage: R.<x, y, z> = ZZ[]196sage: H = AffineHypersurface(x*z+y^2)197sage: H198Affine hypersurface defined by y^2 + x*z in Affine Space of dimension 3 over Integer Ring199sage: H._repr_()200'Affine hypersurface defined by y^2 + x*z in Affine Space of dimension 3 over Integer Ring'201"""202return "Affine hypersurface defined by %s in %s"%(203self.defining_polynomial(), self.ambient_space())204205def defining_polynomial(self):206"""207Return the polynomial equation that cuts out this affine208hypersurface.209210EXAMPLES::211212sage: R.<x, y, z> = ZZ[]213sage: H = AffineHypersurface(x*z+y^2)214sage: H.defining_polynomial()215y^2 + x*z216"""217return self.defining_polynomials()[0]218219220221222223