Path: blob/master/sage/schemes/generic/ambient_space.py
4091 views
"""1Ambient Spaces2"""34#*****************************************************************************5# Copyright (C) 2006 William Stein <[email protected]>6#7# Distributed under the terms of the GNU General Public License (GPL)8#9# http://www.gnu.org/licenses/10#*****************************************************************************1112from sage.rings.all import Integer, is_CommutativeRing, ZZ1314from sage.schemes.generic.scheme import Scheme1516def is_AmbientSpace(x):17"""18Return True if `x` is an ambient space.1920EXAMPLES::2122sage: from sage.schemes.generic.ambient_space import is_AmbientSpace23sage: is_AmbientSpace(ProjectiveSpace(3, ZZ))24True25sage: is_AmbientSpace(AffineSpace(2, QQ))26True27sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)28sage: is_AmbientSpace(P.subscheme([x+y+z]))29False30"""31return isinstance(x, AmbientSpace)3233class AmbientSpace(Scheme):34"""35Base class for ambient spaces over a ring.3637INPUT:383940- ``n`` - dimension4142- ``R`` - ring43"""44def __init__(self, n, R=ZZ):45"""46TEST::4748sage: from sage.schemes.generic.ambient_space import AmbientSpace49sage: A = AmbientSpace(5, ZZ)50sage: TestSuite(A).run() # not tested (abstract scheme with no elements?)51"""52if not is_CommutativeRing(R):53raise TypeError, "R (=%s) must be a commutative ring"%R54n = Integer(n)55if n < 0:56raise ValueError, "n (=%s) must be nonnegative"%n57self._dimension_relative = n58Scheme.__init__(self, R)5960# NT: this seems to set improperly self._base_scheme to X instead of Spec(X)????61# scheme.Scheme.__init__(self, R)62# This should be cleaned up by someone who knows about schemes (not me!)63#from sage.categories.schemes import Schemes64#Parent.__init__(self, R, category = Schemes(self.base_scheme()))6566#######################################################################67# Derived classes must overload all of the following functions68#######################################################################69def __cmp__(self, right):70"""71TEST::7273sage: from sage.schemes.generic.ambient_space import AmbientSpace74sage: A = AmbientSpace(5, ZZ)75sage: A.__cmp__(ProjectiveSpace(2, QQ))76Traceback (most recent call last):77...78NotImplementedError79"""80raise NotImplementedError8182def _latex_(self):83"""84TEST::8586sage: from sage.schemes.generic.ambient_space import AmbientSpace87sage: A = AmbientSpace(5, ZZ)88sage: A._latex_()89Traceback (most recent call last):90...91NotImplementedError92"""93raise NotImplementedError9495def _repr_(self):96"""97TEST::9899sage: from sage.schemes.generic.ambient_space import AmbientSpace100sage: A = AmbientSpace(5, ZZ)101sage: A._repr_()102Traceback (most recent call last):103...104NotImplementedError105"""106raise NotImplementedError107108def _repr_generic_point(self, coords=None):109"""110TEST::111112sage: from sage.schemes.generic.ambient_space import AmbientSpace113sage: A = AmbientSpace(5, ZZ)114sage: A._repr_generic_point([1, 2, 3, 4, 5])115Traceback (most recent call last):116...117NotImplementedError118"""119raise NotImplementedError120121def _latex_generic_point(self, coords=None):122"""123TEST::124125sage: from sage.schemes.generic.ambient_space import AmbientSpace126sage: A = AmbientSpace(5, ZZ)127sage: A._latex_generic_point([1, 2, 3, 4, 5])128Traceback (most recent call last):129...130NotImplementedError131"""132raise NotImplementedError133134def _check_satisfies_equations(self, v):135"""136Verify that the coordinates of v define a point on this scheme, or137raise a TypeError.138139TEST::140141sage: from sage.schemes.generic.ambient_space import AmbientSpace142sage: A = AmbientSpace(5, ZZ)143sage: A._check_satisfies_equations([1, 2, 3, 4, 5])144Traceback (most recent call last):145...146NotImplementedError147"""148raise NotImplementedError149150def _validate(self, polynomials):151"""152If ``polynomials`` is a tuple of valid polynomial functions on self,153return ``polynomials``, otherwise raise TypeError.154155INPUT:156157- ``polynomials`` -- tuple of polynomials in the coordinate ring of158self159160OUTPUT:161162- tuple of polynomials in the coordinate ring of self163164TESTS::165166sage: from sage.schemes.generic.ambient_space import AmbientSpace167sage: A = AmbientSpace(3, ZZ)168sage: A._validate((x + 1, 1))169Traceback (most recent call last):170...171NotImplementedError: ambient spaces must override "_validate" method!172"""173raise NotImplementedError('ambient spaces must override "_validate" '174'method!')175176def change_ring(self, R):177r"""178Return an ambient space over ring `R` and otherwise the same as self.179180INPUT:181182- ``R`` -- commutative ring183184OUTPUT:185186- ambient space over ``R``187188.. NOTE::189190There is no need to have any relation between `R` and the base ring191of self, if you want to have such a relation, use192``self.base_extend(R)`` instead.193194TESTS::195196sage: from sage.schemes.generic.ambient_space import AmbientSpace197sage: A = AmbientSpace(5)198sage: A.change_ring(QQ)199Traceback (most recent call last):200...201NotImplementedError: ambient spaces must override "change_ring" method!202"""203raise NotImplementedError(204'ambient spaces must override "change_ring" method!')205206#######################################################################207# End overloads208#######################################################################209210def is_projective(self):211"""212Return whether this ambient space is projective n-space.213214EXAMPLES::215216sage: AffineSpace(3,QQ).is_projective()217False218sage: ProjectiveSpace(3,QQ).is_projective()219True220"""221# overloaded in the projective space derived class222return False223224def base_extend(self, R):225"""226Return the natural extension of ``self`` over ``R``.227228INPUT:229230- ``R`` -- a commutative ring, such that there is a natural map from231the base ring of self to ``R``.232233OUTPUT:234235- an ambient space over ``R`` of the same structure as ``self``.236237.. NOTE::238239A ``ValueError`` is raised if there is no such natural map. If240you need to drop this condition, use ``self.change_ring(R)``.241242EXAMPLES::243244sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)245sage: PQ = P.base_extend(QQ); PQ246Projective Space of dimension 2 over Rational Field247sage: PQ.base_extend(GF(5))248Traceback (most recent call last):249...250ValueError: no natural map from the base ring (=Rational Field)251to R (=Finite Field of size 5)!252"""253if is_CommutativeRing(R):254if self.base_ring() == R:255return self256if not R.has_coerce_map_from(self.base_ring()):257raise ValueError(258"no natural map from the base ring (=%s) to R (=%s)!"259% (self.base_ring(), R))260return self.change_ring(R)261else:262raise NotImplementedError(263"extension of spaces over %s to %s is not implemented!"264% (self.base_ring(), R))265266def ambient_space(self):267"""268Return the ambient space of the scheme self, in this case self269itself.270271EXAMPLES::272273sage: P = ProjectiveSpace(4, ZZ)274sage: P.ambient_space() is P275True276277sage: A = AffineSpace(2, GF(3))278sage: A.ambient_space()279Affine Space of dimension 2 over Finite Field of size 3280"""281return self282283def defining_polynomials(self):284"""285Return the defining polynomials of the scheme self. Since286self is an ambient space, this is an empty list.287288EXAMPLES::289290sage: ProjectiveSpace(2, QQ).defining_polynomials()291()292sage: AffineSpace(0, ZZ).defining_polynomials()293()294"""295return ()296297######################################################################298# Associated MPolynomial ring generators299######################################################################300301def gen(self, n=0):302"""303Return the `n`-th generator of the coordinate ring of the304scheme self.305306EXAMPLES::307308sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)309sage: P.gen(1)310y311"""312return self.coordinate_ring().gen(n)313314def gens(self):315"""316Return the generators of the coordinate ring of the scheme317self.318319EXAMPLES::320321sage: AffineSpace(0, QQ).gens()322()323324sage: P.<x, y, z> = ProjectiveSpace(2, GF(5))325sage: P.gens()326(x, y, z)327"""328return self.coordinate_ring().gens()329330def ngens(self):331"""332Return the number of generators of the coordinate ring of the333scheme self.334335EXAMPLES::336337sage: AffineSpace(0, QQ).ngens()3380339340sage: ProjectiveSpace(50, ZZ).ngens()34151342"""343return len(self.gens())344345## def assign_names(self, names=None):346## """347## EXAMPLES:348## sage: A = AffineSpace(2, QQ, 'ab'); A349## Affine Space of dimension 2 over Rational Field350## sage: A.coordinate_ring()351## Polynomial Ring in a, b over Rational Field352## sage: A._assign_names('xy'); A.coordinate_ring()353## Polynomial Ring in x, y over Rational Field354## """355## self.coordinate_ring()._assign_names(names)356357def dimension_absolute(self):358"""359Return the absolute dimension of this scheme.360361EXAMPLES::362363sage: A2Q = AffineSpace(2, QQ)364sage: A2Q.dimension_absolute()3652366sage: A2Q.dimension()3672368sage: A2Z = AffineSpace(2, ZZ)369sage: A2Z.dimension_absolute()3703371sage: A2Z.dimension()3723373"""374base = self.base_scheme()375if base.is_noetherian():376return self.dimension_relative() + base.dimension()377raise NotImplementedError, "Cannot compute the dimension of this scheme."378379dimension = dimension_absolute380381def dimension_relative(self):382"""383Return the relative dimension of this scheme over its base.384385EXAMPLES::386387sage: A2Q = AffineSpace(2, QQ)388sage: A2Q.dimension_relative()3892390sage: A2Z = AffineSpace(2, ZZ)391sage: A2Z.dimension_relative()3922393"""394return self._dimension_relative395396397