# Ticket #5631: trac_5631.patch

File trac_5631.patch, 9.5 KB (added by AlexGhitza, 14 years ago)
• ## sage/schemes/generic/affine_space.py

# HG changeset patch
# User Alexandru Ghitza <aghitza@alum.mit.edu>
# Date 1238316080 -39600
# Node ID 4b7a0f0c1793faea17cd8b78645e270cca86e886
# Parent  5c72dbb92d8284101858a5e6f2b476a56e597e14
trac 5631: improve doctest coverage of affine_space.py

diff -r 5c72dbb92d82 -r 4b7a0f0c1793 sage/schemes/generic/affine_space.py
 a def AffineSpace(n, R=None, names='x'): r""" Return affine space of dimension n over the ring R. Return affine space of dimension n over the ring R. EXAMPLES: The dimension and ring can be given in either order. sage: AffineSpace(5, names='x') Affine Space of dimension 5 over Integer Ring There is also an affine space associated each polynomial ring. There is also an affine space associated to each polynomial ring. :: Affine Space of dimension 0 over Integer Ring """ def __init__(self, n, R, names): """ EXAMPLES:: sage: AffineSpace(3, Zp(5), 'y') Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20 """ names = normalize_names(n, names) ambient_space.AmbientSpace.__init__(self, n, R) self._assign_names(names) i += 1 def ngens(self): """ Return the number of generators of self, i.e. the number of variables in the coordinate ring of self. EXAMPLES:: sage: AffineSpace(3, QQ).ngens() 3 sage: AffineSpace(7, ZZ).ngens() 7 """ return self.dimension() def rational_points(self, F=None): """ Return the list of F-rational points on the affine space self, where F is a given finite field, or the base ring of self. EXAMPLES:: sage: A = AffineSpace(1, GF(3)) sage: A.rational_points() [(0), (1), (2)] sage: A.rational_points(GF(3^2, 'b')) [(0), (2*b), (b + 1), (b + 2), (2), (b), (2*b + 2), (2*b + 1), (1)] sage: AffineSpace(2, ZZ).rational_points(GF(2)) [(0, 0), (1, 0), (0, 1), (1, 1)] TESTS:: sage: AffineSpace(2, QQ).rational_points() Traceback (most recent call last): ... TypeError: Base ring (= Rational Field) must be a finite field. sage: AffineSpace(1, GF(3)).rational_points(ZZ) Traceback (most recent call last): ... TypeError: Second argument (= Integer Ring) must be a finite field. """ if F == None: if not is_FiniteField(self.base_ring()): raise TypeError, "Base ring (= %s) must be a finite field."%self.base_ring() return [ P for P in self ] elif not is_FiniteField(F): raise TypeError, "Second argument (= %s) must be a finite field."%F return [ P for P in self(F) ] return [ P for P in self.base_extend(F) ] def _point_morphism_class(self, *args, **kwds): return morphism.SchemeMorphism_on_points_affine_space(*args, **kwds) def _latex_(self): r""" Return a LaTeX representation of this affine space. EXAMPLES:: sage: print latex(AffineSpace(1, ZZ, 'x')) \mathbf{A}_{\mathbf{Z}}^1 TESTS:: sage: AffineSpace(3, Zp(5), 'y')._latex_() '\\mathbf{A}_{\\mathbf{Z}_{5}}^3' """ return "\\mathbf{A}_{%s}^%s"%(latex(self.base_ring()), self.dimension()) return morphism.SchemeMorphism_affine_coordinates(*args, **kwds) def _repr_(self): """ Return a string representation of this affine space. EXAMPLES:: sage: AffineSpace(1, ZZ, 'x') Affine Space of dimension 1 over Integer Ring TESTS:: sage: AffineSpace(3, Zp(5), 'y')._repr_() 'Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20' """ return "Affine Space of dimension %s over %s"%(self.dimension(), self.base_ring()) def _repr_generic_point(self, polys=None): """ Return a string representation of the generic point corresponding to the list of polys on this affine space. If polys is None, the representation of the generic point of the affine space is returned. EXAMPLES:: sage: A. = AffineSpace(2, ZZ) sage: A._repr_generic_point([y-x^2]) '(-x^2 + y)' sage: A._repr_generic_point() '(x, y)' """ if polys is None: polys = self.gens() return '(%s)'%(", ".join([str(f) for f in polys])) def _latex_generic_point(self, v=None): """ Return a LaTeX representation of the generic point corresponding to the list of polys on this affine space. If polys is None, the representation of the generic point of the affine space is returned. EXAMPLES:: sage: A. = AffineSpace(2, ZZ) sage: A._latex_generic_point([y-x^2]) '\\left(- x^{2} + y\\right)' sage: A._latex_generic_point() '\\left(x, y\\right)' """ if v is None: v = self.gens() return '\\left(%s\\right)'%(", ".join([str(latex(f)) for f in v])) def coordinate_ring(self): """ Return the coordinate ring of this scheme, if defined. Otherwise raise a ValueError. Return the coordinate ring of this scheme, if defined. EXAMPLES:: """ return algebraic_scheme.AlgebraicScheme_subscheme_affine(self, X) def subscheme_complement(self, X, Y): X = self.subscheme(X) Y = self.subscheme(Y) return algebraic_scheme.AlgebraicScheme_quasi(X, Y)
