Path: blob/master/src/sage/schemes/generic/ambient_space.py
8820 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, ZZ13from sage.rings.commutative_ring import is_CommutativeRing1415from sage.schemes.generic.scheme import Scheme1617def is_AmbientSpace(x):18"""19Return True if `x` is an ambient space.2021EXAMPLES::2223sage: from sage.schemes.generic.ambient_space import is_AmbientSpace24sage: is_AmbientSpace(ProjectiveSpace(3, ZZ))25True26sage: is_AmbientSpace(AffineSpace(2, QQ))27True28sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)29sage: is_AmbientSpace(P.subscheme([x+y+z]))30False31"""32return isinstance(x, AmbientSpace)3334class AmbientSpace(Scheme):35"""36Base class for ambient spaces over a ring.3738INPUT:394041- ``n`` - dimension4243- ``R`` - ring44"""45def __init__(self, n, R=ZZ):46"""47TEST::4849sage: from sage.schemes.generic.ambient_space import AmbientSpace50sage: A = AmbientSpace(5, ZZ)51sage: TestSuite(A).run() # not tested (abstract scheme with no elements?)52"""53if not is_CommutativeRing(R):54raise TypeError, "R (=%s) must be a commutative ring"%R55n = Integer(n)56if n < 0:57raise ValueError, "n (=%s) must be nonnegative"%n58self._dimension_relative = n59Scheme.__init__(self, R)6061# NT: this seems to set improperly self._base_scheme to X instead of Spec(X)????62# scheme.Scheme.__init__(self, R)63# This should be cleaned up by someone who knows about schemes (not me!)64#from sage.categories.schemes import Schemes65#Parent.__init__(self, R, category = Schemes(self.base_scheme()))6667#######################################################################68# Derived classes must overload all of the following functions69#######################################################################70def __cmp__(self, right):71"""72TEST::7374sage: from sage.schemes.generic.ambient_space import AmbientSpace75sage: A = AmbientSpace(5, ZZ)76sage: A.__cmp__(ProjectiveSpace(2, QQ))77Traceback (most recent call last):78...79NotImplementedError80"""81raise NotImplementedError8283def _latex_(self):84"""85TEST::8687sage: from sage.schemes.generic.ambient_space import AmbientSpace88sage: A = AmbientSpace(5, ZZ)89sage: A._latex_()90Traceback (most recent call last):91...92NotImplementedError93"""94raise NotImplementedError9596def _repr_(self):97"""98TEST::99100sage: from sage.schemes.generic.ambient_space import AmbientSpace101sage: A = AmbientSpace(5, ZZ)102sage: A._repr_()103Traceback (most recent call last):104...105NotImplementedError106"""107raise NotImplementedError108109def _repr_generic_point(self, coords=None):110"""111TEST::112113sage: from sage.schemes.generic.ambient_space import AmbientSpace114sage: A = AmbientSpace(5, ZZ)115sage: A._repr_generic_point([1, 2, 3, 4, 5])116Traceback (most recent call last):117...118NotImplementedError119"""120raise NotImplementedError121122def _latex_generic_point(self, coords=None):123"""124TEST::125126sage: from sage.schemes.generic.ambient_space import AmbientSpace127sage: A = AmbientSpace(5, ZZ)128sage: A._latex_generic_point([1, 2, 3, 4, 5])129Traceback (most recent call last):130...131NotImplementedError132"""133raise NotImplementedError134135def _check_satisfies_equations(self, v):136"""137Verify that the coordinates of v define a point on this scheme, or138raise a TypeError.139140TEST::141142sage: from sage.schemes.generic.ambient_space import AmbientSpace143sage: A = AmbientSpace(5, ZZ)144sage: A._check_satisfies_equations([1, 2, 3, 4, 5])145Traceback (most recent call last):146...147NotImplementedError148"""149raise NotImplementedError150151def _validate(self, polynomials):152"""153If ``polynomials`` is a tuple of valid polynomial functions on self,154return ``polynomials``, otherwise raise TypeError.155156INPUT:157158- ``polynomials`` -- tuple of polynomials in the coordinate ring of159self160161OUTPUT:162163- tuple of polynomials in the coordinate ring of self164165TESTS::166167sage: from sage.schemes.generic.ambient_space import AmbientSpace168sage: A = AmbientSpace(3, ZZ)169sage: A._validate((x + 1, 1))170Traceback (most recent call last):171...172NotImplementedError: ambient spaces must override "_validate" method!173"""174raise NotImplementedError('ambient spaces must override "_validate" '175'method!')176177def change_ring(self, R):178r"""179Return an ambient space over ring `R` and otherwise the same as self.180181INPUT:182183- ``R`` -- commutative ring184185OUTPUT:186187- ambient space over ``R``188189.. NOTE::190191There is no need to have any relation between `R` and the base ring192of self, if you want to have such a relation, use193``self.base_extend(R)`` instead.194195TESTS::196197sage: from sage.schemes.generic.ambient_space import AmbientSpace198sage: A = AmbientSpace(5)199sage: A.change_ring(QQ)200Traceback (most recent call last):201...202NotImplementedError: ambient spaces must override "change_ring" method!203"""204raise NotImplementedError(205'ambient spaces must override "change_ring" method!')206207#######################################################################208# End overloads209#######################################################################210211def is_projective(self):212"""213Return whether this ambient space is projective n-space.214215EXAMPLES::216217sage: AffineSpace(3,QQ).is_projective()218False219sage: ProjectiveSpace(3,QQ).is_projective()220True221"""222# overloaded in the projective space derived class223return False224225def base_extend(self, R):226"""227Return the natural extension of ``self`` over ``R``.228229INPUT:230231- ``R`` -- a commutative ring, such that there is a natural map from232the base ring of self to ``R``.233234OUTPUT:235236- an ambient space over ``R`` of the same structure as ``self``.237238.. NOTE::239240A ``ValueError`` is raised if there is no such natural map. If241you need to drop this condition, use ``self.change_ring(R)``.242243EXAMPLES::244245sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)246sage: PQ = P.base_extend(QQ); PQ247Projective Space of dimension 2 over Rational Field248sage: PQ.base_extend(GF(5))249Traceback (most recent call last):250...251ValueError: no natural map from the base ring (=Rational Field)252to R (=Finite Field of size 5)!253"""254if is_CommutativeRing(R):255if self.base_ring() == R:256return self257if not R.has_coerce_map_from(self.base_ring()):258raise ValueError(259"no natural map from the base ring (=%s) to R (=%s)!"260% (self.base_ring(), R))261return self.change_ring(R)262else:263raise NotImplementedError(264"extension of spaces over %s to %s is not implemented!"265% (self.base_ring(), R))266267def ambient_space(self):268"""269Return the ambient space of the scheme self, in this case self270itself.271272EXAMPLES::273274sage: P = ProjectiveSpace(4, ZZ)275sage: P.ambient_space() is P276True277278sage: A = AffineSpace(2, GF(3))279sage: A.ambient_space()280Affine Space of dimension 2 over Finite Field of size 3281"""282return self283284def defining_polynomials(self):285"""286Return the defining polynomials of the scheme self. Since287self is an ambient space, this is an empty list.288289EXAMPLES::290291sage: ProjectiveSpace(2, QQ).defining_polynomials()292()293sage: AffineSpace(0, ZZ).defining_polynomials()294()295"""296return ()297298######################################################################299# Associated MPolynomial ring generators300######################################################################301302def gen(self, n=0):303"""304Return the `n`-th generator of the coordinate ring of the305scheme self.306307EXAMPLES::308309sage: P.<x, y, z> = ProjectiveSpace(2, ZZ)310sage: P.gen(1)311y312"""313return self.coordinate_ring().gen(n)314315def gens(self):316"""317Return the generators of the coordinate ring of the scheme318self.319320EXAMPLES::321322sage: AffineSpace(0, QQ).gens()323()324325sage: P.<x, y, z> = ProjectiveSpace(2, GF(5))326sage: P.gens()327(x, y, z)328"""329return self.coordinate_ring().gens()330331def ngens(self):332"""333Return the number of generators of the coordinate ring of the334scheme self.335336EXAMPLES::337338sage: AffineSpace(0, QQ).ngens()3390340341sage: ProjectiveSpace(50, ZZ).ngens()34251343"""344return len(self.gens())345346## def assign_names(self, names=None):347## """348## EXAMPLES:349## sage: A = AffineSpace(2, QQ, 'ab'); A350## Affine Space of dimension 2 over Rational Field351## sage: A.coordinate_ring()352## Polynomial Ring in a, b over Rational Field353## sage: A._assign_names('xy'); A.coordinate_ring()354## Polynomial Ring in x, y over Rational Field355## """356## self.coordinate_ring()._assign_names(names)357358def dimension_absolute(self):359"""360Return the absolute dimension of this scheme.361362EXAMPLES::363364sage: A2Q = AffineSpace(2, QQ)365sage: A2Q.dimension_absolute()3662367sage: A2Q.dimension()3682369sage: A2Z = AffineSpace(2, ZZ)370sage: A2Z.dimension_absolute()3713372sage: A2Z.dimension()3733374"""375base = self.base_scheme()376if base.is_noetherian():377return self.dimension_relative() + base.dimension()378raise NotImplementedError, "Cannot compute the dimension of this scheme."379380dimension = dimension_absolute381382def dimension_relative(self):383"""384Return the relative dimension of this scheme over its base.385386EXAMPLES::387388sage: A2Q = AffineSpace(2, QQ)389sage: A2Q.dimension_relative()3902391sage: A2Z = AffineSpace(2, ZZ)392sage: A2Z.dimension_relative()3932394"""395return self._dimension_relative396397398