Ticket #5631: trac_5631_rebased.patch

File trac_5631_rebased.patch, 9.5 KB (added by AlexGhitza, 14 years ago)

apply instead of the previous patch

  • sage/schemes/generic/affine_space.py

    # HG changeset patch
    # User Alexandru Ghitza <aghitza@alum.mit.edu>
    # Date 1239351644 -36000
    # Node ID b1949e0776d6498eaddee808815ffbde94959357
    # Parent  470a0a0e9a2c89bdace62f0d5e2051c43f6b0747
    trac 5631: improve doctest coverage of affine_space.py
    
    diff -r 470a0a0e9a2c -r b1949e0776d6 sage/schemes/generic/affine_space.py
    a b  
    5555
    5656def AffineSpace(n, R=None, names='x'):
    5757    r"""
    58     Return affine space of dimension `n` over the ring
    59     `R`.
     58    Return affine space of dimension `n` over the ring `R`.
    6059   
    6160    EXAMPLES: The dimension and ring can be given in either order.
    6261   
     
    8584        sage: AffineSpace(5, names='x')
    8685        Affine Space of dimension 5 over Integer Ring
    8786   
    88     There is also an affine space associated each polynomial ring.
     87    There is also an affine space associated to each polynomial ring.
    8988   
    9089    ::
    9190   
     
    158157        Affine Space of dimension 0 over Integer Ring
    159158    """
    160159    def __init__(self, n, R, names):
     160        """
     161        EXAMPLES::
     162
     163            sage: AffineSpace(3, Zp(5), 'y')
     164            Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20
     165        """
    161166        names = normalize_names(n, names)
    162167        ambient_space.AmbientSpace.__init__(self, n, R)
    163168        self._assign_names(names)
     
    204209                i += 1
    205210           
    206211    def ngens(self):
     212        """
     213        Return the number of generators of self, i.e. the number of
     214        variables in the coordinate ring of self.
     215
     216        EXAMPLES::
     217
     218            sage: AffineSpace(3, QQ).ngens()
     219            3
     220            sage: AffineSpace(7, ZZ).ngens()
     221            7
     222        """
    207223        return self.dimension_relative()
    208224
    209225    def rational_points(self, F=None):
     226        """
     227        Return the list of `F`-rational points on the affine space self,
     228        where `F` is a given finite field, or the base ring of self.
     229
     230        EXAMPLES::
     231
     232            sage: A = AffineSpace(1, GF(3))
     233            sage: A.rational_points()
     234            [(0), (1), (2)]
     235            sage: A.rational_points(GF(3^2, 'b'))
     236            [(0), (2*b), (b + 1), (b + 2), (2), (b), (2*b + 2), (2*b + 1), (1)]
     237
     238            sage: AffineSpace(2, ZZ).rational_points(GF(2))
     239            [(0, 0), (1, 0), (0, 1), (1, 1)]
     240
     241        TESTS::
     242           
     243            sage: AffineSpace(2, QQ).rational_points()
     244            Traceback (most recent call last):
     245            ...
     246            TypeError: Base ring (= Rational Field) must be a finite field.
     247            sage: AffineSpace(1, GF(3)).rational_points(ZZ)
     248            Traceback (most recent call last):
     249            ...
     250            TypeError: Second argument (= Integer Ring) must be a finite field.
     251        """
    210252        if F == None:
    211253            if not is_FiniteField(self.base_ring()):
    212254                raise TypeError, "Base ring (= %s) must be a finite field."%self.base_ring()
    213255            return [ P for P in self ]
    214256        elif not is_FiniteField(F):
    215257            raise TypeError, "Second argument (= %s) must be a finite field."%F
    216         return [ P for P in self(F) ]
     258        return [ P for P in self.base_extend(F) ]
    217259
    218260    def _point_morphism_class(self, *args, **kwds):
    219261        return morphism.SchemeMorphism_on_points_affine_space(*args, **kwds)
     
    236278
    237279    def _latex_(self):
    238280        r"""
     281        Return a LaTeX representation of this affine space.
     282
    239283        EXAMPLES::
    240284       
    241285            sage: print latex(AffineSpace(1, ZZ, 'x'))
    242286            \mathbf{A}_{\mathbf{Z}}^1
     287
     288        TESTS::
     289
     290            sage: AffineSpace(3, Zp(5), 'y')._latex_()
     291            '\\mathbf{A}_{\\mathbf{Z}_{5}}^3'
    243292        """
    244293        return "\\mathbf{A}_{%s}^%s"%(latex(self.base_ring()), self.dimension_relative())
    245294   
     
    253302        return morphism.SchemeMorphism_affine_coordinates(*args, **kwds)
    254303
    255304    def _repr_(self):
     305        """
     306        Return a string representation of this affine space.
     307
     308        EXAMPLES::
     309       
     310            sage: AffineSpace(1, ZZ, 'x')
     311            Affine Space of dimension 1 over Integer Ring
     312
     313        TESTS::
     314
     315            sage: AffineSpace(3, Zp(5), 'y')._repr_()
     316            'Affine Space of dimension 3 over 5-adic Ring with capped relative precision 20'
     317        """
    256318        return "Affine Space of dimension %s over %s"%(self.dimension_relative(), self.base_ring())
    257319
    258320    def _repr_generic_point(self, polys=None):
     321        """
     322        Return a string representation of the generic point
     323        corresponding to the list of polys on this affine space.
     324
     325        If polys is None, the representation of the generic point of
     326        the affine space is returned.
     327
     328        EXAMPLES::
     329
     330            sage: A.<x, y> = AffineSpace(2, ZZ)
     331            sage: A._repr_generic_point([y-x^2])
     332            '(-x^2 + y)'
     333            sage: A._repr_generic_point()
     334            '(x, y)'
     335        """
    259336        if polys is None:
    260337            polys = self.gens()
    261338        return '(%s)'%(", ".join([str(f) for f in polys]))
    262339
    263340    def _latex_generic_point(self, v=None):
     341        """
     342        Return a LaTeX representation of the generic point
     343        corresponding to the list of polys on this affine space.
     344
     345        If polys is None, the representation of the generic point of
     346        the affine space is returned.
     347
     348        EXAMPLES::
     349
     350            sage: A.<x, y> = AffineSpace(2, ZZ)
     351            sage: A._latex_generic_point([y-x^2])
     352            '\\left(- x^{2} + y\\right)'
     353            sage: A._latex_generic_point()
     354            '\\left(x, y\\right)'
     355        """
    264356        if v is None:
    265357            v = self.gens()
    266358        return '\\left(%s\\right)'%(", ".join([str(latex(f)) for f in v]))
     
    280372   
    281373    def coordinate_ring(self):
    282374        """
    283         Return the coordinate ring of this scheme, if defined. Otherwise
    284         raise a ValueError.
     375        Return the coordinate ring of this scheme, if defined.
    285376       
    286377        EXAMPLES::
    287378       
     
    410501            0
    411502        """
    412503        return algebraic_scheme.AlgebraicScheme_subscheme_affine(self, X)
    413 
    414     def subscheme_complement(self, X, Y):
    415         X = self.subscheme(X)
    416         Y = self.subscheme(Y)
    417         return algebraic_scheme.AlgebraicScheme_quasi(X, Y)
  • sage/schemes/generic/algebraic_scheme.py

    diff -r 470a0a0e9a2c -r b1949e0776d6 sage/schemes/generic/algebraic_scheme.py
    a b  
    195195    """
    196196    An algebraic scheme presented as a closed subscheme is defined by
    197197    explicit polynomial equations. This is as opposed to a general
    198     scheme, which could, e.g., by the Neron model of some object, and
     198    scheme, which could, e.g., be the Neron model of some object, and
    199199    for which we do not want to give explicit equations.
    200200   
    201201    INPUT:
     
    427427            raise ValueError, "other (=%s) must be in the same ambient space as self"%other
    428428        return A.subscheme(self.defining_ideal() + other.defining_ideal())
    429429
    430     def exclude(self, other):
     430
     431    def complement(self, other):
    431432        """
    432         Return the scheme-theoretic complement self - other.
    433        
    434         EXAMPLES: HERE
     433        Return the scheme-theoretic complement self - other, where
     434        self and other are both closed algebraic subschemes of the
     435        same ambient space.
     436        EXAMPLES::
     437
     438            sage: A.<x, y, z> = AffineSpace(3, ZZ)
     439            sage: X = A.subscheme([x+y-z])
     440            sage: Y = A.subscheme([x-y+z])
     441            sage: X.complement(Y)
     442            Quasi-affine scheme X - Y, where:
     443              X: Closed subscheme of Affine Space of dimension 3 over Integer Ring defined by:
     444              x + y - z
     445              Y: Closed subscheme of Affine Space of dimension 3 over Integer Ring defined by:
     446              x - y + z
     447
     448            sage: P.<x, y, z> = ProjectiveSpace(2, QQ)
     449            sage: X = P.subscheme([x^2+y^2+z^2])
     450            sage: Y = P.subscheme([x*y+y*z+z*x])
     451            sage: X.complement(Y)
     452            Quasi-projective scheme X - Y, where:
     453              X: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
     454              x^2 + y^2 + z^2
     455              Y: Closed subscheme of Projective Space of dimension 2 over Rational Field defined by:
     456              x*y + x*z + y*z
    435457        """
    436458        if not isinstance(other, AlgebraicScheme_subscheme):
    437459            raise TypeError, \
     
    439461        A = self.ambient_space()
    440462        if other.ambient_space() != A:
    441463            raise ValueError, "other (=%s) must be in the same ambient space as self"%other
    442         return A.subscheme_complement(
    443             self.defining_ideal(), self.defining_ideal() + other.defining_ideal())
     464        return AlgebraicScheme_quasi(self, other)
    444465
    445466    def rational_points(self, F=None, bound=0):
    446467        """
  • sage/schemes/generic/projective_space.py

    diff -r 470a0a0e9a2c -r b1949e0776d6 sage/schemes/generic/projective_space.py
    a b  
    299299        """
    300300        return algebraic_scheme.AlgebraicScheme_subscheme_projective(self, X)
    301301
    302     def subscheme_complement(self, X, Y):
    303         return algebraic_scheme.AlgebraicScheme_quasi(self, X, Y)
    304 
    305302    def affine_patch(self, i):
    306303        r"""
    307304        Return the `i^{th}` affine patch of this projective space.