• ## sage/schemes/generic/algebraic_scheme.py

diff -r 5c72dbb92d82 -r 4b7a0f0c1793 sage/schemes/generic/algebraic_scheme.py
 a """ An algebraic scheme presented as a closed subscheme is defined by explicit polynomial equations. This is as opposed to a general scheme, which could, e.g., by the Neron model of some object, and scheme, which could, e.g., be the Neron model of some object, and for which we do not want to give explicit equations. INPUT: raise ValueError, "other (=%s) must be in the same ambient space as self"%other return A.subscheme(self.defining_ideal() + other.defining_ideal()) def exclude(self, other): def complement(self, other): """ Return the scheme-theoretic complement self - other. Return the scheme-theoretic complement self - other, where self and other are both closed algebraic subschemes of the same ambient space. EXAMPLES: HERE EXAMPLES:: sage: A. = AffineSpace(3, ZZ) sage: X = A.subscheme([x+y-z]) sage: Y = A.subscheme([x-y+z]) sage: X.complement(Y) Quasi-affine scheme X - Y, where: X: Closed subscheme of Affine Space of dimension 3 over Integer Ring defined by: x + y - z Y: Closed subscheme of Affine Space of dimension 3 over Integer Ring defined by: x - y + z sage: P. = ProjectiveSpace(2, QQ) sage: X = P.subscheme([x^2+y^2+z^2]) sage: Y = P.subscheme([x*y+y*z+z*x]) sage: X.complement(Y) Quasi-projective scheme X - Y, where: X: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by: x^2 + y^2 + z^2 Y: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by: x*y + x*z + y*z """ if not isinstance(other, AlgebraicScheme_subscheme): raise TypeError, \ A = self.ambient_space() if other.ambient_space() != A: raise ValueError, "other (=%s) must be in the same ambient space as self"%other return A.subscheme_complement( self.defining_ideal(), self.defining_ideal() + other.defining_ideal()) return AlgebraicScheme_quasi(self, other) def rational_points(self, F=None, bound=0): """
• ## sage/schemes/generic/projective_space.py

diff -r 5c72dbb92d82 -r 4b7a0f0c1793 sage/schemes/generic/projective_space.py
 a """ return algebraic_scheme.AlgebraicScheme_subscheme_projective(self, X) def subscheme_complement(self, X, Y): return algebraic_scheme.AlgebraicScheme_quasi(self, X, Y) def affine_patch(self, i): r""" Return the i^{th} affine patch of this projective space.