Ticket #11599: trac_11599_homset_new_coercion_model.patch

File trac_11599_homset_new_coercion_model.patch, 148.0 KB (added by vbraun, 10 years ago)

Updated patch

  • doc/en/reference/structure.rst

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1325181309 0
    # Node ID 39cd1100df9bd5631e517807780b926ae263506b
    # Parent  9c4e903d21c02abc03b88cfd00d353c76acb2ef2
    Trac #11599: Port the scheme morphisms / homsets to the
    new parents and coercion model.
    
    diff --git a/doc/en/reference/structure.rst b/doc/en/reference/structure.rst
    a b  
    1111   sage/structure/factorization
    1212   sage/structure/element
    1313   sage/structure/unique_representation
     14   sage/structure/factory
    1415   sage/structure/dynamic_class
    1516   sage/structure/list_clone
    1617   sage/structure/mutability
  • sage/categories/map.pyx

    diff --git a/sage/categories/map.pyx b/sage/categories/map.pyx
    a b  
    9191        sage: f(x^2+2*x-1)
    9292        x^2 + 2*x*y + y^2 + 2*x + 2*y - 1
    9393    """
     94
    9495    def __init__(self, parent, codomain=None):
    9596        """
    9697        INPUT:
     
    158159            sage: f._repr_type_str
    159160            'bla'
    160161        """
     162        # todo: the following can break during unpickling of complex
     163        # objects with circular references! In that case, _slots might
     164        # contain incomplete objects.
    161165        self._domain = _slots['_domain']
    162166        self._codomain = _slots['_codomain']
     167
    163168        # Several pickles exist without a _repr_type_str, so
    164169        # if there is none saved, we just set it to None.
    165170        if _slots.has_key('_repr_type_str'):
  • sage/categories/schemes.py

    diff --git a/sage/categories/schemes.py b/sage/categories/schemes.py
    a b  
    2424        Category of Schemes
    2525
    2626        sage: Schemes(Spec(ZZ))
    27         Category of schemes over Spectrum of Integer Ring
     27        Category of schemes over Integer Ring
    2828
    2929        sage: Schemes(ZZ)
    30         Category of schemes over Spectrum of Integer Ring
     30        Category of schemes over Integer Ring
    3131    """
    3232    if X is None:
    3333        return Schemes_abstract()
    34     from sage.schemes.all import is_Scheme
     34    from sage.schemes.generic.scheme import is_Scheme
    3535    if not is_Scheme(X):
    3636        X = Schemes()(X)
    3737    return Schemes_over_base(X)
     
    9090            Spectrum of Integer Ring
    9191
    9292        We create a scheme morphism from a ring homomorphism.x::
    93 \
     93
    9494            sage: phi = ZZ.hom(QQ); phi
    9595            Ring Coercion morphism:
    9696              From: Integer Ring
     
    116116                      To:   Rational Field
    117117
    118118        """
     119        from sage.schemes.generic.scheme import is_Scheme
     120        if is_Scheme(x):
     121            return x
     122        from sage.schemes.generic.morphism import is_SchemeMorphism
     123        if is_SchemeMorphism(x):
     124            return x
    119125        from sage.rings.all import is_CommutativeRing, is_RingHomomorphism
    120         from sage.schemes.all import is_Scheme, Spec, is_SchemeMorphism
    121         if is_Scheme(x) or is_SchemeMorphism(x):
    122             return x
    123         elif is_CommutativeRing(x):
     126        from sage.schemes.generic.spec import Spec
     127        if is_CommutativeRing(x):
    124128            return Spec(x)
    125129        elif is_RingHomomorphism(x):
    126130            A = Spec(x.codomain())
     
    159163                the parent for Hom(R, S) to be in a different class::
    160164
    161165                    sage: Hom(Spec(ZZ), Spec(ZZ)).__class__
    162                     <class 'sage.schemes.generic.homset.SchemeHomset_spec_with_category'>
     166                    <class 'sage.schemes.generic.homset.SchemeHomset_coordinates_with_category'>
    163167
    164168                Currently, and to minimize the changes, this is done
    165169                by delegating the job to SchemeHomset. This is not
     
    182186    EXAMPLES::
    183187
    184188        sage: Schemes(Spec(ZZ))
    185         Category of schemes over Spectrum of Integer Ring
     189        Category of schemes over Integer Ring
    186190
    187191    TESTS::
    188192
     
    214218        EXAMPLES::
    215219
    216220            sage: Schemes(Spec(ZZ)) # indirect doctest
    217             Category of schemes over Spectrum of Integer Ring
     221            Category of schemes over Integer Ring
    218222        """
    219223        # To work around the name of the class (schemes_over_base)
    220         return "schemes over %s"%self.base_scheme()
     224        from sage.schemes.generic.spec import is_Spec
     225        if is_Spec(self.base_scheme()):
     226            return "schemes over %s" % self.base_scheme().coordinate_ring()
     227        else:
     228            return "schemes over %s" % self.base_scheme()
  • sage/groups/additive_abelian/additive_abelian_wrapper.py

    diff --git a/sage/groups/additive_abelian/additive_abelian_wrapper.py b/sage/groups/additive_abelian/additive_abelian_wrapper.py
    a b  
    2424    (0 : 1 : 0)
    2525    sage: 3000000000000001 * M.0
    2626    (4 : -7 : 1)
    27     sage: M == loads(dumps(M))
     27    sage: M == loads(dumps(M))    # optional - pickling http://trac.sagemath.org/sage_trac/ticket/11599
    2828    True
    2929
    3030We check that ridiculous operations are being avoided::
  • sage/schemes/elliptic_curves/ell_curve_isogeny.py

    diff --git a/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/sage/schemes/elliptic_curves/ell_curve_isogeny.py
    a b  
    526526        x
    527527        sage: phi.rational_maps()
    528528        ((x^2 + 1)/x, (x^2*y - y)/x^2)
    529         sage: phi == loads(dumps(phi))
     529        sage: phi == loads(dumps(phi))   # optional - pickling http://trac.sagemath.org/sage_trac/ticket/11599
    530530        True
    531531
    532532    A more complicated example of a characteristic 2 field::
  • sage/schemes/elliptic_curves/ell_generic.py

    diff --git a/sage/schemes/elliptic_curves/ell_generic.py b/sage/schemes/elliptic_curves/ell_generic.py
    a b  
    603603            characteristic = self.base_ring().characteristic()
    604604            if characteristic != 0 and isinstance(args[0][0], rings.Rational) and isinstance(args[0][1], rings.Rational):
    605605                if rings.mod(args[0][0].denominator(),characteristic) == 0 or rings.mod(args[0][1].denominator(),characteristic) == 0:
    606                     args = self._reduce_point(args[0], characteristic)
    607                     args = tuple(args)
    608             else:
    609                 args = tuple(args[0])
     606                    return self._reduce_point(args[0], characteristic)
     607            args = tuple(args[0])
    610608
    611609        return plane_curve.ProjectiveCurve_generic.__call__(self, *args, **kwds)
    612610   
     
    860858        EXAMPLES::
    861859       
    862860            sage: E=EllipticCurve(GF(5),[1,1])
    863             sage: E._homset_class(GF(5^10,'a'),GF(5))
    864             Abelian group of points on Finite Field in a of size 5^10
     861            sage: E._homset_class(Spec(GF(5^10,'a'),GF(5)), E)
     862            Abelian group of points on Elliptic Curve defined
     863            by y^2 = x^3 + x + 1 over Finite Field in a of size 5^10
    865864        """
    866865        return homset.SchemeHomsetModule_abelian_variety_coordinates_field(*args, **kwds)
    867866
     
    23012300            sage: F = EllipticCurve('27a3') # should be the same one
    23022301            sage: E.isomorphisms(F);       
    23032302            [Generic morphism:
    2304             From: Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 over Rational Field
    2305             To:   Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 over Rational Field
    2306             Via:  (u,r,s,t) = (-1, 0, 0, -1), Generic morphism:
    2307             From: Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 over Rational Field
    2308             To:   Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 over Rational Field
    2309             Via:  (u,r,s,t) = (1, 0, 0, 0)]
     2303              From: Abelian group of points on Elliptic Curve defined
     2304                    by y^2 + y = x^3 over Rational Field
     2305              To:   Abelian group of points on Elliptic Curve defined
     2306                    by y^2 + y = x^3 over Rational Field
     2307              Via:  (u,r,s,t) = (-1, 0, 0, -1), Generic morphism:
     2308              From: Abelian group of points on Elliptic Curve defined
     2309                    by y^2 + y = x^3 over Rational Field
     2310              To:   Abelian group of points on Elliptic Curve defined
     2311                    by y^2 + y = x^3 over Rational Field
     2312              Via:  (u,r,s,t) = (1, 0, 0, 0)]
     2313
    23102314       
    23112315        We can also find isomorphisms defined over extension fields::
    23122316       
  • sage/schemes/elliptic_curves/ell_number_field.py

    diff --git a/sage/schemes/elliptic_curves/ell_number_field.py b/sage/schemes/elliptic_curves/ell_number_field.py
    a b  
    15471547            sage: K.<t> = NumberField(x^4 + x^3 + 11*x^2 + 41*x + 101)
    15481548            sage: EK = E.base_extend(K)
    15491549            sage: EK.torsion_points()
    1550             [(5 : 5 : 1),
    1551             (5 : -6 : 1),
    1552             (16 : -61 : 1),
    1553             (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : 6/55*t^3 + 3/55*t^2 + 25/11*t + 156/55 : 1),
    1554             (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : -7/121*t^3 + 24/121*t^2 + 197/121*t + 16/121 : 1),
    1555             (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : -49/121*t^3 - 129/121*t^2 - 315/121*t - 207/121 : 1),
    1556             (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : 32/121*t^3 + 60/121*t^2 - 261/121*t - 807/121 : 1),
    1557             (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : -6/11*t^3 - 3/11*t^2 - 26/11*t - 321/11 : 1),
    1558             (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : 16/121*t^3 - 69/121*t^2 + 293/121*t - 46/121 : 1),
    1559             (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : 7/55*t^3 - 24/55*t^2 + 9/11*t + 17/55 : 1),
    1560             (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : 34/121*t^3 - 27/121*t^2 + 305/121*t + 708/121 : 1),
    1561             (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : 15/121*t^3 + 156/121*t^2 - 232/121*t + 2766/121 : 1),
    1562             (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : 6/11*t^3 + 3/11*t^2 + 26/11*t + 310/11 : 1),
    1563             (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : -15/121*t^3 - 156/121*t^2 + 232/121*t - 2887/121 : 1),
    1564             (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : -34/121*t^3 + 27/121*t^2 - 305/121*t - 829/121 : 1),
    1565             (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : -7/55*t^3 + 24/55*t^2 - 9/11*t - 72/55 : 1),
    1566             (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : -16/121*t^3 + 69/121*t^2 - 293/121*t - 75/121 : 1),
    1567             (t : -1/11*t^3 - 6/11*t^2 - 19/11*t - 59/11 : 1),
    1568             (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : -32/121*t^3 - 60/121*t^2 + 261/121*t + 686/121 : 1),
    1569             (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : 49/121*t^3 + 129/121*t^2 + 315/121*t + 86/121 : 1),
    1570             (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : 7/121*t^3 - 24/121*t^2 - 197/121*t - 137/121 : 1),
    1571             (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : -6/55*t^3 - 3/55*t^2 - 25/11*t - 211/55 : 1),
    1572             (0 : 1 : 0),
    1573             (16 : 60 : 1),
    1574             (t : 1/11*t^3 + 6/11*t^2 + 19/11*t + 48/11 : 1)]
     1550            [(16 : 60 : 1),
     1551             (5 : 5 : 1),
     1552             (5 : -6 : 1),
     1553             (16 : -61 : 1),
     1554             (t : 1/11*t^3 + 6/11*t^2 + 19/11*t + 48/11 : 1),
     1555             (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : 6/55*t^3 + 3/55*t^2 + 25/11*t + 156/55 : 1),
     1556             (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : -7/121*t^3 + 24/121*t^2 + 197/121*t + 16/121 : 1),
     1557             (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : -49/121*t^3 - 129/121*t^2 - 315/121*t - 207/121 : 1),
     1558             (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : 32/121*t^3 + 60/121*t^2 - 261/121*t - 807/121 : 1),
     1559             (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : -6/11*t^3 - 3/11*t^2 - 26/11*t - 321/11 : 1),
     1560             (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : 16/121*t^3 - 69/121*t^2 + 293/121*t - 46/121 : 1),
     1561             (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : 7/55*t^3 - 24/55*t^2 + 9/11*t + 17/55 : 1),
     1562             (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : 34/121*t^3 - 27/121*t^2 + 305/121*t + 708/121 : 1),
     1563             (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : 15/121*t^3 + 156/121*t^2 - 232/121*t + 2766/121 : 1),
     1564             (1/11*t^3 - 5/11*t^2 + 19/11*t - 40/11 : 6/11*t^3 + 3/11*t^2 + 26/11*t + 310/11 : 1),
     1565             (-26/121*t^3 + 20/121*t^2 - 219/121*t - 995/121 : -15/121*t^3 - 156/121*t^2 + 232/121*t - 2887/121 : 1),
     1566             (-5/121*t^3 + 36/121*t^2 - 84/121*t + 24/121 : -34/121*t^3 + 27/121*t^2 - 305/121*t - 829/121 : 1),
     1567             (3/55*t^3 + 7/55*t^2 + 2/55*t + 78/55 : -7/55*t^3 + 24/55*t^2 - 9/11*t - 72/55 : 1),
     1568             (14/121*t^3 - 15/121*t^2 + 90/121*t + 232/121 : -16/121*t^3 + 69/121*t^2 - 293/121*t - 75/121 : 1),
     1569             (t : -1/11*t^3 - 6/11*t^2 - 19/11*t - 59/11 : 1),
     1570             (10/121*t^3 + 49/121*t^2 + 168/121*t + 73/121 : -32/121*t^3 - 60/121*t^2 + 261/121*t + 686/121 : 1),
     1571             (5/121*t^3 - 14/121*t^2 - 158/121*t - 453/121 : 49/121*t^3 + 129/121*t^2 + 315/121*t + 86/121 : 1),
     1572             (-9/121*t^3 - 21/121*t^2 - 127/121*t - 377/121 : 7/121*t^3 - 24/121*t^2 - 197/121*t - 137/121 : 1),
     1573             (-3/55*t^3 - 7/55*t^2 - 2/55*t - 133/55 : -6/55*t^3 - 3/55*t^2 - 25/11*t - 211/55 : 1),
     1574             (0 : 1 : 0)]
    15751575
    15761576        ::
    15771577   
     
    15791579            sage: K.<t> = NumberField(x^2 + 2*x + 10)
    15801580            sage: EK = E.base_extend(K)
    15811581            sage: EK.torsion_points()
    1582             [(3 : -2 : 1),
    1583             (8 : -27 : 1),
    1584             (1/2 : 5/4*t + 1/2 : 1),
    1585             (-t - 2 : 2*t + 8 : 1),
    1586             (-7 : -5*t - 2 : 1),
    1587             (-1 : 0 : 1),
    1588             (-2 : 3 : 1),
    1589             (-13/4 : 9/8 : 1),
    1590             (-2 : -2 : 1),
    1591             (t : -2*t + 4 : 1),
    1592             (-7 : 5*t + 8 : 1),
    1593             (-t - 2 : -t - 7 : 1),
    1594             (1/2 : -5/4*t - 2 : 1),
    1595             (0 : 1 : 0),
    1596             (8 : 18 : 1),
    1597             (t : t - 5 : 1)]
    1598        
     1582            [(8 : 18 : 1),
     1583             (3 : -2 : 1),
     1584             (8 : -27 : 1),
     1585             (t : t - 5 : 1),
     1586             (1/2 : 5/4*t + 1/2 : 1),
     1587             (-t - 2 : 2*t + 8 : 1),
     1588             (-7 : -5*t - 2 : 1),
     1589             (-1 : 0 : 1),
     1590             (-2 : 3 : 1),
     1591             (-13/4 : 9/8 : 1),
     1592             (-2 : -2 : 1),
     1593             (t : -2*t + 4 : 1),
     1594             (-7 : 5*t + 8 : 1),
     1595             (-t - 2 : -t - 7 : 1),
     1596             (1/2 : -5/4*t - 2 : 1),
     1597             (0 : 1 : 0)]
     1598
    15991599        ::
    16001600   
    16011601            sage: K.<i> = QuadraticField(-1)
    16021602            sage: EK = EllipticCurve(K,[0,0,0,0,-1])
    16031603            sage: EK.torsion_points ()
    1604             [(0 : -i : 1), (1 : 0 : 1), (0 : i : 1), (-2 : 3*i : 1), (0 : 1 : 0), (-2 : -3*i : 1)]
     1604            [(-2 : -3*i : 1), (0 : -i : 1), (1 : 0 : 1), (0 : i : 1), (-2 : 3*i : 1), (0 : 1 : 0)]
    16051605         """
    16061606        T = self.torsion_subgroup() # make sure it is cached
    16071607        return sorted(T.points())           # these are also cached in T
  • sage/schemes/elliptic_curves/ell_point.py

    diff --git a/sage/schemes/elliptic_curves/ell_point.py b/sage/schemes/elliptic_curves/ell_point.py
    a b  
    164164            sage: Q+Q == 4*P
    165165            True
    166166        """
    167         if isinstance(other, (int, long, rings.Integer)) and other == 0:
    168             if self.is_zero():
    169                 return 0
    170             else:
    171                 return -1
    172         return SchemePoint_projective_abelian_scheme.__cmp__(self, other)
    173 
    174 class EllipticCurvePoint_field(AdditiveGroupElement): # SchemeMorphism_abelian_variety_coordinates_field):
     167        assert isinstance(other, (int, long, rings.Integer)) and other == 0
     168        if self.is_zero():
     169            return 0
     170        else:
     171            return -1
     172
     173
     174class EllipticCurvePoint_field(SchemeMorphism_abelian_variety_coordinates_field):
    175175    """
    176176    A point on an elliptic curve over a field.  The point has coordinates
    177177    in the base field.
     
    260260            (1 : -2 : 1)
    261261        """
    262262        point_homset = curve.point_homset()
    263         AdditiveGroupElement.__init__(self, point_homset)
    264 
     263        if is_SchemeMorphism(v) or isinstance(v,EllipticCurvePoint_field):
     264            v = list(v)
     265        elif v == 0:
     266            # some of the code assumes that E(0) has integral entries
     267            # irregardless of the base ring...
     268            #R = self.base_ring()
     269            #v = (R.zero(),R.one(),R.zero())
     270            v = (0,1,0)
    265271        if check:
    266272            # mostly from SchemeMorphism_projective_coordinates_field
    267273            d = point_homset.codomain().ambient_space().ngens()
    268             if is_SchemeMorphism(v) or isinstance(v, EllipticCurvePoint_field):
    269                 v = list(v)
    270             elif v == 0:
    271                 self._coords = Sequence((0,1,0), point_homset.value_ring())
    272                 return
    273274            if not isinstance(v,(list,tuple)):
    274275                raise TypeError, \
    275276                      "Argument v (= %s) must be a scheme point, list, or tuple."%str(v)
     
    301302                test = y**2 + (a1*x+a3)*y - (((x+a2)*x+a4)*x+a6)
    302303            if not test == 0:
    303304                raise TypeError, "Coordinates %s do not define a point on %s"%(list(v),curve)
    304 #            point_homset.codomain()._check_satisfies_equations(v)
    305305               
    306         self._coords = v
    307        
     306        SchemeMorphism_abelian_variety_coordinates_field.__init__(self, point_homset, v, check=False)
     307        #AdditiveGroupElement.__init__(self, point_homset)
    308308       
    309309    def _repr_(self):
    310310        """
     
    831831            sage: tor = E.torsion_points(); len(tor)
    832832            8
    833833            sage: [T.order() for T in tor]
    834             [2, 4, 4, 2, 4, 1, 4, 2]
     834            [4, 2, 4, 2, 4, 2, 4, 1]
    835835            sage: all([T.is_divisible_by(3) for T in tor])
    836836            True
    837837            sage: Set([T for T in tor if T.is_divisible_by(2)])
  • sage/schemes/elliptic_curves/ell_torsion.py

    diff --git a/sage/schemes/elliptic_curves/ell_torsion.py b/sage/schemes/elliptic_curves/ell_torsion.py
    a b  
    155155            sage: type(T)
    156156            <class 'sage.schemes.elliptic_curves.ell_torsion.EllipticCurveTorsionSubgroup_with_category'>
    157157
    158             sage: T == loads(dumps(T))
     158            sage: T == loads(dumps(T))  # optional - pickling http://trac.sagemath.org/sage_trac/ticket/11599
    159159            True
    160160
    161161        """
  • sage/schemes/generic/affine_space.py

    diff --git a/sage/schemes/generic/affine_space.py b/sage/schemes/generic/affine_space.py
    a b  
    5151    r"""
    5252    Return affine space of dimension `n` over the ring `R`.
    5353   
    54     EXAMPLES: The dimension and ring can be given in either order.
    55    
    56     ::
     54    EXAMPLES:
     55
     56    The dimension and ring can be given in either order::
    5757   
    5858        sage: AffineSpace(3, QQ, 'x')
    5959        Affine Space of dimension 3 over Rational Field
     
    6464        sage: A.coordinate_ring()
    6565        Multivariate Polynomial Ring in X, Y over Rational Field
    6666   
    67     Use the divide operator for base extension.
    68    
    69     ::
     67    Use the divide operator for base extension::
    7068   
    7169        sage: AffineSpace(5, names='x')/GF(17)
    7270        Affine Space of dimension 5 over Finite Field of size 17
    7371   
    74     The default base ring is `\ZZ`.
    75    
    76     ::
     72    The default base ring is `\ZZ`::
    7773   
    7874        sage: AffineSpace(5, names='x')
    7975        Affine Space of dimension 5 over Integer Ring
    8076   
    81     There is also an affine space associated to each polynomial ring.
    82    
    83     ::
     77    There is also an affine space associated to each polynomial ring::
    8478   
    8579        sage: R = GF(7)['x,y,z']
    8680        sage: A = AffineSpace(R); A
     
    10498            raise TypeError, "You must specify the variables names of the coordinate ring."
    10599    return AffineSpace_generic(n, R, names)
    106100
     101
    107102class AffineSpace_generic(AmbientSpace, AffineScheme):
    108103    """
    109104    Affine space of dimension `n` over the ring `R`.
     
    116111        sage: X.base_ring()
    117112        Rational Field
    118113        sage: X.category()
    119         Category of schemes over Spectrum of Rational Field
    120         sage: X.structure_morphism ()
     114        Category of schemes over Rational Field
     115        sage: X.structure_morphism()
    121116        Scheme morphism:
    122117          From: Affine Space of dimension 3 over Rational Field
    123118          To:   Spectrum of Rational Field
     
    128123        sage: loads(X.dumps()) == X
    129124        True
    130125   
    131     We create several other examples of affine spaces.
    132    
    133     ::
     126    We create several other examples of affine spaces::
    134127   
    135128        sage: AffineSpace(5, PolynomialRing(QQ, 'z'), 'Z')
    136129        Affine Space of dimension 5 over Univariate Polynomial Ring in z over Rational Field
    137130   
    138     ::
    139    
    140131        sage: AffineSpace(RealField(), 3, 'Z')
    141132        Affine Space of dimension 3 over Real Field with 53 bits of precision
    142133   
    143     ::
    144    
    145134        sage: AffineSpace(Qp(7), 2, 'x')
    146135        Affine Space of dimension 2 over 7-adic Field with capped relative precision 20
    147136   
    148     Even 0-dimensional affine spaces are supported.
    149    
    150     ::
     137    Even 0-dimensional affine spaces are supported::
    151138   
    152139        sage: AffineSpace(0)
    153140        Affine Space of dimension 0 over Integer Ring
  • sage/schemes/generic/algebraic_scheme.py

    diff --git a/sage/schemes/generic/algebraic_scheme.py b/sage/schemes/generic/algebraic_scheme.py
    a b  
    344344
    345345        OUTPUT:
    346346
    347         A scheme morphism whose :meth:`~morphism.PyMorphism.domain` is
    348         ``self``.
     347        A scheme morphism whose
     348        :meth:`~morphism.SchemeMorphism.domain` is ``self``.
    349349
    350350        * By default, it is the tautological embedding into its own
    351351          ambient space :meth:`ambient_space`.
     
    715715            ...
    716716            TypeError: number of arguments does not match number of variables in parent
    717717
    718 
    719718            sage: A.<x, y> = AffineSpace(2, GF(7))
    720719            sage: S = A.subscheme([x^2-y])
    721720            sage: T = A.subscheme([x-y])
  • sage/schemes/generic/ambient_space.py

    diff --git a/sage/schemes/generic/ambient_space.py b/sage/schemes/generic/ambient_space.py
    a b  
    1212
    1313from sage.rings.all import Integer, is_CommutativeRing, ZZ
    1414
    15 from sage.structure.parent import Parent
    16 
    17 import scheme
     15from sage.schemes.generic.scheme import Scheme
    1816
    1917def is_AmbientSpace(x):
    2018    """
     
    3331    """
    3432    return isinstance(x, AmbientSpace)
    3533
    36 class AmbientSpace(scheme.Scheme, Parent):
     34class AmbientSpace(Scheme):
    3735    """
    3836    Base class for ambient spaces over a ring.
    3937   
     
    5755        n = Integer(n)
    5856        if n < 0:
    5957            raise ValueError, "n (=%s) must be nonnegative"%n
    60         self.__n = n
    61         self._base_ring = R
     58        self._dimension_relative = n
     59        Scheme.__init__(self, R)
     60       
    6261        # NT: this seems to set improperly self._base_scheme to X instead of Spec(X)????
    6362        # scheme.Scheme.__init__(self, R)
    6463        # This should be cleaned up by someone who knows about schemes (not me!)
    65         from sage.categories.schemes import Schemes
    66         Parent.__init__(self, R, category = Schemes(self.base_scheme()))
     64        #from sage.categories.schemes import Schemes
     65        #Parent.__init__(self, R, category = Schemes(self.base_scheme()))
    6766
    6867    #######################################################################
    6968    # Derived classes must overload all of the following functions
     
    393392            sage: A2Z.dimension_relative()
    394393            2
    395394        """
    396         return self.__n
     395        return self._dimension_relative
  • sage/schemes/generic/homset.py

    diff --git a/sage/schemes/generic/homset.py b/sage/schemes/generic/homset.py
    a b  
    11"""
    22Set of homomorphisms between two schemes
     3
     4.. note::
     5
     6    You should not create the homsets manually. Instead, use the
     7    :meth:`~sage.structure.parent.Hom` method that is inherited by all
     8    schemes.
    39"""
    410
    511#*****************************************************************************
     
    814#                  http://www.gnu.org/licenses/
    915#*****************************************************************************
    1016
    11 import sage.structure.parent_old as parent_old
    1217from sage.categories.homset import HomsetWithBase
    13 from sage.rings.integer_ring import ZZ
    14 from sage.rings.finite_rings.constructor import is_FiniteField
    15 from sage.rings.rational_field import is_RationalField
    16 from sage.rings.morphism import is_RingHomomorphism
     18from sage.structure.factory import UniqueFactory
    1719
    18 import spec
    19 import morphism
     20from sage.rings.all import ( gcd, ZZ, QQ,
     21    is_CommutativeRing, is_RingHomomorphism, is_RationalField, is_FiniteField )
     22
     23from sage.schemes.generic.scheme import is_Scheme
     24from sage.schemes.generic.spec import Spec, is_Spec
     25from sage.schemes.generic.morphism import (
     26    SchemeMorphism,
     27    SchemeMorphism_structure_map, SchemeMorphism_spec,
     28    SchemeMorphism_affine_coordinates,
     29    SchemeMorphism_projective_coordinates_field )
    2030from sage.schemes.generic.toric_morphism import SchemeMorphism_toric_coordinates_field
    2131
    2232
    2333
    2434
    2535def is_SchemeHomset(H):
     36    r"""
     37    Test whether ``H`` is a scheme homset.
     38    """
    2639    return isinstance(H, SchemeHomset_generic)
    2740
    28 def SchemeHomset(R, S, category=None, check=True):
    29     if spec.is_Spec(R) and spec.is_Spec(S):
    30         return SchemeHomset_spec(R, S, category=category, check=check)
    31     else:
    32         return SchemeHomset_generic(R, S, category=category, check=check)
    3341
    34 class SchemeHomset_generic(parent_old.Parent, HomsetWithBase):
    35     def __init__(self, X, Y, category=None, check=True, base=ZZ):
    36         HomsetWithBase.__init__(self, X, Y, category=category, check=check, base=base)
     42#*******************************************************************
     43# Factory for Hom sets of schemes
     44#*******************************************************************
     45class SchemeHomsetFactory(UniqueFactory):
     46    """
     47    Factory for Hom sets of schemes.
    3748
    38     def has_coerce_map_from_impl(self, S):
    39         if self == S:   # an obvious case
    40             return True
    41         # Todo -- implement more cases.
    42         return False
     49    EXAMPLES::
     50
     51        sage: A2 = AffineSpace(QQ,2)
     52        sage: A3 = AffineSpace(QQ,3)
     53        sage: Hom = A3.Hom(A2)
     54        sage: Hom is copy(Hom)
     55        True
     56        sage: Hom is A3.Hom(A2)
     57        True
     58        sage: loads(Hom.dumps()) is Hom
     59        True
     60
     61    Here is a tricy point. The Hom sets are not identical if
     62    domain/codomains are isomorphic but not identiacal::
     63
     64        sage: A3_iso = AffineSpace(QQ,3)
     65        sage: [ A3_iso is A3, A3_iso == A3 ]
     66        [False, True]
     67        sage: Hom_iso = A3_iso.Hom(A2)
     68        sage: Hom_iso is Hom
     69        False
     70        sage: Hom_iso == Hom
     71        True
     72
     73    TESTS::
     74
     75        sage: Hom.base()
     76        Integer Ring
     77        sage: Hom.base_ring()
     78        Integer Ring
     79    """
     80   
     81    def create_key_and_extra_args(self, X, Y, category=None, check=True, base=ZZ):
     82        """
     83        Create a key that uniquely determines the Hom set.
     84       
     85        INPUT:
     86       
     87        - ``X`` -- a scheme. The domain of the morphisms.
     88       
     89        - ``Y`` -- a scheme. The codomain of the morphisms.
     90
     91        - ``base`` -- a scheme or a ring. The base scheme of domain
     92          and codomain schemes. If a ring is specified, the spectrum
     93          of that ring will be used as base scheme.
     94
     95        - ``check`` -- boolean (default: ``True``).
     96
     97        EXAMPLES::
     98       
     99            sage: A2 = AffineSpace(QQ,2)
     100            sage: A3 = AffineSpace(QQ,3)
     101            sage: A3.Hom(A2)    # indirect doctest
     102            Set of morphisms
     103              From: Affine Space of dimension 3 over Rational Field
     104              To:   Affine Space of dimension 2 over Rational Field
     105            sage: from sage.schemes.generic.homset import SchemeHomsetFactory
     106            sage: SHOMfactory = SchemeHomsetFactory('test')
     107            sage: key, extra = SHOMfactory.create_key_and_extra_args(A3,A2,check=False)
     108            sage: key
     109            (..., ..., Category of schemes over Integer Ring)
     110            sage: extra
     111            {'Y': Affine Space of dimension 2 over Rational Field,
     112             'X': Affine Space of dimension 3 over Rational Field,
     113             'base_ring': Integer Ring, 'check': False}
     114        """
     115        if not is_Scheme(X) and is_CommutativeRing(X):
     116            X = Spec(X)
     117        if not is_Scheme(Y) and is_CommutativeRing(Y):
     118            Y = Spec(Y)
     119        if is_Spec(base):
     120            base_spec = base
     121            base_ring = base.coordinate_ring()
     122        elif is_CommutativeRing(base):
     123            base_spec = Spec(base)
     124            base_ring = base
     125        else:
     126            raise ValueError('The base must be an affine scheme or a commutative ring.')
     127        if not category:
     128            from sage.categories.schemes import Schemes
     129            category = Schemes(base_spec)
     130        key = tuple([id(X), id(Y), category])
     131        extra = {'X':X, 'Y':Y, 'base_ring':base_ring, 'check':check}
     132        return key, extra
     133
     134    def create_object(self, version, key, **extra_args):
     135        """
     136        Create a :class:`SchemeHomset_generic`.
     137
     138        INPUT:
     139       
     140        - ``version`` -- object version. Currently not used.
     141       
     142        - ``key`` -- a key created by :meth:`create_key_and_extra_args`.
     143
     144        - ``extra_args`` -- a dictionary of extra keyword arguments.
     145
     146        EXAMPLES::
     147
     148            sage: A2 = AffineSpace(QQ,2)
     149            sage: A3 = AffineSpace(QQ,3)
     150            sage: A3.Hom(A2) is A3.Hom(A2)   # indirect doctest
     151            True
     152            sage: from sage.schemes.generic.homset import SchemeHomsetFactory
     153            sage: SHOMfactory = SchemeHomsetFactory('test')
     154            sage: SHOMfactory.create_object(0, [id(A3),id(A2),A3.category()], check=True,
     155            ...                             X=A3, Y=A2, base_ring=QQ)
     156            Set of morphisms
     157              From: Affine Space of dimension 3 over Rational Field
     158              To:   Affine Space of dimension 2 over Rational Field
     159        """
     160        category = key[2]
     161        X = extra_args.pop('X')
     162        Y = extra_args.pop('Y')
     163        base_ring = extra_args.pop('base_ring')
     164        if is_Spec(X):
     165            return Y._homset_class(X, Y, category=category, base=base_ring, **extra_args)
     166        return SchemeHomset_generic(X, Y, category=category, base=base_ring, **extra_args)
     167
     168
     169SchemeHomset = SchemeHomsetFactory('sage.schemes.generic.homset.SchemeHomset')
     170
     171
     172
     173#*******************************************************************
     174# Base class
     175#*******************************************************************
     176class SchemeHomset_generic(HomsetWithBase):
     177    r"""
     178    The base class for Hom sets of schemes.
     179
     180    INPUT:
     181
     182    - ``X`` -- a scheme. The domain of the Hom set.
     183
     184    - ``Y`` -- a scheme. The codomain of the Hom set.
     185
     186    - ``category`` -- a category (optional). The category of the Hom
     187      set.
     188
     189    - ``check`` -- boolean (optional, default=``True``). Whether to
     190      check the defining data for consistency.
     191
     192    EXAMPLES::
     193
     194        sage: from sage.schemes.generic.homset import SchemeHomset_generic
     195        sage: A2 = AffineSpace(QQ,2)
     196        sage: Hom = SchemeHomset_generic(A2, A2); Hom
     197        Set of morphisms
     198          From: Affine Space of dimension 2 over Rational Field
     199          To:   Affine Space of dimension 2 over Rational Field
     200        sage: Hom.category()
     201        Category of hom sets in Category of Schemes
     202    """
     203    Element = SchemeMorphism
     204
     205    def __call__(self, *args, **kwds):
     206        r"""
     207        Make Hom sets callable.
     208
     209        See the ``_call_()`` method of the derived class. All
     210        arguments are handed through.
     211
     212        EXAMPLES::
     213
     214            sage: A2 = AffineSpace(QQ,2)
     215            sage: A2(4,5)
     216            (4, 5)
     217        """
     218        # Homset (base of HomsetWithBase) overrides __call__ @#$
     219        from sage.structure.parent import Set_generic
     220        return Set_generic.__call__(self, *args, **kwds)
    43221
    44222    def _repr_(self):
    45         try:
    46             return "Set of points of %s defined over %s"%(self.codomain(), self.domain().coordinate_ring())
    47         except ValueError:
    48             return "Set of morphisms from %s to %s"%(self.domain(), self.codomain())
     223        r"""
     224        Return a string representation.
     225
     226        OUTPUT:
     227
     228        A string.
     229       
     230        EXAMPLES::
     231
     232            sage: A = AffineSpace(4, QQ)
     233            sage: A.structure_morphism()._repr_()
     234            'Scheme morphism:\n  From: Affine Space of dimension 4 over Rational Field\n  To:   Spectrum of Rational Field\n  Defn: Structure map'
     235        """
     236        s = 'Set of morphisms'
     237        s += '\n  From: %s' % self.domain()
     238        s += '\n  To:   %s' % self.codomain()
     239        return s
    49240
    50241    def natural_map(self):
     242        r"""
     243        Return a natural map in the Hom space.
     244
     245        OUTPUT:
     246       
     247        A :class:`SchemeMorphism` if there is a natural map from
     248        domain to codomain. Otherwise, a ``NotImplementedError`` is
     249        raised.
     250
     251        EXAMPLES::
     252
     253            sage: A = AffineSpace(4, QQ)
     254            sage: A.structure_morphism()   # indirect doctest
     255            Scheme morphism:
     256              From: Affine Space of dimension 4 over Rational Field
     257              To:   Spectrum of Rational Field
     258              Defn: Structure map
     259        """
    51260        X = self.domain()
    52261        Y = self.codomain()
    53         if spec.is_Spec(Y) and Y.coordinate_ring() == X.base_ring():
    54             return morphism.SchemeMorphism_structure_map(self)
     262        if is_Spec(Y) and Y.coordinate_ring() == X.base_ring():
     263            return SchemeMorphism_structure_map(self)
    55264        raise NotImplementedError
    56265
    57     def __call__(self, x, check=True):
     266    def _element_constructor_(self, x, check=True):
    58267        """
     268        Construct a scheme morphism.
     269
    59270        INPUT:
    60271
    61             - `x` -- a ring morphism, or a list or tuple of that
    62               define a ring morphism.
     272        - `x` -- a ring morphism, or a list or tuple of that define a
     273          ring morphism.
    63274
    64             - ``check`` -- (default: True) passed onto functions
    65               called by this to be more careful about input argument
    66               type checking
     275        - ``check`` -- boolean (default: ``True``) passed onto
     276          functions called by this to be more careful about input
     277          argument type checking
    67278       
    68279        EXAMPLES::
    69280       
     
    72283              From: Integer Ring
    73284              To:   Rational Field
    74285       
    75         ::
    76        
    77             sage: H = Hom(Spec(QQ,ZZ), Spec(ZZ)); H
    78             Set of points of Spectrum of Integer Ring defined over Rational Field
    79        
    80         ::
     286            sage: H = Hom(Spec(QQ, ZZ), Spec(ZZ)); H
     287            Set of rational points of Spectrum of Rational Field
    81288       
    82289            sage: phi = H(f); phi
    83290            Affine Scheme morphism:
     
    87294                      From: Integer Ring
    88295                      To:   Rational Field
    89296
    90         TESTS::
     297        TESTS:
    91298       
    92299        We illustrate input type checking::
    93300       
     
    95302            sage: A.<x,y> = AffineSpace(R)
    96303            sage: C = A.subscheme(x*y-1)
    97304            sage: H = C.Hom(C); H
    98             Set of points of Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
    99               x*y - 1 defined over Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
     305            Set of morphisms
     306              From: Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
     307              x*y - 1
     308              To:   Closed subscheme of Affine Space of dimension 2 over Rational Field defined by:
     309              x*y - 1
    100310            sage: H(1)
    101311            Traceback (most recent call last):
    102312            ...
     
    106316            return self.domain()._point_morphism_class(self, x, check=check)
    107317       
    108318        if is_RingHomomorphism(x):
    109             return morphism.SchemeMorphism_spec(self, x, check=check)
     319            return SchemeMorphism_spec(self, x, check=check)
    110320
    111321        raise TypeError, "x must be a ring homomorphism, list or tuple"
    112322
    113 class SchemeHomset_spec(SchemeHomset_generic):
    114     pass
     323
    115324
    116325class SchemeHomset_coordinates(SchemeHomset_generic):
    117326    """
    118     Set of points on X defined over the base ring of X, and given by
    119     explicit tuples.
     327    Set of rational points of the scheme.
     328
     329    Recall that the `K`-rational points of a scheme `X` over `k` can
     330    be identified with the set of morphisms `Spec(K) \to X`. In Sage,
     331    the rational points are implemented by such scheme morphisms.
     332
     333    INPUT:
     334   
     335    See :class:`SchemeHomset_generic`.
     336
     337    EXAMPLES::
     338
     339        sage: from sage.schemes.generic.homset import SchemeHomset_coordinates
     340        sage: SchemeHomset_coordinates(Spec(QQ), AffineSpace(ZZ,2))
     341        Set of rational points of Affine Space of dimension 2 over Rational Field
    120342    """
    121     def __init__(self, X, S):
    122         R = X.base_ring()
    123         if R != S:
    124             X = X.base_extend(S)
    125         SchemeHomset_generic.__init__(self, spec.Spec(S, R), X)
     343
     344    def __init__(self, X, Y, category=None, check=True, base=ZZ):
     345        """
     346        Python constructor.
     347       
     348        INPUT:
     349       
     350        See :class:`SchemeHomset_generic`.
     351
     352        EXAMPLES::
     353
     354            sage: from sage.schemes.generic.homset import SchemeHomset_coordinates
     355            sage: SchemeHomset_coordinates(Spec(QQ), AffineSpace(ZZ,2))
     356            Set of rational points of Affine Space of dimension 2 over Rational Field
     357        """
     358        if check and not is_Spec(X):
     359            raise ValueError('The domain must be an affine scheme.')
     360        SchemeHomset_generic.__init__(self, X, Y, category=category, check=check, base=base)
     361
     362    def extended_codomain(self):
     363        """
     364        Return the codomain with extended base, if necessary.
     365
     366        OUTPUT:
     367
     368        The codomain scheme, with its base ring extended to the
     369        codomain. That is, the codomain is of the form `Spec(R)` and
     370        the base ring of the domain is extended to `R`.
     371       
     372        EXAMPLES::
     373       
     374            sage: P2 = ProjectiveSpace(QQ,2)
     375            sage: K.<a> = NumberField(x^2 + x - (3^3-3))
     376            sage: K_points = P2(K);  K_points
     377            Set of rational points of Projective Space of dimension 2
     378            over Number Field in a with defining polynomial x^2 + x - 24
     379
     380            sage: K_points.codomain()
     381            Projective Space of dimension 2 over Rational Field
     382
     383            sage: K_points.extended_codomain()
     384            Projective Space of dimension 2 over Number Field in a with
     385            defining polynomial x^2 + x - 24
     386        """
     387        if '_extended_codomain' in self.__dict__:
     388            return self._extended_codomain
     389        R = self.domain().coordinate_ring()
     390        if R is not self.codomain().base_ring():
     391            X = self.codomain().base_extend(R)
     392        else:
     393            X = self.codomain()
     394        self._extended_codomain = X
     395        return X
    126396       
    127397    def _repr_(self):
    128         S = self.domain()
    129         if S == self.codomain().base_scheme():
    130             return "Set of Rational Points of %s"%self.codomain()
    131         if spec.is_Spec(S):
    132             S = S.coordinate_ring()
    133         return "Set of Rational Points over %s of %s"%(S, self.codomain())
     398        """
     399        Return a string representation of ``self``.
     400
     401        OUTPUT:
     402
     403        A string.
     404       
     405        EXAMPLES::
     406
     407            sage: P2 = ProjectiveSpace(ZZ,2)
     408            sage: P2(QQ)._repr_()
     409            'Set of rational points of Projective Space of dimension 2 over Rational Field'
     410        """
     411        return 'Set of rational points of '+str(self.extended_codomain())
    134412
    135413    def value_ring(self):
    136414        """
    137         Returns S for a homset X(T) where T = Spec(S).
     415        Returns ``R` for a homset `X(Spec(R))`
     416
     417        OUTPUT:
     418       
     419        A commutative ring.
     420       
     421        EXAMPLES::
     422       
     423            sage: P2 = ProjectiveSpace(ZZ,2)
     424            sage: P2(QQ).value_ring()
     425            Rational Field
    138426        """
    139         T = self.domain()
    140         if spec.is_Spec(T):
    141             return T.coordinate_ring()
    142         else:
    143             raise TypeError, "Domain of argument must be of the form Spec(S)."
     427        dom = self.domain()
     428        assert is_Spec(dom)
     429        return dom.coordinate_ring()
    144430
    145431
    146432#*******************************************************************
     
    148434#*******************************************************************
    149435class SchemeHomset_affine_coordinates(SchemeHomset_coordinates):
    150436    """
    151     Set of points on X defined over the base ring of X, and given by
    152     explicit tuples.
     437    Set of rational points of an affine variety.
     438
     439    INPUT:
     440   
     441    See :class:`SchemeHomset_generic`.
     442
     443    EXAMPLES::
     444
     445        sage: from sage.schemes.generic.homset import SchemeHomset_affine_coordinates
     446        sage: SchemeHomset_affine_coordinates(Spec(QQ), AffineSpace(ZZ,2))
     447        Set of rational points of Affine Space of dimension 2 over Rational Field
    153448    """
    154     def __call__(self, *v):
     449    def _element_constructor_(self, *v):
     450        """
     451        The element contstructor.
     452
     453        INPUT:
     454
     455        - ``v`` -- anything that determines a scheme morphism in the
     456          hom set.
     457
     458        OUTPUT:
     459
     460        The scheme morphism determined by ``v``.
     461
     462        EXAMPLES::
     463       
     464            sage: A2 = AffineSpace(ZZ,2)
     465            sage: F = GF(3)
     466            sage: F_points = A2(F);  type(F_points)
     467            <class 'sage.schemes.generic.homset.SchemeHomset_affine_coordinates_with_category'>
     468            sage: F_points([2,5])
     469            (2, 2)
     470        """
    155471        if len(v) == 1:
    156472            v = v[0]
    157         return morphism.SchemeMorphism_affine_coordinates(self, v)
     473        return SchemeMorphism_affine_coordinates(self, v)
    158474
    159475    def points(self, B=0):
    160476        r"""
    161         Return the set of points given by coordinate tuples with coordinates
    162         in the base ring.
     477        Return some or all rational points of an affine scheme.
    163478
    164479        INPUT:
    165480
    166         - ``B`` -- an integer.
     481        - `B` -- integer (optional, default=0). The bound for the
     482          height of the coordinates.
    167483
    168484        OUTPUT:
    169485
    170         - If the base ring is a finite field: the set of points given by
    171           coordinate tuples.
     486        - If the base ring is a finite field: All points of the scheme,
     487          given by coordinate tuples.
    172488
    173489        - If the base ring is `\QQ` or `\ZZ`: the subset of points whose
    174490          coordinates have height ``B`` or less.
    175491
    176492        EXAMPLES: The bug reported at #11526 is fixed::
    177493
     494            sage: A2 = AffineSpace(ZZ,2)
     495            sage: F = GF(3)
     496            sage: A2(F).points()
     497            [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
     498
    178499            sage: R = ZZ
    179500            sage: A.<x,y> = R[]
    180501            sage: I = A.ideal(x^2-y^2-1)
     
    184505            sage: M.points(1)
    185506            [(-1, 0), (1, 0)]
    186507        """
    187         try:
    188             R = self.value_ring()
    189         except TypeError:
    190             raise TypeError, "Domain of argument must be of the form Spec(S)."
     508        R = self.value_ring()
    191509        if is_RationalField(R) or R == ZZ:
    192510            if not B > 0:
    193511                raise TypeError, "A positive bound B (= %s) must be specified."%B
     
    205523#*******************************************************************
    206524class SchemeHomset_projective_coordinates_field(SchemeHomset_coordinates):
    207525    """
    208     Set of points on X defined over the base ring of X, and given by
    209     explicit tuples.
     526    Set of rational points of a projective variety over a field.
     527
     528    INPUT:
     529   
     530    See :class:`SchemeHomset_generic`.
     531
     532    EXAMPLES::
     533
     534        sage: from sage.schemes.generic.homset import SchemeHomset_projective_coordinates_field
     535        sage: SchemeHomset_projective_coordinates_field(Spec(QQ), ProjectiveSpace(QQ,2))
     536        Set of rational points of Projective Space of dimension 2 over Rational Field
    210537    """
    211     def __call__(self, *v):
     538    def _element_constructor_(self, *v):
     539        """
     540        The element contstructor.
     541
     542        INPUT:
     543
     544        - ``v`` -- anything that determines a scheme morphism in the
     545          hom set.
     546
     547        OUTPUT:
     548
     549        The scheme morphism determined by ``v``.
     550
     551        EXAMPLES::
     552       
     553            sage: P2 = ProjectiveSpace(GF(3),2)
     554            sage: F.<a> = GF(9,'a')
     555            sage: F_points = P2(F)
     556            sage: F_points([4,2*a])
     557            (1 : 2*a : 1)
     558        """
    212559        if len(v) == 1:
    213560            v = v[0]
    214         X = self.codomain()
    215         try:
    216             return X._point_class(X, v)
    217         except AttributeError:  # should be very rare
    218             return morphism.SchemeMorphism_projective_coordinates_field(self, v)
     561        X = self.extended_codomain()
     562        return X.point(v)
    219563
    220564    def points(self, B=0):
     565        """
     566        Return some or all rational points of a projective scheme.
     567
     568        INPUT:
     569
     570        - `B` -- integer (optional, default=0). The bound for the
     571          coordinates.
     572
     573        OUTPUT:
     574
     575        A list of points. Over a finite field, all points are
     576        returned. Over an infinite field, all points satisfying the
     577        bound are returned.
     578
     579        EXAMPLES::
     580       
     581            sage: P1 = ProjectiveSpace(GF(2),1)
     582            sage: F.<a> = GF(4,'a')
     583            sage: P1(F).points()
     584            [(0 : 1), (1 : 0), (1 : 1), (a : 1), (a + 1 : 1)]
     585        """
    221586        from sage.schemes.generic.rational_point import enum_projective_rational_field
    222587        from sage.schemes.generic.rational_point import enum_projective_finite_field
    223         try:
    224             R = self.value_ring()
    225         except TypeError:
    226             raise TypeError, "Domain of argument must be of the form Spec(S)."
     588        R = self.value_ring()
    227589        if is_RationalField(R):
    228590            if not B > 0:
    229591                raise TypeError, "A positive bound B (= %s) must be specified."%B
    230592            return enum_projective_rational_field(self,B)
    231593        elif is_FiniteField(R):
    232             return enum_projective_finite_field(self)
     594            return enum_projective_finite_field(self.extended_codomain())
    233595        else:
    234596            raise TypeError, "Unable to enumerate points over %s."%R
    235597
    236598class SchemeHomset_projective_coordinates_ring(SchemeHomset_coordinates):
    237599    """
    238     Set of points on X defined over the base ring of X, and given by
    239     explicit tuples.
     600    Set of rational points of a projective variety over a commutative ring.
     601
     602    INPUT:
     603   
     604    See :class:`SchemeHomset_generic`.
     605
     606    EXAMPLES::
     607
     608        sage: from sage.schemes.generic.homset import SchemeHomset_projective_coordinates_ring
     609        sage: SchemeHomset_projective_coordinates_ring(Spec(ZZ), ProjectiveSpace(ZZ,2))
     610        Set of rational points of Projective Space of dimension 2 over Integer Ring
    240611    """
    241     def __call__(self, *v):
     612    def _element_constructor_(self, *v):
     613        r"""
     614        The element constructor.
     615       
     616        This is currently not implemented.
     617
     618        EXAMPLES::
     619
     620            sage: from sage.schemes.generic.homset import SchemeHomset_projective_coordinates_ring
     621            sage: Hom = SchemeHomset_projective_coordinates_ring(Spec(ZZ), ProjectiveSpace(ZZ,2))
     622            sage: Hom(1,2,3)
     623            Traceback (most recent call last):
     624            ...
     625            NotImplementedError
     626        """
    242627        raise NotImplementedError
    243628
    244629    def points(self, B=0):
    245         raise NotImplementedError # fixed when __call__ is defined.
    246         try:
    247             R = self.value_ring()
    248         except TypeError:
    249             raise TypeError, "Domain of argument must be of the form Spec(S)."
     630        """
     631        Return some or all rational points of a projective scheme.
     632
     633        INPUT:
     634
     635        - `B` -- integer (optional, default=0). The bound for the
     636          coordinates.
     637
     638        OUTPUT:
     639
     640        This is currently not implemented and will raise ``NotImplementedError``.
     641
     642        EXAMPLES::
     643
     644            sage: from sage.schemes.generic.homset import SchemeHomset_projective_coordinates_ring
     645            sage: Hom = SchemeHomset_projective_coordinates_ring(Spec(ZZ), ProjectiveSpace(ZZ,2))
     646            sage: Hom.points(5)
     647            Traceback (most recent call last):
     648            ...
     649            NotImplementedError
     650        """
     651        raise NotImplementedError # fixed when _element_constructor_ is defined.
     652        R = self.value_ring()
    250653        if R == ZZ:
    251654            if not B > 0:
    252655                raise TypeError, "A positive bound B (= %s) must be specified."%B
     
    260663# Abelian varieties
    261664#*******************************************************************
    262665class SchemeHomsetModule_abelian_variety_coordinates_field(SchemeHomset_projective_coordinates_field):
    263     def __init__(self, X, S, category=None, check=True):
    264         r"""
    265         EXAMPLES: The bug reported at trac #1785 is fixed::
     666    r"""
     667    Set of rational points of an abelian variety.
     668
     669    INPUT:
     670   
     671    See :class:`SchemeHomset_generic`.
     672
     673    TESTS:
     674
     675    The bug reported at trac #1785 is fixed::
    266676       
    267             sage: K.<a> = NumberField(x^2 + x - (3^3-3))
    268             sage: E = EllipticCurve('37a')
    269             sage: X = E(K)
    270             sage: X
    271             Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 + (-1)*x over Number Field in a with defining polynomial x^2 + x - 24
    272             sage: P = X([3,a])
    273             sage: P
    274             (3 : a : 1)
    275             sage: P in E
    276             False
    277             sage: P in E.base_extend(K)
    278             True
    279         """
    280         R = X.base_ring()
    281         if R != S:
    282             X = X.base_extend(S)
    283         Y = spec.Spec(S, R)
    284         HomsetWithBase.__init__(self, Y, X, category=category,
    285                                 check = check, base = ZZ)
     677        sage: K.<a> = NumberField(x^2 + x - (3^3-3))
     678        sage: E = EllipticCurve('37a')
     679        sage: X = E(K)
     680        sage: X
     681        Abelian group of points on Elliptic Curve defined by
     682        y^2 + y = x^3 + (-1)*x over Number Field in a with
     683        defining polynomial x^2 + x - 24
     684        sage: P = X([3,a])
     685        sage: P
     686        (3 : a : 1)
     687        sage: P in E
     688        False
     689        sage: P in E.base_extend(K)
     690        True
     691        sage: P in X.codomain()
     692        False
     693        sage: P in X.extended_codomain()
     694        True
     695    """
    286696
    287697    def _repr_(self):
    288         return "Abelian group of points on %s"%self.codomain()
     698        """
     699        Return a string representation of ``self``.
     700
     701        OUTPUT:
     702       
     703        String.
     704
     705        EXAMPLES::
     706       
     707            sage: E = EllipticCurve('37a')
     708            sage: X = E(QQ)
     709            sage: X._repr_()
     710            'Abelian group of points on Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field'
     711        """
     712        s = 'Abelian group of points on ' + str(self.extended_codomain())
     713        return s
    289714
    290715    def base_extend(self, R):
    291         if R != sage.rings.integer_ring.ZZ:
    292             raise NotImplementedError, "Abelian variety point sets not implemented as modules over rings other than ZZ."
     716        if not R is ZZ:
     717            raise NotImplementedError('Abelian variety point sets not implemented '
     718                                      'as modules over rings other than ZZ.')
    293719        return self
    294720   
    295721
     
    298724#*******************************************************************
    299725class SchemeHomset_toric_coordinates_field(SchemeHomset_coordinates):
    300726    """
    301     Construct the `Hom`-space of morphisms given on coordinates.
    302 
    303     .. WARNING::
    304 
    305         You should not create objects of this class directly.
    306 
     727    Set of rational points of a toric variety.
    307728
    308729    INPUT:
    309730
     
    311732
    312733    OUPUT:
    313734
    314     - :class:`SchemeHomset_toric_coordinates_field`.
     735    A scheme morphism of type
     736    :class:`SchemeHomset_toric_coordinates_field`.
     737
     738    EXAMPLES::
     739
     740        sage: P1xP1 = toric_varieties.P1xP1()
     741        sage: P1xP1(QQ)
     742        Set of rational points of 2-d CPR-Fano toric variety
     743        covered by 4 affine patches
    315744
    316745    TESTS::
    317746
    318         sage: fan = FaceFan(lattice_polytope.octahedron(2))
    319         sage: P1xP1 = ToricVariety(fan)
    320747        sage: import sage.schemes.generic.homset as HOM
    321         sage: HOM.SchemeHomset_toric_coordinates_field(P1xP1, QQ)
    322         Set of Rational Points of 2-d toric variety
    323         covered by 4 affine patches
    324 
    325     A better way to construct the same `Hom`-space as above::
    326 
    327         sage: P1xP1(QQ)
    328         Set of Rational Points of 2-d toric variety
    329         covered by 4 affine patches
     748        sage: HOM.SchemeHomset_toric_coordinates_field(Spec(QQ), P1xP1)
     749        Set of rational points of 2-d CPR-Fano toric variety covered by 4 affine patches
    330750    """
    331     # Mimicking SchemeHomset_projective_coordinates_field,
    332     # affine spaces implement only "except" case
    333     def __call__(self, *arg):
    334         r"""
    335         Construct a morphism from given parameters.
    336 
    337         INPUT:
    338 
    339         - data determining a morphism.
    340 
    341         TESTS::
    342 
    343             sage: fan = FaceFan(lattice_polytope.octahedron(2))
    344             sage: P1xP1 = ToricVariety(fan)
    345             sage: import sage.schemes.generic.homset as HOM
    346             sage: H = HOM.SchemeHomset_toric_coordinates_field(P1xP1, QQ)
    347             sage: H(1,2,3,4)
    348             [1 : 2 : 3 : 4]
    349         """
    350         # This may break for one-dimensional varieties.
    351         if len(arg) == 1:
    352             arg = arg[0]
    353         X = self.codomain()
    354         try:
    355             return X._point_class(X, arg)
    356         except AttributeError:  # should be very rare
    357             return SchemeMorphism_toric_coordinates_field(self, arg)
    358 
     751    pass
  • sage/schemes/generic/morphism.py

    diff --git a/sage/schemes/generic/morphism.py b/sage/schemes/generic/morphism.py
    a b  
    11"""
    22Scheme morphism
    33
     4.. note::
     5
     6    You should never create the morphisms directy. Instead, use the
     7    :meth:`~sage.schemes.generic.scheme.hom` and
     8    :meth:`~sage.structure.parent.Hom` methods that are inherited by
     9    all schemes.
     10
    411AUTHORS:
    512
    613- David Kohel, William Stein
     
    2431from point                    import is_SchemeTopologicalPoint
    2532import scheme                 
    2633
     34
    2735def is_SchemeMorphism(f):
    2836    """
    29     Return True if f is a scheme morphism or a point on an elliptic curve.
     37    Test whether ``f`` is a scheme morphism.
     38
     39    INPUT:
     40   
     41    - ``f`` -- anything.
     42
     43    OUTPUT:
     44   
     45    Boolean. Return ``True`` if ``f``a is a scheme morphism or a point
     46    on an elliptic curve.
    3047
    3148    EXAMPLES::
    3249
    33         sage: R.<x,y> = QQ[]; A.<x,y> = AffineSpace(R); H = A.Hom(A)
    34         sage: f = H([y,x^2+y])
    35         sage: sage.schemes.generic.morphism.is_SchemeMorphism(f)
     50        sage: A.<x,y> = AffineSpace(QQ,2); H = A.Hom(A)
     51        sage: f = H([y,x^2+y]); f
     52        Scheme endomorphism of Affine Space of dimension 2 over Rational Field
     53          Defn: Defined on coordinates by sending (x, y) to
     54                (y, x^2 + y)
     55        sage: from sage.schemes.generic.morphism import is_SchemeMorphism
     56        sage: is_SchemeMorphism(f)
    3657        True
    3758    """
    38     from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field # TODO: fix circular ref.
     59    from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field
    3960    return isinstance(f, (SchemeMorphism, EllipticCurvePoint_field));
    4061
    4162
    42 class PyMorphism(Element):
     63class SchemeMorphism(Element):
     64    """
     65    Base class for scheme morphisms
     66
     67    INPUT:
     68
     69    - ``parent`` -- the parent of the morphism.
     70
     71    EXAMPLES::
     72
     73        sage: from sage.schemes.generic.scheme import Scheme
     74        sage: X = Scheme(ZZ)
     75        sage: Hom = X.Hom(X)
     76        sage: from sage.schemes.generic.morphism import SchemeMorphism
     77        sage: f = SchemeMorphism(Hom)
     78        sage: type(f)
     79        <class 'sage.schemes.generic.morphism.SchemeMorphism'>
     80    """
    4381    def __init__(self, parent):
     82        """
     83        The Pyhon constructor.
     84       
     85        EXAMPLES::
     86       
     87            sage: from sage.schemes.generic.scheme import Scheme
     88            sage: X = Scheme(ZZ)
     89            sage: Hom = X.Hom(X)
     90            sage: from sage.schemes.generic.morphism import SchemeMorphism
     91            sage: f = SchemeMorphism(Hom)
     92            sage: type(f)
     93            <class 'sage.schemes.generic.morphism.SchemeMorphism'>
     94        """
    4495        if not isinstance(parent, Homset):
    4596            raise TypeError, "parent (=%s) must be a Homspace"%parent
    4697        Element.__init__(self, parent)
    4798        self._domain = parent.domain()
    4899        self._codomain = parent.codomain()
    49100
     101    def _repr_defn(self):
     102        r"""
     103        Return a string representation of the definition of ``self``.
     104
     105        OUTPUT:
     106
     107        String.
     108
     109        EXAMPLES::
     110
     111            sage: from sage.schemes.generic.scheme import Scheme
     112            sage: X = Scheme(ZZ)
     113            sage: Hom = X.Hom(X)
     114            sage: from sage.schemes.generic.morphism import SchemeMorphism
     115            sage: f = SchemeMorphism(Hom)
     116            sage: f._repr_defn()
     117            Traceback (most recent call last):
     118            ...
     119            NotImplementedError
     120        """
     121        raise NotImplementedError
     122
    50123    def _repr_type(self):
    51         return "Generic"
     124        r"""
     125        Return a string representation of the type of ``self``.
    52126
    53     def _repr_defn(self):
    54         return ""
     127        OUTPUT:
     128
     129        String.
     130
     131        EXAMPLES::
     132
     133            sage: from sage.schemes.generic.scheme import Scheme
     134            sage: X = Scheme(ZZ)
     135            sage: Hom = X.Hom(X)
     136            sage: from sage.schemes.generic.morphism import SchemeMorphism
     137            sage: f = SchemeMorphism(Hom)
     138            sage: f._repr_type()
     139            'Scheme'
     140        """
     141        return "Scheme"
    55142
    56143    def _repr_(self):
     144        r"""
     145        Return a string representation of ``self``.
     146
     147        OUTPUT:
     148
     149        String.
     150
     151        EXAMPLES::
     152
     153            sage: from sage.schemes.generic.scheme import Scheme
     154            sage: X = Scheme(ZZ)
     155            sage: Hom = X.Hom(X)
     156            sage: from sage.schemes.generic.morphism import SchemeMorphism
     157            sage: f = SchemeMorphism(Hom)
     158            sage: f._repr_()
     159            Traceback (most recent call last):
     160            ...
     161            NotImplementedError
     162        """
    57163        if self.is_endomorphism():
    58164            s = "%s endomorphism of %s"%(self._repr_type(), self.domain())
    59165        else:
     
    64170        if d != '':
    65171            s += "\n  Defn: %s"%('\n        '.join(self._repr_defn().split('\n')))
    66172        return s
    67        
     173
    68174    def domain(self):
     175        """
     176        Return the domain of the morphism.
     177
     178        OUTPUT:
     179
     180        A scheme. The domain of the morphism ``self``.
     181
     182        EXAMPLES::
     183
     184            sage: A2 = AffineSpace(QQ,2)
     185            sage: A2.structure_morphism().domain()
     186            Affine Space of dimension 2 over Rational Field
     187        """
    69188        return self._domain
    70189       
    71190    def codomain(self):
     191        """
     192        Return the codomain (range) of the morphism.
     193
     194        OUTPUT:
     195
     196        A scheme. The codomain of the morphism ``self``.
     197
     198        EXAMPLES::
     199       
     200            sage: A2 = AffineSpace(QQ,2)
     201            sage: A2.structure_morphism().codomain()
     202            Spectrum of Rational Field
     203        """
    72204        return self.parent().codomain()
    73205
    74206    def category(self):
     207        """
     208        Return the category of the hom set.
     209
     210        OUTPUT:
     211
     212        A category.
     213       
     214        EXAMPLES::
     215
     216        EXAMPLES::
     217       
     218            sage: A2 = AffineSpace(QQ,2)
     219            sage: A2.structure_morphism().category()
     220            Category of hom sets in Category of Schemes
     221        """
    75222        return self.parent().category()
    76223
    77224    def is_endomorphism(self):
     225        """
     226        Return wether the morphism is an endomorphism.
     227
     228        OUTPUT:
     229
     230        Boolean. Whether the domain and codomain are identical.
     231
     232        EXAMPLES::
     233
     234            sage: X = AffineSpace(QQ,2)
     235            sage: X.structure_morphism().is_endomorphism()
     236            False
     237            sage: X.identity_morphism().is_endomorphism()
     238            True
     239        """
    78240        return self.parent().is_endomorphism_set()
    79241
    80242    def _composition_(self, right, homset):
    81         return FormalCompositeMorphism(homset, right, self)
     243        """
     244        Helper to construct the composition of two morphisms.
     245
     246        EXAMPLES::
     247
     248            sage: X = AffineSpace(QQ,2)
     249            sage: f = X.structure_morphism()
     250            sage: g = X.identity_morphism()
     251            sage: f._composition_(g, f.parent())
     252            Traceback (most recent call last):
     253            ...
     254            NotImplementedError
     255
     256            sage: f * g
     257            Traceback (most recent call last):
     258            ...
     259            TypeError: unsupported operand type(s) for *: 'SchemeMorphism_structure_map' and 'SchemeMorphism_id'
     260        """
     261        raise NotImplementedError
    82262
    83263    def __pow__(self, n, dummy=None):
     264        """
     265        Exponentiate an endomorphism.
     266
     267        INPUT:
     268
     269        - ``n`` -- integer. The exponent.
     270
     271        OUTPUT:
     272
     273        A scheme morphism in the same endomorphism set as ``self``.
     274
     275        EXAMPLES::
     276
     277            sage: X = AffineSpace(QQ,2)
     278            sage: id = X.identity_morphism()
     279            sage: id^0
     280            Scheme endomorphism of Affine Space of dimension 2 over Rational Field
     281              Defn: Identity map
     282            sage: id^2
     283            Traceback (most recent call last):
     284            ...
     285            TypeError: unsupported operand type(s) for *: 'SchemeMorphism_id' and 'SchemeMorphism_id'
     286        """
    84287        if not self.is_endomorphism():
    85288            raise TypeError, "self must be an endomorphism."
    86         # todo -- what about the case n=0 -- need to specify the identity map somehow.
     289        if n==0:
     290            return self.domain().identity_morphism()
    87291        return generic_power(self, n)
    88292
    89 
    90 
    91 class SchemeMorphism(PyMorphism):
    92     """
    93     A scheme morphism
    94     """
    95     def __init__(self, parent):
    96         PyMorphism.__init__(self, parent)
    97 
    98     def _repr_type(self):
    99         return "Scheme"
    100 
    101293    def glue_along_domains(self, other):
    102294        r"""
     295        Glue two morphism
     296
     297        INPUT:
     298       
     299        - ``other`` -- a scheme morphism with the same domain.
     300
     301        OUTPUT:
     302
    103303        Assuming that self and other are open immersions with the same
    104304        domain, return scheme obtained by gluing along the images.
    105305       
     
    107307
    108308        We construct a scheme isomorphic to the projective line over
    109309        `\mathrm{Spec}(\QQ)` by gluing two copies of `\mathbb{A}^1`
    110         minus a point.
    111        
    112         ::
     310        minus a point::
    113311       
    114312            sage: R.<x,y> = PolynomialRing(QQ, 2)
    115313            sage: S.<xbar, ybar> = R.quotient(x*y - 1)
     
    129327            Scheme obtained by gluing X and Y along U, where
    130328              X: Spectrum of Univariate Polynomial Ring in x over Rational Field
    131329              Y: Spectrum of Univariate Polynomial Ring in y over Rational Field
    132               U: Spectrum of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
    133        
    134         ::
     330              U: Spectrum of Quotient of Multivariate Polynomial Ring in x, y
     331              over Rational Field by the ideal (x*y - 1)
    135332       
    136333            sage: a, b = P1.gluing_maps()
    137334            sage: a
    138335            Affine Scheme morphism:
    139              From: Spectrum of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
     336             From: Spectrum of Quotient of Multivariate Polynomial Ring in x, y
     337                   over Rational Field by the ideal (x*y - 1)
    140338              To:   Spectrum of Univariate Polynomial Ring in x over Rational Field
    141339              Defn: Ring morphism:
    142340                      From: Univariate Polynomial Ring in x over Rational Field
    143                       To:   Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
     341                      To:   Quotient of Multivariate Polynomial Ring in x, y over
     342                            Rational Field by the ideal (x*y - 1)
    144343                      Defn: x |--> xbar
    145344            sage: b
    146345            Affine Scheme morphism:
    147               From: Spectrum of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
     346              From: Spectrum of Quotient of Multivariate Polynomial Ring in x, y
     347                    over Rational Field by the ideal (x*y - 1)
    148348              To:   Spectrum of Univariate Polynomial Ring in y over Rational Field
    149349              Defn: Ring morphism:
    150350                      From: Univariate Polynomial Ring in y over Rational Field
    151                       To:   Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x*y - 1)
     351                      To:   Quotient of Multivariate Polynomial Ring in x, y over
     352                            Rational Field by the ideal (x*y - 1)
    152353                      Defn: y |--> ybar
    153354        """
    154355        import glue
     
    156357
    157358class SchemeMorphism_id(SchemeMorphism):
    158359    """
    159     Return the identity morphism from X to itself.
     360    Return the identity morphism from `X` to itself.
    160361   
     362    INPUT:
     363
     364    - ``X`` -- the scheme.
     365
    161366    EXAMPLES::
    162367   
    163368        sage: X = Spec(ZZ)
    164         sage: X.identity_morphism()
     369        sage: X.identity_morphism()  # indirect doctest
    165370        Scheme endomorphism of Spectrum of Integer Ring
    166371          Defn: Identity map
    167372    """
    168373    def __init__(self, X):
     374        """
     375        The Python constructor.
     376
     377        See :class:`SchemeMorphism_id` for details.
     378
     379        TESTS::
     380
     381            sage: Spec(ZZ).identity_morphism()
     382            Scheme endomorphism of Spectrum of Integer Ring
     383              Defn: Identity map
     384        """
    169385        SchemeMorphism.__init__(self, X.Hom(X))
    170386       
    171387    def _repr_defn(self):
    172         return "Identity map"
     388        r"""
     389        Return a string representation of the definition of ``self``.
     390
     391        OUTPUT:
     392
     393        String.
     394
     395        EXAMPLES::
     396       
     397            sage: Spec(ZZ).identity_morphism()._repr_defn()
     398            'Identity map'
     399        """
     400        return 'Identity map'
    173401
    174402
    175403class SchemeMorphism_structure_map(SchemeMorphism):
     404    r"""
     405    The structure morphism
     406
     407    INPUT:
     408
     409    - ``parent`` -- homset with codomain equal to the base scheme of
     410      the domain.
     411
     412    EXAMPLES::
     413
     414        sage: Spec(ZZ).structure_morphism()    # indirect doctest
     415        Scheme morphism:
     416          From: Spectrum of Integer Ring
     417          To:   Spectrum of Integer Ring
     418          Defn: Structure map
     419    """
    176420    def __init__(self, parent):
    177421        """
    178         INPUT:
     422        The Python constuctor.
    179423
    180         - ``parent`` - homset with codomain equal to the base
    181           scheme of the domain.
     424        See :class:`SchemeMorphism_structure_map` for details.
     425
     426        TESTS::
     427
     428            sage: from sage.schemes.generic.morphism import SchemeMorphism_structure_map
     429            sage: SchemeMorphism_structure_map( Spec(QQ).Hom(Spec(ZZ)) )
     430            Scheme morphism:
     431              From: Spectrum of Rational Field
     432              To:   Spectrum of Integer Ring
     433              Defn: Structure map
    182434        """
    183435        SchemeMorphism.__init__(self, parent)
    184436        if self.domain().base_scheme() != self.codomain():
    185437            raise ValueError, "parent must have codomain equal the base scheme of domain."
    186438
    187439    def _repr_defn(self):
    188         return "Structure map"
     440        r"""
     441        Return a string representation of the definition of ``self``.
     442
     443        OUTPUT:
     444
     445        String.
     446
     447        EXAMPLES::
     448       
     449            sage: Spec(ZZ).structure_morphism()._repr_defn()
     450            'Structure map'
     451        """
     452        return 'Structure map'
    189453
    190454
    191455class SchemeMorphism_spec(SchemeMorphism):
    192456    """
    193     A morphism of spectrums of rings
     457    Morphism of spectra of rings
     458
     459    INPUT:
     460
     461    - ``parent`` -- homset whose domain and codomain are affine schemes.
     462
     463    - ``phi`` -- a ring morphism with matching domain and codomain.
     464
     465    - ``check`` -- boolean (optional, default:``True``). Whether to
     466      check the input for consistency.
    194467   
    195468    EXAMPLES::
    196469   
     
    201474          To:   Rational Field
    202475          Defn: x |--> 7
    203476   
    204     ::
    205    
    206477        sage: X = Spec(QQ); Y = Spec(R)
    207478        sage: f = X.hom(phi); f
    208479        Affine Scheme morphism:
     
    213484                  To:   Rational Field
    214485                  Defn: x |--> 7
    215486   
    216     ::
    217    
    218487        sage: f.ring_homomorphism()
    219488        Ring morphism:
    220489          From: Univariate Polynomial Ring in x over Rational Field
     
    222491          Defn: x |--> 7
    223492    """
    224493    def __init__(self, parent, phi, check=True):
     494        """
     495        The Python constuctor.
     496
     497        See :class:`SchemeMorphism_structure_map` for details.
     498
     499        TESTS::
     500
     501            sage: from sage.schemes.generic.morphism import SchemeMorphism_spec
     502            sage: SchemeMorphism_spec(Spec(QQ).Hom(Spec(ZZ)), ZZ.hom(QQ))
     503            Affine Scheme morphism:
     504              From: Spectrum of Rational Field
     505              To:   Spectrum of Integer Ring
     506              Defn: Ring Coercion morphism:
     507                      From: Integer Ring
     508                      To:   Rational Field
     509        """
    225510        SchemeMorphism.__init__(self, parent)
    226511        if check:
    227512            if not is_RingHomomorphism(phi):
    228                 raise TypeError, "phi (=%s) must be a ring homomorphism"%phi
     513                raise TypeError("phi (=%s) must be a ring homomorphism" % phi)
    229514            if phi.domain() != parent.codomain().coordinate_ring():
    230                 raise TypeError, "phi (=%s) must have domain %s"%(phi,
    231                                                    parent.codomain().coordinate_ring())
     515                raise TypeError("phi (=%s) must have domain %s"
     516                                % (phi, parent.codomain().coordinate_ring()))
    232517            if phi.codomain() != parent.domain().coordinate_ring():
    233                 raise TypeError, "phi (=%s) must have codomain %s"%(phi,
    234                                                  parent.domain().coordinate_ring())
     518                raise TypeError("phi (=%s) must have codomain %s"
     519                                % (phi, parent.domain().coordinate_ring()))
    235520        self.__ring_homomorphism = phi
    236521
    237522    def __call__(self, P):
     523        r"""
     524        Make morphisms callable.
     525
     526        INPUT:
     527
     528        - ``P`` -- a scheme point.
     529
     530        OUTPUT:
     531
     532        The image scheme point.
     533
     534        EXAMPLES::
     535
     536            sage: R.<x> = PolynomialRing(QQ)
     537            sage: phi = R.hom([QQ(7)])
     538            sage: X = Spec(QQ); Y = Spec(R)
     539            sage: f = X.hom(phi)
     540            sage: f(X.an_element())
     541            Traceback (most recent call last):
     542            ...
     543            NotImplementedError
     544        """
    238545        if not is_SchemeTopologicalPoint(P) and P in self.domain():
    239546            raise TypeError, "P (=%s) must be a topological scheme point of %s"%(P, self)
    240547        S = self.ring_homomorphism().inverse_image(P.prime_ideal())
    241548        return self.codomain()(S)
    242549
    243550    def _repr_type(self):
     551        r"""
     552        Return a string representation of the type of ``self``.
     553
     554        OUTPUT:
     555
     556        String.
     557
     558        EXAMPLES::
     559
     560            sage: R.<x> = PolynomialRing(QQ)
     561            sage: phi = R.hom([QQ(7)])
     562            sage: X = Spec(QQ); Y = Spec(R)
     563            sage: f = X.hom(phi)
     564            sage: f._repr_type()
     565            'Affine Scheme'
     566        """
    244567        return "Affine Scheme"
    245568
    246569    def _repr_defn(self):
     570        r"""
     571        Return a string representation of the type of ``self``.
     572
     573        OUTPUT:
     574
     575        String.
     576
     577        EXAMPLES::
     578
     579            sage: R.<x> = PolynomialRing(QQ)
     580            sage: phi = R.hom([QQ(7)])
     581            sage: X = Spec(QQ); Y = Spec(R)
     582            sage: f = X.hom(phi)
     583            sage: f._repr_type()
     584            'Affine Scheme'
     585        """
    247586        return repr(self.ring_homomorphism())
    248587       
     588    def ring_homomorphism(self):
     589        """
     590        Return the underlying ring homomorphism.
    249591
    250     def ring_homomorphism(self):
     592        OUTPUT:
     593
     594        A ring homomorphism.
     595
     596        EXAMPLES::
     597
     598            sage: R.<x> = PolynomialRing(QQ)
     599            sage: phi = R.hom([QQ(7)])
     600            sage: X = Spec(QQ); Y = Spec(R)
     601            sage: f = X.hom(phi)
     602            sage: f.ring_homomorphism()
     603            Ring morphism:
     604              From: Univariate Polynomial Ring in x over Rational Field
     605              To:   Rational Field
     606              Defn: x |--> 7
     607        """
    251608        return self.__ring_homomorphism
    252609
    253610
     
    262619    """
    263620    A morphism of schemes determined by rational functions that define
    264621    what the morphism does on points in the ambient space.
     622
     623    INPUT:
     624
     625    - ``parent`` -- homset whose domain and codomain are affine schemes.
     626
     627    - ``polys`` -- a list/tuple/iterable of polynomials defining the
     628      scheme morphism.
     629
     630    - ``check`` -- boolean (optional, default:``True``). Whether to
     631      check the input for consistency.
    265632   
    266633    EXAMPLES:
    267634
     
    297664        sage: f = H([exp(x),exp(y)])
    298665        Traceback (most recent call last):
    299666        ...
    300         TypeError: polys (=[e^x, e^y]) must be elements of Multivariate Polynomial Ring in x, y over Rational Field
     667        TypeError: polys (=[e^x, e^y]) must be elements of Multivariate
     668        Polynomial Ring in x, y over Rational Field
    301669    """
    302670    def __init__(self, parent, polys, check=True):
     671        """
     672        The Python constructor.
     673
     674        See :class:`SchemeMorphism_on_points` for details.
     675
     676        EXAMPLES::
     677
     678            sage: A2.<x,y> = AffineSpace(QQ,2)
     679            sage: H = A2.Hom(A2)
     680            sage: H([x-y, x*y])
     681            Scheme endomorphism of Affine Space of dimension 2 over Rational Field
     682              Defn: Defined on coordinates by sending (x, y) to
     683                    (x - y, x*y)
     684        """
    303685        if check:
    304686            if not isinstance(polys, (list, tuple)):
    305687                raise TypeError, "polys (=%s) must be a list or tuple"%polys
     
    341723       
    342724    def defining_polynomials(self):
    343725        """
    344         Return the immutable sequence of polynomials that defines this
    345         scheme morphism.
     726        Return the defining polynomials.
     727
     728        OUTPUT:
     729
     730        An immutable sequence of polynomials that defines this scheme
     731        morphism.
    346732
    347733        EXAMPLES::
    348734
     
    358744        """
    359745        Apply this morphism to a point in the domain.
    360746
     747        INPUT:
     748
     749        - ``x`` -- anything that defines a point in the domain.
     750
     751        OUTPUT:
     752
     753        A point in the codomain.
     754
    361755        EXAMPLES::
    362756       
    363757            sage: R.<x,y> = QQ[]
     
    400794
    401795    def _repr_defn(self):
    402796        """
    403         This function is used internally for printing.
     797        Return a string representation of the definition of ``self``.
     798
     799        OUTPUT:
     800
     801        String.
    404802
    405803        EXAMPLES::
    406804
     
    437835          Defn: Defined on coordinates by sending (x, y) to
    438836                (x : y : 1)
    439837    """
     838    pass
    440839
    441840class SchemeMorphism_on_points_projective_space(SchemeMorphism_on_points):
    442841    """
     
    500899        sage: H([exp(x),exp(y)])
    501900        Traceback (most recent call last):
    502901        ...
    503         TypeError: polys (=[e^x, e^y]) must be elements of Multivariate Polynomial Ring in x, y over Rational Field
     902        TypeError: polys (=[e^x, e^y]) must be elements of
     903        Multivariate Polynomial Ring in x, y over Rational Field
    504904    """
    505905
    506906    def __init__(self, parent, polys, check=True):
     907        """
     908        The Python constructor.
     909
     910        See :class:`SchemeMorphism_on_points` for details.
     911
     912        EXAMPLES::
     913
     914            sage: P1.<x,y> = ProjectiveSpace(QQ,1)
     915            sage: H = P1.Hom(P1)
     916            sage: H([y,2*x])
     917            Scheme endomorphism of Projective Space of dimension 1 over Rational Field
     918              Defn: Defined on coordinates by sending (x : y) to
     919                    (y : 2*x)
     920        """
    507921        SchemeMorphism_on_points.__init__(self, parent, polys, check)
    508922        if check:
    509923            # morphisms from projective space are always given by
     
    526940############################################################################
    527941
    528942class SchemeMorphism_coordinates(SchemeMorphism):
     943    """
     944    Base class for rational points on schemes.
     945
     946    Recall that the `K`-rational points of a scheme `X` over `k` can
     947    be identified with the set of morphisms `Spec(K) \to X`. In Sage,
     948    the rational points are implemented by such scheme morphisms.
     949
     950    EXAMPLES::
     951
     952        sage: from sage.schemes.generic.morphism import SchemeMorphism
     953        sage: f = SchemeMorphism(Spec(ZZ).Hom(Spec(ZZ)))
     954        sage: type(f)
     955        <class 'sage.schemes.generic.morphism.SchemeMorphism'>
     956    """
    529957    def _repr_(self):
     958        r"""
     959        Return a string representation of ``self``.
     960
     961        OUTPUT:
     962
     963        String.
     964
     965        EXAMPLES::
     966       
     967            sage: A = AffineSpace(2, QQ)
     968            sage: a = A(1,2)
     969            sage: a._repr_()
     970            '(1, 2)'
     971        """
    530972        return self.codomain().ambient_space()._repr_generic_point(self._coords)
    531973
    532974    def _latex_(self):
     975        r"""
     976        Return a latex representation of ``self``.
     977
     978        OUTPUT:
     979
     980        String.
     981
     982        EXAMPLES::
     983       
     984            sage: A = AffineSpace(2, QQ)
     985            sage: a = A(1,2)
     986            sage: latex(a) == a._latex_()
     987            True
     988            sage: a._latex_()
     989            '\\left(1, 2\\right)'
     990        """
    533991        return self.codomain().ambient_space()._latex_generic_point(self._coords)
    534992
    535993    def __getitem__(self, n):
     994        """
     995        Return the ``n``-th coordinate.
     996
     997        OUTPUT:
     998
     999        The coordinate values as an element of the base ring.
     1000       
     1001        EXAMPLES::
     1002
     1003            sage: A = AffineSpace(2, QQ)
     1004            sage: a = A(1,2)
     1005            sage: a[0]
     1006            1
     1007            sage: a[1]
     1008            2
     1009        """
    5361010        return self._coords[n]
    5371011
    5381012    def __iter__(self):
     1013        """
     1014        Iterate over the coordinates of the point.
     1015
     1016        OUTPUT:
     1017
     1018        An iterator.
     1019
     1020        EXAMPLES::
     1021
     1022            sage: A = AffineSpace(2, QQ)
     1023            sage: a = A(1,2)
     1024            sage: iter = a.__iter__()
     1025            sage: iter.next()
     1026            1
     1027            sage: iter.next()
     1028            2
     1029            sage: list(a)
     1030            [1, 2]
     1031        """
    5391032        return iter(self._coords)
    5401033
    5411034    def __tuple__(self):
     1035        """
     1036        Return the coordinates as a tuple.
     1037
     1038        OUTPUT:
     1039
     1040        A tuple.
     1041       
     1042        EXAMPLES::
     1043       
     1044            sage: A = AffineSpace(2, QQ)
     1045            sage: a = A(1,2)
     1046            sage: tuple(a)
     1047            (1, 2)
     1048        """
    5421049        return self._coords
    5431050   
     1051    def __len__(self):
     1052        """
     1053        Return the number of coordinates.
     1054       
     1055        OUTPUT:
     1056
     1057        Integer. The number of coordinates used to describe the point.
     1058
     1059        EXAMPLES::
     1060
     1061            sage: A = AffineSpace(2, QQ)
     1062            sage: a = A(1,2)
     1063            sage: len(a)
     1064            2
     1065        """
     1066        return len(self._coords)
     1067   
    5441068    def __cmp__(self, other):
     1069        """
     1070        Compare two scheme morphisms.
     1071
     1072        INPUT:
     1073
     1074        - ``other`` -- anything. To compare against the scheme
     1075          morphism ``self``.
     1076
     1077        OUTPUT:
     1078
     1079        ``+1``, ``0``, or ``-1``.
     1080
     1081        EXAMPLES::
     1082
     1083            sage: A = AffineSpace(2, QQ)
     1084            sage: a = A(1,2)
     1085            sage: b = A(3,4)
     1086            sage: a.__cmp__(b)
     1087            -1
     1088            sage: a != b
     1089            True
     1090        """
    5451091        if not isinstance(other, SchemeMorphism_coordinates):
    5461092            try:
    5471093                other = self.codomain().ambient_space()(other)
     
    5501096        return cmp(self._coords, other._coords)
    5511097
    5521098    def scheme(self):
     1099        """
     1100        Return the scheme whose point is represented.
     1101
     1102        OUTPUT:
     1103
     1104        A scheme.
     1105
     1106        EXAMPLES::
     1107
     1108            sage: A = AffineSpace(2, QQ)
     1109            sage: a = A(1,2)
     1110            sage: a.scheme()
     1111            Affine Space of dimension 2 over Rational Field
     1112        """
    5531113        return self.codomain()
    5541114
    5551115
     
    5581118#*******************************************************************
    5591119class SchemeMorphism_affine_coordinates(SchemeMorphism_coordinates):
    5601120    """
    561     A morphism determined by giving coordinates in a ring.
     1121    A rational point on an affine scheme.
    5621122   
    5631123    INPUT:
    5641124   
     1125    - ``X`` -- a subscheme of an ambient affine space over a ring `R`.
    5651126   
    566     -  ``X`` - a subscheme of an ambient affine space over
    567        a ring R.
    568    
    569     -  ``v`` - a list or tuple of coordinates in R
    570    
     1127    - ``v`` -- a list/tuple/iterable of coordinates in `R`.
     1128
     1129    - ``check`` -- boolean (optional, default:``True``). Whether to
     1130      check the input for consistency.
    5711131   
    5721132    EXAMPLES::
    5731133   
     
    5761136        (1, 2)
    5771137    """
    5781138    def __init__(self, X, v, check=True):
    579         if scheme.is_Scheme(X):
    580             X = X(X.base_ring())
     1139        """
     1140        The Python constructor.
     1141
     1142        See :class:`SchemeMorphism_affine_coordinates` for details.
     1143
     1144        TESTS::
     1145
     1146            sage: from sage.schemes.generic.morphism import SchemeMorphism_affine_coordinates
     1147            sage: A3.<x,y,z> = AffineSpace(QQ, 3)
     1148            sage: SchemeMorphism_affine_coordinates(A3(QQ), [1,2,3])
     1149            (1, 2, 3)
     1150        """
    5811151        SchemeMorphism.__init__(self, X)
     1152        if is_SchemeMorphism(v):
     1153            v = list(v)
    5821154        if check:
    5831155            # Verify that there are the right number of coords
    584             d = X.codomain().ambient_space().ngens()
     1156            d = self.codomain().ambient_space().ngens()
    5851157            if len(v) != d:
    5861158                raise TypeError, \
    5871159                      "Argument v (=%s) must have %s coordinates."%(v, d)
    588             if is_SchemeMorphism(v):
    589                 v = list(v)
    5901160            if not isinstance(v,(list,tuple)):
    5911161                raise TypeError, \
    5921162                      "Argument v (= %s) must be a scheme point, list, or tuple."%str(v)
    5931163            # Make sure the coordinates all lie in the appropriate ring
    5941164            v = Sequence(v, X.value_ring())
    5951165            # Verify that the point satisfies the equations of X.
    596             X.codomain()._check_satisfies_equations(v)
    597         self._coords = v
     1166            X.extended_codomain()._check_satisfies_equations(v)
     1167        self._coords = tuple(v)
    5981168
    5991169   
    6001170#*******************************************************************
     
    6021172#*******************************************************************
    6031173class SchemeMorphism_projective_coordinates_ring(SchemeMorphism_coordinates):
    6041174    """
    605     A morphism determined by giving coordinates in a ring (how?).
     1175    A rational point of projective space over a ring (how?).
     1176
     1177    Currently this is not implemented.
     1178
     1179    EXAMPLES:
     1180
     1181        sage: from sage.schemes.generic.morphism import SchemeMorphism_projective_coordinates_ring
     1182        sage: SchemeMorphism_projective_coordinates_ring(None, None)
     1183        Traceback (most recent call last):
     1184        ...
     1185        NotImplementedError
     1186       
    6061187    """
    6071188    def __init__(self, X, v, check=True):
     1189        """
     1190        The Python constructor
     1191       
     1192        EXAMPLES:
     1193
     1194            sage: from sage.schemes.generic.morphism import SchemeMorphism_projective_coordinates_ring
     1195            sage: SchemeMorphism_projective_coordinates_ring(None, None)
     1196            Traceback (most recent call last):
     1197            ...
     1198            NotImplementedError
     1199        """
    6081200        raise NotImplementedError
    6091201
    6101202
    6111203class SchemeMorphism_projective_coordinates_field(SchemeMorphism_projective_coordinates_ring):
    6121204    """
    613     A morphism determined by giving coordinates in a field.
     1205    A rational point of projective space over a field.
    6141206   
    6151207    INPUT:
    6161208   
     1209    -  ``X`` -- a subscheme of an ambient projective space
     1210       over a field `K`
    6171211   
    618     -  ``X`` - a subscheme of an ambient projective space
    619        over a field K
     1212    - ``v`` -- a list or tuple of coordinates in `K`
    6201213   
    621     -  ``v`` - a list or tuple of coordinates in K
    622    
     1214    - ``check`` -- boolean (optional, default:``True``). Whether to
     1215      check the input for consistency.
    6231216   
    6241217    EXAMPLES::
    6251218   
    6261219        sage: P = ProjectiveSpace(3, RR)
    6271220        sage: P(2,3,4,5)
    6281221        (0.400000000000000 : 0.600000000000000 : 0.800000000000000 : 1.00000000000000)
    629    
    630     ::
     1222
     1223    Not all homogeneous coordinates are allowed to vanish simultaneously::
    6311224   
    6321225        sage: P = ProjectiveSpace(3, QQ)
    6331226        sage: P(0,0,0,0)
     
    6361229        ValueError: [0, 0, 0, 0] does not define a valid point since all entries are 0
    6371230    """
    6381231    def __init__(self, X, v, check=True):
    639         if scheme.is_Scheme(X):
    640             X = X(X.base_ring())
     1232        """
     1233        The Python constructor.
     1234
     1235        See :class:`SchemeMorphism_projective_coordinates_field` for details.
     1236       
     1237        EXAMPLES::
     1238
     1239        sage: P = ProjectiveSpace(2, CDF)
     1240        sage: P(2+I, 3-I, 4+5*I)
     1241        (0.317073170732 - 0.146341463415*I : 0.170731707317 - 0.463414634146*I : 1.0)
     1242        """
    6411243        SchemeMorphism.__init__(self, X)
    6421244        if check:
    643             from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field # TODO: fix circular ref.
     1245            from sage.schemes.elliptic_curves.ell_point import EllipticCurvePoint_field
    6441246            d = X.codomain().ambient_space().ngens()
    6451247            if is_SchemeMorphism(v) or isinstance(v, EllipticCurvePoint_field):
    6461248                v = list(v)
     
    6801282#*******************************************************************
    6811283# Abelian varieties
    6821284#*******************************************************************
    683 class SchemeMorphism_abelian_variety_coordinates_field(AdditiveGroupElement, SchemeMorphism_projective_coordinates_field):
    684     def __mul__(self, n):
    685         if isinstance(n, (RingElement, int, long)):
    686             # [n]*P - multiplication by n.
    687             return AdditiveGroupElement._rmul_(self, Integer(n))
    688         else:
    689             # Function composition
    690             return SchemeMorphism_projective_coordinates_field.__mul__(self, n) 
     1285class SchemeMorphism_abelian_variety_coordinates_field\
     1286        (AdditiveGroupElement, SchemeMorphism_projective_coordinates_field):
     1287    """
     1288    A rational point of an abelian variety over a field.
    6911289
     1290    EXAMPLES::
     1291     
     1292        sage: E = EllipticCurve([0,0,1,-1,0])
     1293        sage: origin = E(0)
     1294        sage: origin.domain()
     1295        Spectrum of Rational Field
     1296        sage: origin.codomain()
     1297        Elliptic Curve defined by y^2 + y = x^3 - x over Rational Field
     1298    """
     1299    pass
    6921300
    6931301
     1302
     1303
  • sage/schemes/generic/projective_space.py

    diff --git a/sage/schemes/generic/projective_space.py b/sage/schemes/generic/projective_space.py
    a b  
    176176        Spectrum of Rational Field
    177177        sage: X.base_ring()
    178178        Rational Field
    179         sage: X.structure_morphism ()
     179        sage: X.structure_morphism()
    180180        Scheme morphism:
    181181          From: Projective Space of dimension 3 over Rational Field
    182182          To:   Spectrum of Rational Field
  • sage/schemes/generic/scheme.py

    diff --git a/sage/schemes/generic/scheme.py b/sage/schemes/generic/scheme.py
    a b  
    1919#*******************************************************************************
    2020
    2121from sage.structure.parent import Parent
     22from sage.misc.all import cached_method
    2223from sage.rings.all import (IntegerRing, is_CommutativeRing,
    2324                            ZZ, is_RingHomomorphism, GF, PowerSeriesRing,
    2425                            Rationals)
    2526
    2627def is_Scheme(x):
    2728    """
    28     Return True if `x` is a scheme.
     29    Test whether ``x`` is a scheme.
     30   
     31    INPUT:
     32   
     33    - ``x`` -- anything.
     34
     35    OUTPUT:
     36
     37    Boolean. Whether ``x`` derives from :class:`Scheme`.
    2938   
    3039    EXAMPLES::
    3140   
     
    3948    return isinstance(x, Scheme)
    4049
    4150
    42 # If a derived class sets any of the properties, _base_scheme, _base_ring,
    43 # or _base_morphism, it will determine the others.  If none are set,
    44 # the base defaults to Spec(Z) with the canonical morphism.
    4551
    4652class Scheme(Parent):
    47     def __init__(self, X, category = None):
     53    """
     54    The base class for all schemes.
     55
     56    INPUT:
     57
     58    - ``X`` -- a scheme, scheme morphism, commutative ring,
     59      commutative ring morphism, or ``None`` (optional). Determines
     60      the base scheme. If a commutative ring is passed, the spectrum
     61      of the ring will be used as base.
     62
     63    - ``category`` -- the category (optional). Will be automatically
     64      construted by default.
     65
     66    EXAMPLES::
     67
     68        sage: from sage.schemes.generic.scheme import Scheme
     69        sage: Scheme(ZZ)
     70        <class 'sage.schemes.generic.scheme.Scheme_with_category'>
     71
     72    A scheme is in the category of all schemes over its base::
     73
     74        sage: ProjectiveSpace(4, QQ).category()
     75        Category of schemes over Rational Field
     76
     77    There is a special and unique `Spec(\ZZ)` that is the default base
     78    scheme::
     79
     80        sage: Spec(ZZ).base_scheme() is Spec(QQ).base_scheme()
     81        True
     82    """
     83
     84    def __init__(self, X=None, category=None):
    4885        """
    49         A scheme.
    50        
     86        Construct a scheme.
     87
    5188        TESTS::
    5289       
    5390            sage: R.<x, y> = QQ[]
     
    5693            sage: X = Spec(RmodI)
    5794            sage: TestSuite(X).run(skip = ["_test_an_element", "_test_elements",
    5895            ...                            "_test_some_elements", "_test_category"]) # See #7946
    59 
    60         A scheme is in the category of all schemes over the base scheme of self::
    61 
    62             sage: ProjectiveSpace(4, QQ).category()
    63             Category of schemes over Spectrum of Rational Field
    6496        """
    6597        from sage.schemes.generic.spec import is_Spec
    66         if is_Spec(X):
    67             self._base_ring = X.coordinate_ring()
    68             base = self._base_ring
     98        from sage.schemes.generic.morphism import is_SchemeMorphism
     99
     100        if X is None:
     101            try:
     102                from sage.schemes.generic.spec import SpecZ
     103                self._base_scheme = SpecZ
     104            except ImportError:  # we are currently constructing SpecZ
     105                self._base_ring = ZZ
     106        elif is_Scheme(X):
     107            self._base_scheme = X
     108        elif is_SchemeMorphism(X):
     109            self._base_morphism = X
     110        elif is_CommutativeRing(X):
     111            self._base_ring = X
     112        elif is_RingHomomorphism(X):
     113            self._base_ring = X.codomain()
    69114        else:
    70             self._base_scheme = X
    71             base = self._base_scheme
    72 
     115            raise ValueError('The base must be define by a scheme, '
     116                             'scheme morphism, or commutative ring.')
     117       
    73118        from sage.categories.schemes import Schemes
    74         default_category = Schemes(self.base_scheme())
     119        if not X:
     120            default_category = Schemes()
     121        else:
     122            default_category = Schemes(self.base_scheme())
    75123        if category is None:
    76124            category = default_category
    77125        else:
    78126            assert category.is_subcategory(default_category), \
    79127                "%s is not a subcategory of %s"%(category, default_category)
    80128
    81         Parent.__init__(self, base, category = category)
     129        Parent.__init__(self, self.base_ring(), category = category)
    82130
    83     def __cmp__(self, X):
     131    def __cmp__(left, right):
    84132        """
     133        Compare two schemes.
     134
     135        INPUT:
     136
     137        - ``right`` -- anything. To compare against the scheme
     138          ``left``.
     139
     140        OUTPUT:
     141
     142        ``+1``, ``0``, or ``-1``.
     143
    85144        EXAMPLES::
    86        
     145   
    87146            sage: X = Spec(QQ);  Y = Spec(QQ)
    88147            sage: X == Y
    89148            True
    90149            sage: X is Y
    91150            False
    92151        """
    93         if not isinstance(X, self.__class__):
     152        if not is_Scheme(right):
    94153            return -1
    95         return self._cmp_(X)
     154        return left._cmp_(right)
    96155
    97156    def union(self, X):
    98157        """
    99         Return the disjoint union of the schemes self and X.
     158        Return the disjoint union of the schemes ``self`` and ``X``.
    100159       
    101160        EXAMPLES::
    102161       
     
    138197
    139198    def base_extend(self, Y):
    140199        """
    141         Y is either a scheme in the same category as self or a ring.
    142        
     200        Extend the base of the scheme.
     201
     202        Derived clases must override this method.
     203
    143204        EXAMPLES::
    144205       
    145             sage: X = Spec(QQ)
     206            sage: from sage.schemes.generic.scheme import Scheme
     207            sage: X = Scheme(ZZ)
    146208            sage: X.base_scheme()
    147209            Spectrum of Integer Ring
    148210            sage: X.base_extend(QQ)
     
    154216
    155217    def __call__(self, *args):
    156218        """
    157         If S is a ring or scheme, return the set `X(S)` of
    158         `S`-valued points on `X`. If `S` is a list
    159         or tuple or just the coordinates, return a point in `X(T)`,
    160         where `T` is the base scheme of self.
     219        Call syntax for schemes.
     220
     221        INPUT/OUTPUT:
     222       
     223        The arguments must be one of the following:
     224
     225        - a ring or a scheme `S`. Output will be the set `X(S)` of
     226          `S`-valued points on `X`.
     227
     228        - If `S` is a list or tuple or just the coordinates, return a
     229          point in `X(T)`, where `T` is the base scheme of self.
    161230       
    162231        EXAMPLES::
    163232       
     
    166235        We create some point sets::
    167236       
    168237            sage: A(QQ)
    169             Set of Rational Points of Affine Space of dimension 2 over Rational Field           
     238            Set of rational points of Affine Space of dimension 2 over Rational Field
    170239            sage: A(RR)
    171             Set of Rational Points of Affine Space of dimension 2 over Real Field with 53 bits of precision
     240            Set of rational points of Affine Space of dimension 2 over Real Field
     241            with 53 bits of precision
    172242       
    173         Space of dimension 2 over Rational Field
    174        
    175         ::
     243        Space of dimension 2 over Rational Field::
    176244       
    177245            sage: R.<x> = PolynomialRing(QQ)
    178246            sage: A(NumberField(x^2+1, 'a'))
    179             Set of Rational Points of Affine Space of dimension 2 over Number Field in a with defining polynomial x^2 + 1
     247            Set of rational points of Affine Space of dimension 2 over Number Field
     248            in a with defining polynomial x^2 + 1
    180249            sage: A(GF(7))
    181250            Traceback (most recent call last):
    182251            ...
    183             ValueError: no natural map from the base ring (=Rational Field) to R (=Finite Field of size 7)!
     252            ValueError: There must be a natural map S --> R, but
     253            S = Rational Field and R = Finite Field of size 7
    184254       
    185255        We create some points::
    186256       
     
    188258            (1, 0)
    189259       
    190260        We create the same point by giving the coordinates of the point
    191         directly.
    192        
    193         ::
     261        directly::
    194262       
    195263            sage: A( 1,0 )
    196264            (1, 0)
    197265        """
    198266        if len(args) == 0:
    199             raise TypeError, "0-dimensional affine space has no points"
     267            raise TypeError('You need to specify at least one argument.')
    200268       
    201269        S = args[0]
    202270        if is_CommutativeRing(S):
     
    219287                    return self.point(S)
    220288        return self.point(args)
    221289
     290    @cached_method
    222291    def point_homset(self, S = None):
    223292        """
    224293        Return the set of S-valued points of this scheme.
     294
     295        INPUT:
     296
     297        - ``S`` -- a commutative ring.
     298
     299        OUTPUT:
     300
     301        The set of morphisms `Spec(S)\to X`.
    225302       
    226303        EXAMPLES::
    227304       
    228305            sage: P = ProjectiveSpace(ZZ, 3)
    229306            sage: P.point_homset(ZZ)
    230             Set of Rational Points of Projective Space of dimension 3 over Integer Ring
     307            Set of rational points of Projective Space of dimension 3 over Integer Ring
    231308            sage: P.point_homset(QQ)
    232             Set of Rational Points of Projective Space of dimension 3 over Rational Field
     309            Set of rational points of Projective Space of dimension 3 over Rational Field
    233310            sage: P.point_homset(GF(11))
    234             Set of Rational Points of Projective Space of dimension 3 over Finite Field of size 11
     311            Set of rational points of Projective Space of dimension 3 over
     312            Finite Field of size 11
     313
     314        TESTS::
     315
     316            sage: P = ProjectiveSpace(QQ,3)
     317            sage: P.point_homset(GF(11))
     318            Traceback (most recent call last):
     319            ...
     320            ValueError: There must be a natural map S --> R, but
     321            S = Rational Field and R = Finite Field of size 11
    235322        """
    236         if S is None or S == self.base_ring():
    237             # optimize common case
    238             try:
    239                 return self.__ring_point_homset
    240             except AttributeError:
    241                 self.__ring_point_homset = self._homset_class(self,self.base_ring())
    242                 return self.__ring_point_homset
    243         try:
    244             return self.__point_homset[S]
    245         except AttributeError:
    246             self.__point_homset = {}
    247         except KeyError:
    248             pass
    249         H = self._homset_class(self, S)
    250         self.__point_homset[S] = H
    251         return H
     323        if S is None:
     324            S = self.base_ring()
     325        from sage.schemes.generic.spec import Spec
     326        SpecS = Spec(S, self.base_ring())
     327        from sage.schemes.generic.homset import SchemeHomset
     328        return SchemeHomset(SpecS, self)
    252329
    253330    def point(self, v, check=True):
    254         return self._point_class(self, v, check=check)
     331        """
     332        Create a point.
     333
     334        INPUT:
     335       
     336        - ``v`` -- anything that defines a point.
     337
     338        - ``check`` -- boolean (optional, default=``True``). Whether
     339          to check the defining data for consistency.
     340
     341        OUTPUT:
     342
     343        A point of the scheme.
     344
     345        EXAMPLES::
     346       
     347            sage: A2 = AffineSpace(QQ,2)
     348            sage: A2.point([4,5])
     349            (4, 5)
     350        """
     351        # todo: update elliptic curve stuff to take point_homset as argument
     352        from sage.schemes.elliptic_curves.ell_generic import is_EllipticCurve
     353        if is_EllipticCurve(self):
     354            return self._point_class(self, v, check=check)
     355
     356        return self._point_class(self.point_homset(), v, check=check)
    255357   
    256358    def _point_class(self):
    257359        """
     360        Return the Hom set from some affine scheme to ``self``.
     361
     362        OUTPUT:
     363
     364        A scheme hom set, see :mod:`~sage.schemes.generic.homset`.
     365
    258366        EXAMPLES::
    259367       
    260368            sage: X = Spec(QQ)
     
    265373        """
    266374        raise NotImplementedError
    267375
    268     def _homset_class(self):
     376    def _homset_class(self, *args, **kwds):
    269377        """
     378        Return the Hom set from ``self`` to another scheme.
     379
    270380        EXAMPLES::
    271381       
    272             sage: X = Spec(QQ)
     382            sage: from sage.schemes.generic.scheme import Scheme
     383            sage: X = Scheme(QQ)
    273384            sage: X._homset_class()
    274385            Traceback (most recent call last):
    275386            ...
     
    277388        """
    278389        raise NotImplementedError
    279390
    280 
    281391    def __div__(self, Y):
    282392        """
    283393        Return the base extension of self to Y.
    284394       
     395        See :meth:`base_extend` for details.
     396       
    285397        EXAMPLES::
    286398       
    287399            sage: A = AffineSpace(3, ZZ)
     
    298410        """
    299411        Return the base ring of the scheme self.
    300412       
     413        OUTPUT:
     414
     415        A commutative ring.
     416
    301417        EXAMPLES::
    302418       
    303419            sage: A = AffineSpace(4, QQ)
    304420            sage: A.base_ring()
    305421            Rational Field
    306422       
    307         ::
    308        
    309423            sage: X = Spec(QQ)
    310424            sage: X.base_ring()
    311425            Integer Ring
     
    323437
    324438    def base_scheme(self):
    325439        """
    326         Return the base scheme of the scheme self.
     440        Return the base scheme.
     441
     442        OUTPUT:
     443
     444        A scheme.
    327445       
    328446        EXAMPLES::
    329447       
     
    331449            sage: A.base_scheme()
    332450            Spectrum of Rational Field
    333451       
    334         ::
    335        
    336452            sage: X = Spec(QQ)
    337453            sage: X.base_scheme()
    338454            Spectrum of Integer Ring
     
    340456        try:
    341457            return self._base_scheme
    342458        except AttributeError:
    343             from sage.schemes.generic.spec import Spec, SpecZ
    344459            if hasattr(self, '_base_morphism'):
    345460                self._base_scheme = self._base_morphism.codomain()
    346461            elif hasattr(self, '_base_ring'):
    347                 import spec
     462                from sage.schemes.generic.spec import Spec
    348463                self._base_scheme = Spec(self._base_ring)
    349464            else:
    350                 import spec               
     465                from sage.schemes.generic.spec import SpecZ
    351466                self._base_scheme = SpecZ
    352467            return self._base_scheme
    353468
    354469    def base_morphism(self):
    355470        """
    356         Return the structure morphism from the scheme self to its base
     471        Return the structure morphism from ``self`` to its base
    357472        scheme.
     473
     474        OUTPUT:
     475
     476        A scheme morphism.
    358477       
    359478        EXAMPLES::
    360479       
     
    365484              To:   Spectrum of Rational Field
    366485              Defn: Structure map
    367486       
    368         ::
    369        
    370487            sage: X = Spec(QQ)
    371488            sage: X.base_morphism()
    372489            Scheme morphism:
     
    392509
    393510    def coordinate_ring(self):
    394511        """
    395         Return the coordinate ring of this scheme, if defined. Otherwise
    396         raise a ValueError.
     512        Return the coordinate ring.
     513
     514        OUTPUT:
     515
     516        The global coordinate ring of this scheme, if
     517        defined. Otherwise raise a ``ValueError``.
    397518       
    398519        EXAMPLES::
    399520       
     
    412533        """
    413534        Return the absolute dimension of this scheme.
    414535       
     536        OUTPUT:
     537
     538        Integer.
     539
    415540        EXAMPLES::
    416541       
    417542            sage: R.<x, y> = QQ[]
     
    433558    def dimension_relative(self):
    434559        """
    435560        Return the relative dimension of this scheme over its base.
     561
     562        OUTPUT:
     563
     564        Integer.
    436565       
    437566        EXAMPLES::
    438567       
     
    448577
    449578    def identity_morphism(self):
    450579        """
    451         Return the identity morphism of the scheme self.
     580        Return the identity morphism.
     581
     582        OUTPUT:
     583
     584        The identity morphism of the scheme ``self``.
    452585       
    453586        EXAMPLES::
    454587       
     
    462595
    463596    def hom(self, x, Y=None, check=True):
    464597        """
    465         Return the scheme morphism from self to Y defined by x. If x is a
    466         scheme, try to determine a natural map to x.
     598        Return the scheme morphism from ``self`` to ``Y`` defined by ``x``.
     599
     600        INPUT:
     601
     602        - ``x`` -- anything hat determines a scheme morphism. If ``x``
     603          is a scheme, try to determine a natural map to ``x``.
    467604       
    468         If Y is not given, try to determine Y from context.
     605        - ``Y`` -- the codomain scheme (optional). If ``Y`` is not
     606          given, try to determine ``Y`` from context.
     607
     608        - ``check`` -- boolean (optional, default=``True``). Whether
     609          to check the defining data for consistency.
     610
     611        OUTPUT:
     612
     613        The scheme morphism from ``self`` to ``Y`` defined by ``x``.
    469614       
    470615        EXAMPLES::
    471616       
     
    485630
    486631    def _Hom_(self, Y, category=None, check=True):
    487632        """
    488         Return the set of scheme morphisms from self to Y.
     633        Return the set of scheme morphisms from ``self`` to ``Y``.
     634
     635        INPUT:
     636
     637        - ``Y`` -- a scheme. The codomain of the Hom set.
     638
     639        - ``category`` -- a category (optional). The category of the
     640          Hom set.
     641
     642        - ``check`` -- boolean (optional, default=``True``). Whether
     643          to check the defining data for consistency.
     644
     645        OUTPUT:
     646
     647        The set of morphisms from ``self`` to ``Y``.
    489648       
    490649        EXAMPLES::
    491650       
    492651            sage: P = ProjectiveSpace(ZZ, 3)
    493652            sage: S = Spec(ZZ)
    494653            sage: S._Hom_(P)
    495             Set of points of Projective Space of dimension 3 over Integer Ring defined over Integer Ring
     654            Set of rational points of Projective Space of dimension 3 over Integer Ring
    496655        """
    497656        from sage.schemes.generic.homset import SchemeHomset
    498657        return SchemeHomset(self, Y, category=category, check=check)
     
    501660
    502661    def count_points(self, n):
    503662        r"""
    504         Count points over
    505         `\GF{q}, \ldots, \GF{q^n}` on a scheme over
    506         a finite field `\GF{q}`.
     663        Count points over finite fields.
     664
     665        INPUT:
     666
     667        - ``n`` -- integer.
     668
     669        OUTPUT:
     670
     671        An integer. The number of points over `\GF{q}, \ldots,
     672        \GF{q^n}` on a scheme over a finite field `\GF{q}`.
    507673       
    508674        .. note::
    509675
     
    521687            ...
    522688            NotImplementedError: Point counting only implemented for schemes over prime fields
    523689        """
    524        
    525690        F = self.base_ring()
    526691        if not F.is_finite():
    527692            raise TypeError, "Point counting only defined for schemes over finite fields"
     
    537702   
    538703    def zeta_series(self, n, t):
    539704        """
     705        Return the zeta series.
     706
    540707        Compute a power series approximation to the zeta function of a
    541708        scheme over a finite field.
    542        
     709
    543710        INPUT:
    544711       
    545        
    546712        -  ``n`` - the number of terms of the power series to
    547713           compute
    548714       
     
    550716           returned
    551717       
    552718       
    553         OUTPUT: A power series approximating the zeta function of self
     719        OUTPUT:
    554720       
     721        A power series approximating the zeta function of self
     722
    555723        EXAMPLES::
    556724       
    557725            sage: P.<x> = PolynomialRing(GF(3))
     
    602770    """
    603771    def hom(self, x, Y=None):
    604772        r"""
    605         Return the scheme morphism from self to Y defined by x.
     773        Return the scheme morphism from ``self`` to ``Y`` defined by ``x``.
     774
     775        INPUT:
     776
     777        - ``x`` -- anything hat determines a scheme morphism. If ``x``
     778          is a scheme, try to determine a natural map to ``x``.
    606779       
    607         If Y is not given, try to determine from context.
     780        - ``Y`` -- the codomain scheme (optional). If ``Y`` is not
     781          given, try to determine ``Y`` from context.
     782
     783        - ``check`` -- boolean (optional, default=``True``). Whether
     784          to check the defining data for consistency.
     785
     786        OUTPUT:
     787
     788        The scheme morphism from ``self`` to ``Y`` defined by ``x``.
    608789       
    609         EXAMPLES: We construct the inclusion from
    610         `\mathrm{Spec}(\QQ)` into `\mathrm{Spec}(\ZZ)`
    611         induced by the inclusion from `\ZZ` into
    612         `\QQ`.
    613        
    614         ::
     790        EXAMPLES:
     791
     792        We construct the inclusion from `\mathrm{Spec}(\QQ)` into
     793        `\mathrm{Spec}(\ZZ)` induced by the inclusion from `\ZZ` into
     794        `\QQ`::
    615795       
    616796            sage: X = Spec(QQ)
    617797            sage: X.hom(ZZ.hom(QQ))
     
    629809                import spec
    630810                Y = spec.Spec(x.domain())
    631811        return Scheme.hom(self, x, Y)
    632 
    633 
    634 #import morphism
    635 #import spec
  • sage/schemes/generic/spec.py

    diff --git a/sage/schemes/generic/spec.py b/sage/schemes/generic/spec.py
    a b  
    11"""
    2 Spec of a ring
     2Spectrum of a ring as affine scheme.
    33"""
    44
    55#*******************************************************************************
     
    1010
    1111from sage.rings.commutative_ring import is_CommutativeRing
    1212from sage.rings.integer_ring import ZZ
    13 import scheme
    14 import point
     13
     14from sage.schemes.generic.scheme import AffineScheme
     15from sage.schemes.generic.point import SchemeTopologicalPoint_prime_ideal
     16
    1517
    1618def is_Spec(X):
    1719    """
     20    Test whether ``X`` is a Spec.
     21
     22    INPUT:
     23
     24    - ``X`` -- anything.
     25
     26    OUTPUT:
     27
     28    Boolean.
     29
    1830    EXAMPLES::
    1931   
    2032        sage: from sage.schemes.generic.spec import is_Spec
     
    2739    """
    2840    return isinstance(X, Spec)
    2941
    30 class Spec(scheme.AffineScheme):
     42class Spec(AffineScheme):
    3143    r"""
    3244    The spectrum of a commutative ring, as a scheme.
    3345   
     
    3749        schemes, which is important for gluing to construct more
    3850        general schemes.
    3951   
     52    INPUT:
     53       
     54    - ``R`` -- a commutative ring.
     55   
     56    - ``S`` -- a commutative ring (optional, default:`\ZZ`). The base
     57      ring.
     58
    4059    EXAMPLES::
    4160   
    4261        sage: Spec(QQ)
     
    4766        Spectrum of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
    4867        sage: X = Spec(PolynomialRing(GF(49,'a'), 3, 'x')); X
    4968        Spectrum of Multivariate Polynomial Ring in x0, x1, x2 over Finite Field in a of size 7^2
    50         sage: TestSuite(X).run(skip = ["_test_an_element", "_test_elements", "_test_some_elements", "_test_category"]) # see # 7946
     69        sage: TestSuite(X).run(skip = ["_test_an_element", "_test_elements",
     70        ...                            "_test_some_elements"])
    5171
    5272        sage: A = Spec(ZZ); B = Spec(ZZ)
    5373        sage: A is B
     
    5575        sage: A == B
    5676        True
    5777   
    58     A TypeError is raised if the input is not a CommutativeRing.
    59    
    60     ::
     78    A ``TypeError`` is raised if the input is not a commutative ring::
    6179   
    6280        sage: Spec(5)
    6381        Traceback (most recent call last):
     
    6684        sage: Spec(FreeAlgebra(QQ,2, 'x'))
    6785        Traceback (most recent call last):
    6886        ...
    69         TypeError: R (=Free Algebra on 2 generators (x0, x1) over Rational Field) must be a commutative ring
     87        TypeError: R (=Free Algebra on 2 generators (x0, x1) over
     88        Rational Field) must be a commutative ring
    7089   
    71     EXAMPLES::
     90    TESTS::
    7291   
    7392        sage: X = Spec(ZZ)
    7493        sage: X
     
    7998        Integer Ring
    8099        sage: X.dimension()
    81100        1
     101        sage: Spec(QQ,QQ).base_scheme()
     102        Spectrum of Rational Field
     103        sage: Spec(RDF,QQ).base_scheme()
     104        Spectrum of Rational Field
    82105    """
    83     def __init__(self, R, S=None, check=True):
     106    def __init__(self, R, S=None):
    84107        """
     108        Construct the spectrum of the ring ``R``.
     109
     110        See :class:`Spec` for details.
     111       
    85112        EXAMPLES::
    86113
    87114            sage: Spec(ZZ)
     
    97124                S.hom(R)
    98125            except TypeError:
    99126                raise ValueError, "There must be a natural map S --> R, but S = %s and R = %s"%(S,R)
    100             self._base_ring = S
     127        AffineScheme.__init__(self, S)
    101128
    102129    def _cmp_(self, X):
    103130        """
    104         Return the result of the comparison of self and X.
     131        Compare ``self`` and ``X``.
    105132
    106133        Spec's are compared with self using comparison of the
    107134        underlying rings.  If X is not a Spec, then the result is
    108135        platform-dependent (either self < X or X < self, but never
    109136        self == X).
     137
     138        INPUT:
     139
     140        - ``X`` -- anything.
     141
     142        OUTPUT:
     143
     144        ``+1``, ``0``, or ``-1``.
    110145       
    111146        EXAMPLES::
    112147
     
    130165   
    131166    def __hash__(self):
    132167        """
     168        Return the hash value.
     169       
     170        OUTPUT:
     171
     172        A 32/64-bit hash value, depending on architecture.
     173
    133174        TESTS::
    134175           
    135176            sage: hash(Spec(ZZ))
     
    145186
    146187    def _repr_(self):
    147188        """
     189        Return a string representation of ``self``.
     190       
     191        OUTPUT:
     192
     193        String.
     194       
    148195        EXAMPLES::
    149196       
    150197            sage: Spec(PolynomialRing(QQ, 3, 'x'))
     
    161208        """
    162209        LaTeX representation of this Spec.
    163210       
     211        OUTPUT:
     212
     213        String.
     214       
    164215        EXAMPLES::
    165216       
    166217            sage: S = Spec(PolynomialRing(ZZ, 2, 'x'))
     
    173224
    174225    def __call__(self, x):
    175226        """
    176         Create a point of this Spec.  The argument `x` can be a prime
    177         ideal of the coordinate ring, or an element (or list of
    178         elements) of the coordinate ring which generates a prime
    179         ideal.
     227        Call syntax for Spec.
     228       
     229        INPUT:
     230
     231        - ``x`` -- a prime ideal of the coordinate ring, or an element
     232          (or list of elements) of the coordinate ring which generates
     233          a prime ideal.
     234
     235        OUTPUT:
     236       
     237        A point of this Spec.
    180238
    181239        EXAMPLES::
    182240
     
    188246            sage: S(ZZ.ideal(next_prime(1000000)))
    189247            Point on Spectrum of Integer Ring defined by the Principal ideal (1000003) of Integer Ring
    190248           
    191         ::
    192 
    193249            sage: R.<x, y, z> = QQ[]
    194250            sage: S = Spec(R)
    195251            sage: P = S(R.ideal(x, y, z)); P
    196             Point on Spectrum of Multivariate Polynomial Ring in x, y, z over Rational Field defined by the Ideal (x, y, z) of Multivariate Polynomial Ring in x, y, z over Rational Field
     252            Point on Spectrum of Multivariate Polynomial Ring
     253            in x, y, z over Rational Field defined by the Ideal (x, y, z)
     254            of Multivariate Polynomial Ring in x, y, z over Rational Field
    197255        """
    198         return point.SchemeTopologicalPoint_prime_ideal(self, x)
     256        return SchemeTopologicalPoint_prime_ideal(self, x)
     257
     258    def _an_element_(self):
     259        r"""
     260        Return an element of the spectrum of the ring.
     261       
     262        OUTPUT:
     263
     264        A point of the affine scheme ``self``.
     265
     266        EXAMPLES::
     267
     268            sage: Spec(QQ).an_element()
     269            Point on Spectrum of Rational Field defined by the Principal ideal (0) of Rational Field
     270            sage: Spec(ZZ).an_element()    # random output
     271            Point on Spectrum of Integer Ring defined by the Principal ideal (811) of Integer Ring
     272        """
     273        if self.coordinate_ring() is ZZ:
     274            from sage.rings.arith import random_prime
     275            return self(random_prime(1000))
     276        return self(0)
    199277
    200278    def coordinate_ring(self):
    201279        """
    202280        Return the underlying ring of this scheme.
    203281       
     282        OUTPUT:
     283
     284        A commutative ring.
     285       
    204286        EXAMPLES::
    205287       
    206288            sage: Spec(QQ).coordinate_ring()
     
    212294
    213295    def is_noetherian(self):
    214296        """
    215         Return True if this scheme is Noetherian.
     297        Test whether ``self`` is Noetherian.
     298
     299        OUTPUT:
     300
     301        Boolean. Return True if this scheme is Noetherian.
    216302
    217303        EXAMPLES::
    218304
     
    225311        """
    226312        Return the absolute dimension of this scheme.
    227313
     314        OUTPUT:
     315       
     316        Integer.
     317       
    228318        EXAMPLES::
    229319
    230320            sage: S = Spec(ZZ)
     
    241331        """
    242332        Return the relative dimension of this scheme over its base.
    243333
     334        OUTPUT:
     335       
     336        Integer.
     337       
    244338        EXAMPLES::
    245339
    246340            sage: S = Spec(ZZ)
     
    249343        """
    250344        return self.__R.krull_dimension() - self.base_ring().krull_dimension()
    251345
     346    def base_extend(self, R):
     347        """
     348        Extend the base ring/scheme.
     349       
     350        INPUT:
     351
     352        - ``R`` -- an affine scheme or a commutative ring.
     353
     354        EXAMPLES::
     355       
     356            sage: Spec_ZZ = Spec(ZZ);  Spec_ZZ
     357            Spectrum of Integer Ring
     358            sage: Spec_ZZ.base_extend(QQ)
     359            Spectrum of Rational Field
     360        """
     361        if is_CommutativeRing(R):
     362            return Spec(self.coordinate_ring().base_extend(R), self.base_ring())
     363        if not self.base_scheme() == R.base_scheme():
     364            raise ValueError('The new base scheme must be a scheme over the old base scheme.')
     365        return Spec(self.coordinate_ring().base_extend(new_base.coordinate_ring()),
     366                    self.base_ring())
     367
     368    def _homset_class(self, *args, **kwds):
     369        """
     370        Return the Hom set class.
     371       
     372        EXAMPLES::
     373       
     374            sage: Spec(QQ)._homset_class(Spec(QQ), Spec(ZZ))
     375            Set of rational points of Spectrum of Rational Field
     376        """
     377        from sage.schemes.generic.homset import SchemeHomset_coordinates
     378        return SchemeHomset_coordinates(*args, **kwds)
     379
     380
    252381SpecZ = Spec(ZZ)
  • sage/schemes/generic/toric_variety.py

    diff --git a/sage/schemes/generic/toric_variety.py b/sage/schemes/generic/toric_variety.py
    a b  
    5858are all zero. ::
    5959
    6060    sage: parent(origin)
    61     Set of Rational Points of 2-d affine toric variety
     61    Set of rational points of 2-d affine toric variety
    6262
    6363As you can see, by default toric varieties live over the field of rational
    6464numbers::
     
    414414        sage: origin
    415415        [0 : 0]
    416416        sage: parent(origin)
    417         Set of Rational Points of 2-d affine toric variety
     417        Set of rational points of 2-d affine toric variety
    418418
    419419    Only affine toric varieties have points whose (homogeneous) coordinates
    420420    are all zero.
     
    637637
    638638            sage: fan = FaceFan(lattice_polytope.octahedron(2))
    639639            sage: P1xP1 = ToricVariety(fan)
    640             sage: P1xP1._homset_class(P1xP1, P1xP1.base_ring())
    641             Set of Rational Points of 2-d toric variety
     640            sage: P1xP1._homset_class(Spec(QQ), P1xP1)
     641            Set of rational points of 2-d toric variety
    642642            covered by 4 affine patches
    643643        """
    644644        return SchemeHomset_toric_coordinates_field(*args, **kwds)
  • sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py

    diff --git a/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py b/sage/schemes/hyperelliptic_curves/hyperelliptic_generic.py
    a b  
    286286        return S.gens()
    287287
    288288    def local_coordinates_at_nonweierstrass(self, P, prec = 20, name = 't'):
    289         """                                                                                                             
     289        """
    290290        For a non-Weierstrass point P = (a,b) on the hyperelliptic                         
    291291        curve y^2 = f(x), returns (x(t), y(t)) such that (y(t))^2 = f(x(t)),
    292292        where t = x - a is the local parameter.
     
    301301        (x(t),y(t)) such that y(t)^2 = f(x(t)) and t = x - a
    302302        is the local parameter at P
    303303
    304         EXAMPLES:                                                                                                       
     304        EXAMPLES::
     305
    305306            sage: R.<x> = QQ['x']                                                             
    306307            sage: H = HyperellipticCurve(x^5-23*x^3+18*x^2+40*x)                               
    307308            sage: P = H(1,6)                                                                   
     
    315316            sage: x                                                                           
    316317            -2 + t + O(t^5)                                                                   
    317318            sage: y                                                                           
    318             12 - 19/2*t - 19/32*t^2 + 61/256*t^3 - 5965/24576*t^4 + O(t^5)                                   
    319                                                                                                                              
    320         AUTHOR:                                                                                                         
    321             - Jennifer Balakrishnan (2007-12)                                                                           
     319            12 - 19/2*t - 19/32*t^2 + 61/256*t^3 - 5965/24576*t^4 + O(t^5)
     320
     321        AUTHOR:
     322
     323            - Jennifer Balakrishnan (2007-12)
    322324        """
    323325        d = P[1]
    324326        if d == 0:                                                                             
  • sage/schemes/hyperelliptic_curves/jacobian_generic.py

    diff --git a/sage/schemes/hyperelliptic_curves/jacobian_generic.py b/sage/schemes/hyperelliptic_curves/jacobian_generic.py
    a b  
    5050        sage: C.defining_polynomial()                       
    5151        -x0^5 + x0*x1*x2^3 + x1^2*x2^3 + x0*x2^4 - x2^5
    5252        sage: C(QQ)
    53         Set of Rational Points of Hyperelliptic Curve over Rational Field defined by v^2 + u*v = u^5 - u + 1
     53        Set of rational points of Hyperelliptic Curve over Rational Field defined by v^2 + u*v = u^5 - u + 1
    5454        sage: K.<t> = NumberField(x^2-2)                     
    5555        sage: C(K)
    56                Set of Rational Points of Closed subscheme of Projective Space of dimension 2 over Number Field in t with defining polynomial x^2 - 2 defined by: -x0^5 + x0*x1*x2^3 + x1^2*x2^3 + x0*x2^4 - x2^5
     56               Set of rational points of Closed subscheme of Projective Space of dimension 2 over Number Field in t with defining polynomial x^2 - 2 defined by: -x0^5 + x0*x1*x2^3 + x1^2*x2^3 + x0*x2^4 - x2^5
    5757        sage: P = C(QQ)(0,1,1); P                           
    5858        (0 : 1 : 1)
    5959        sage: P == C(0,1,1)                                 
    6060        True
    6161        sage: C(0,1,1).parent()                             
    62         Set of Rational Points of Hyperelliptic Curve over Rational Field defined by v^2 + u*v = u^5 - u + 1
     62        Set of rational points of Hyperelliptic Curve over Rational Field defined by v^2 + u*v = u^5 - u + 1
    6363        sage: P1 = C(K)(P)                                   
    6464        sage: P2 = C(K)([2,4*t-1,1])                         
    6565        sage: P3 = C(K)([-1/2,1/8*(7*t+2),1])               
  • sage/schemes/hyperelliptic_curves/jacobian_homset.py

    diff --git a/sage/schemes/hyperelliptic_curves/jacobian_homset.py b/sage/schemes/hyperelliptic_curves/jacobian_homset.py
    a b  
    88    sage: C = HyperellipticCurve(f); C
    99    Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x + 1
    1010    sage: C(QQ)
    11     Set of Rational Points of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x + 1
     11    Set of rational points of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x + 1
    1212    sage: P = C([0,1,1])
    1313    sage: J = C.jacobian(); J
    1414    Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x + 1
     
    4747#                  http://www.gnu.org/licenses/
    4848#*****************************************************************************
    4949
    50 import sage.schemes.generic.spec as spec
    51 from sage.rings.all import is_Polynomial, PolynomialRing, Integer, ZZ
    52 from sage.schemes.generic.homset import SchemeHomset_generic
     50from sage.rings.all import is_Polynomial, PolynomialRing, Integer, is_Integer, ZZ
     51from sage.schemes.generic.homset import SchemeHomset_coordinates
    5352from sage.schemes.generic.morphism import is_SchemeMorphism
    54 #from sage.schemes.jacobians.abstract_jacobian import Jacobian_generic
     53from sage.schemes.generic.spec import Spec, is_Spec
    5554from jacobian_morphism import JacobianMorphism_divisor_class_field
    56 from sage.rings.integer import Integer, is_Integer
    5755
    58 class JacobianHomset_divisor_classes(SchemeHomset_generic):
    59     def __init__(self, X, S):
     56class JacobianHomset_divisor_classes(SchemeHomset_coordinates):
     57    def __init__(self, Y, X, **kwds):
    6058        R = X.base_ring()
    61         SchemeHomset_generic.__init__(self, spec.Spec(S, R), X)
     59        S = Y.coordinate_ring()
     60        SchemeHomset_coordinates.__init__(self, Y, X, **kwds)
    6261        P2 = X.curve()._printing_ring
    6362        if S != R:
    6463            y = str(P2.gen())
     
    168167        Returns S for a homset X(T) where T = Spec(S).
    169168        """
    170169        T = self.domain()
    171         if spec.is_Spec(T):
     170        if is_Spec(T):
    172171            return T.coordinate_ring()
    173172        else:
    174173            raise TypeError, "Domain of argument must be of the form Spec(S)."
  • sage/schemes/hyperelliptic_curves/jacobian_morphism.py

    diff --git a/sage/schemes/hyperelliptic_curves/jacobian_morphism.py b/sage/schemes/hyperelliptic_curves/jacobian_morphism.py
    a b  
    3838
    3939    sage: x = GF(37)['x'].gen()
    4040    sage: H = HyperellipticCurve(x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x); H
    41     Hyperelliptic Curve over Finite Field of size 37 defined by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
     41    Hyperelliptic Curve over Finite Field of size 37 defined
     42    by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
    4243
    4344At this time, Jacobians of hyperelliptic curves are handled
    4445differently than elliptic curves::
    4546
    4647    sage: J = H.jacobian(); J
    47     Jacobian of Hyperelliptic Curve over Finite Field of size 37 defined by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
     48    Jacobian of Hyperelliptic Curve over Finite Field of size 37 defined
     49    by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
    4850    sage: J = J(J.base_ring()); J
    49     Set of points of Jacobian of Hyperelliptic Curve over Finite Field of size 37 defined by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x defined over Finite Field of size 37
     51    Set of rational points of Jacobian of Hyperelliptic Curve over Finite Field
     52    of size 37 defined by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
    5053
    5154Points on the Jacobian are represented by Mumford's polynomials.
    5255First we find a couple of points on the curve::
     
    130133        sage: H = HyperellipticCurve(f); H
    131134        Hyperelliptic Curve over Rational Field defined by y^2 = x^5 - x
    132135        sage: J = H.jacobian()(QQ); J
    133         Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 - x defined over Rational Field
     136        Set of rational points of Jacobian of Hyperelliptic Curve over Rational Field
     137        defined by y^2 = x^5 - x
    134138   
    135139    The following point is 2-torsion::
    136140   
     
    167171        sage: H = HyperellipticCurve(f, x); H
    168172        Hyperelliptic Curve over Rational Field defined by y^2 + x*y = x^5 - x
    169173        sage: J = H.jacobian()(QQ); J
    170         Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 + x*y = x^5 - x defined over Rational Field
     174        Set of rational points of Jacobian of Hyperelliptic Curve over
     175        Rational Field defined by y^2 + x*y = x^5 - x
    171176   
    172177    The following point is 2-torsion::
    173178   
     
    224229   
    225230        sage: F.<a> = NumberField(x^2 - 2, 'a')
    226231        sage: J = H.jacobian()(F); J
    227         Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x defined over Number Field in a with defining polynomial x^2 - 2
     232        Set of rational points of Jacobian of Hyperelliptic Curve over
     233        Number Field in a with defining polynomial x^2 - 2 defined
     234        by y^2 = x^5 + x
    228235   
    229236    ::
    230237   
     
    268275        sage: H = HyperellipticCurve(f, 2*x); H
    269276        Hyperelliptic Curve over Finite Field in a of size 7^2 defined by y^2 + 2*x*y = x^7 + x^2 + a
    270277        sage: J = H.jacobian()(F); J
    271         Set of points of Jacobian of Hyperelliptic Curve over Finite Field in a of size 7^2 defined by y^2 + 2*x*y = x^7 + x^2 + a defined over Finite Field in a of size 7^2
     278        Set of rational points of Jacobian of Hyperelliptic Curve over
     279        Finite Field in a of size 7^2 defined by y^2 + 2*x*y = x^7 + x^2 + a
    272280   
    273281    ::
    274282   
     
    295303        Hyperelliptic Curve over Finite Field of size 1000000000000000000000000000057 defined by y^2 + 2*x*y = x^7 + x^2 + 1
    296304        sage: J = H.jacobian()(F); J
    297305        verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation.
    298         Set of points of Jacobian of Hyperelliptic Curve over Finite Field of size 1000000000000000000000000000057 defined by y^2 + 2*x*y = x^7 + x^2 + 1 defined over Finite Field of size 1000000000000000000000000000057
     306        Set of rational points of Jacobian of Hyperelliptic Curve over
     307        Finite Field of size 1000000000000000000000000000057 defined
     308        by y^2 + 2*x*y = x^7 + x^2 + 1
    299309        sage: Q = J(H.lift_x(F(1))); Q
    300310        (x + 1000000000000000000000000000056, y + 1000000000000000000000000000056)
    301311        sage: 10*Q # indirect doctest
     
    349359       
    350360            sage: x = GF(37)['x'].gen()
    351361            sage: H = HyperellipticCurve(x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x)
    352             sage: J = H.jacobian()(GF(37))
     362            sage: J = H.jacobian()(GF(37));  J
     363            Set of rational points of Jacobian of Hyperelliptic Curve over
     364            Finite Field of size 37 defined by
     365            y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
    353366       
    354367        ::
    355368       
    356369            sage: P1 = J(H.lift_x(2)); P1 # indirect doctest
    357370            (x + 35, y + 26)
    358371            sage: P1.parent()
    359             Set of points of Jacobian of Hyperelliptic Curve over Finite Field of size 37 defined by y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x defined over Finite Field of size 37           
     372            Set of rational points of Jacobian of Hyperelliptic Curve over
     373            Finite Field of size 37 defined by
     374            y^2 = x^5 + 12*x^4 + 13*x^3 + 15*x^2 + 33*x
    360375            sage: type(P1)
    361376            <class 'sage.schemes.hyperelliptic_curves.jacobian_morphism.JacobianMorphism_divisor_class_field'>
    362377        """
     
    472487            sage: H = HyperellipticCurve(f)
    473488            sage: F.<a> = NumberField(x^2 - 2, 'a')
    474489            sage: J = H.jacobian()(F); J
    475             Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x defined over Number Field in a with defining polynomial x^2 - 2
     490            Set of rational points of Jacobian of Hyperelliptic Curve over
     491            Number Field in a with defining polynomial x^2 - 2 defined
     492            by y^2 = x^5 + x
    476493       
    477494        ::
    478495       
     
    495512            sage: H = HyperellipticCurve(f)
    496513            sage: F.<a> = NumberField(x^2 - 2, 'a')
    497514            sage: J = H.jacobian()(F); J
    498             Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x defined over Number Field in a with defining polynomial x^2 - 2
     515            Set of rational points of Jacobian of Hyperelliptic Curve over
     516            Number Field in a with defining polynomial x^2 - 2 defined
     517            by y^2 = x^5 + x
    499518       
    500519        ::
    501520       
     
    517536            sage: H = HyperellipticCurve(f)
    518537            sage: F.<a> = NumberField(x^2 - 2, 'a')
    519538            sage: J = H.jacobian()(F); J
    520             Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x defined over Number Field in a with defining polynomial x^2 - 2
     539            Set of rational points of Jacobian of Hyperelliptic Curve over
     540            Number Field in a with defining polynomial x^2 - 2 defined
     541            by y^2 = x^5 + x
    521542       
    522543        ::
    523544       
     
    539560            sage: H = HyperellipticCurve(f)
    540561            sage: F.<a> = NumberField(x^2 - 2, 'a')
    541562            sage: J = H.jacobian()(F); J
    542             Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 + x defined over Number Field in a with defining polynomial x^2 - 2
     563            Set of rational points of Jacobian of Hyperelliptic Curve over
     564            Number Field in a with defining polynomial x^2 - 2 defined
     565            by y^2 = x^5 + x
    543566       
    544567        ::
    545568       
     
    566589            sage: H = HyperellipticCurve(f); H
    567590            Hyperelliptic Curve over Rational Field defined by y^2 = x^5 - x
    568591            sage: J = H.jacobian()(QQ); J
    569             Set of points of Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^5 - x defined over Rational Field
     592            Set of rational points of Jacobian of Hyperelliptic Curve over
     593            Rational Field defined by y^2 = x^5 - x
    570594       
    571595        The following point is 2-torsion::
    572596       
  • sage/schemes/jacobians/abstract_jacobian.py

    diff --git a/sage/schemes/jacobians/abstract_jacobian.py b/sage/schemes/jacobians/abstract_jacobian.py
    a b  
    160160            Projective Curve over Rational Field defined by x^3 + y^3 + z^3
    161161        """
    162162        return self.__curve
     163
     164    def change_ring(self, R):
     165        r"""
     166        Return the Jacobian over the ring `R`.
     167
     168        INPUT:
     169       
     170        - ``R`` -- a field. The new base ring.
     171
     172        OUTPUT:
     173       
     174        The Jacobian over the ring `R`.
     175
     176        EXAMPLES::
     177
     178            sage: R.<x> = QQ['x']
     179            sage: H = HyperellipticCurve(x^3-10*x+9)
     180            sage: Jac = H.jacobian();   Jac
     181            Jacobian of Hyperelliptic Curve over Rational
     182            Field defined by y^2 = x^3 - 10*x + 9
     183            sage: Jac.change_ring(RDF)
     184            Jacobian of Hyperelliptic Curve over Real Double
     185            Field defined by y^2 = x^3 - 10.0*x + 9.0
     186        """
     187        return self.curve().change_ring(R).jacobian()
     188
     189    def base_extend(self, R):
     190        r"""
     191        Return the natural extension of ``self`` over `R`
     192
     193        INPUT:
     194       
     195        - ``R`` -- a field. The new base field.
     196
     197        OUTPUT:
     198       
     199        The Jacobian over the ring `R`.
     200
     201        EXAMPLES::
     202
     203            sage: R.<x> = QQ['x']
     204            sage: H = HyperellipticCurve(x^3-10*x+9)
     205            sage: Jac = H.jacobian();   Jac
     206            Jacobian of Hyperelliptic Curve over Rational Field defined by y^2 = x^3 - 10*x + 9
     207            sage: F.<a> = QQ.extension(x^2+1)
     208            sage: Jac.base_extend(F)
     209            Jacobian of Hyperelliptic Curve over Number Field in a with defining
     210            polynomial x^2 + 1 defined by y^2 = x^3 - 10*x + 9
     211        """
     212        if not is_Field(R):
     213            raise ValueError('Not a field: '+str(R))
     214        if self.base_ring() is R:
     215            return self
     216        if not R.has_coerce_map_from(self.base_ring()):
     217            raise ValueError('no natural map from the base ring (=%s) to R (=%s)!'
     218                             % (self.base_ring(), R))
     219        return self.change_ring(R)
  • sage/schemes/plane_curves/curve.py

    diff --git a/sage/schemes/plane_curves/curve.py b/sage/schemes/plane_curves/curve.py
    a b  
    99from sage.schemes.generic.divisor import Divisor_curve
    1010
    1111class Curve_generic(AlgebraicScheme_subscheme):
     12    r"""
     13    EXAMPLES::
     14
     15        sage: A.<x,y,z> = AffineSpace(QQ,3)
     16        sage: C = Curve([x-y,z-2])
     17        sage: loads(C.dumps()) == C
     18        True
     19    """
     20
    1221    def _repr_(self):
    1322        """
    14         EXAMPLES:
    15        sage: A.<x,y,z> = AffineSpace(QQ,3)
     23        EXAMPLES::
     24
     25            sage: A.<x,y,z> = AffineSpace(QQ,3)
    1626            sage: C = Curve([x-y,z-2])
    1727            sage: C
    1828            Affine Space Curve over Rational Field defined by x - y, z - 2
  • sage/schemes/readme.py

    diff --git a/sage/schemes/readme.py b/sage/schemes/readme.py
    a b  
    117117  ::
    118118
    119119        sage: PP(QQ)
    120         Set of Rational Points of Projective Space
     120        Set of rational points of Projective Space
    121121        of dimension 2 over Rational Field
    122122        sage: PP(QQ)([-2,3,5])
    123123        (-2/5 : 3/5 : 1)
     
    131131        sage: S.<t> = R.quo(x^2+5)
    132132        sage: P.<X,Y,Z> = ProjectiveSpace(2, S)
    133133        sage: P(S)
    134         Set of Rational Points of Projective Space of dimension 2 over
     134        Set of rational points of Projective Space of dimension 2 over
    135135        Univariate Quotient Polynomial Ring in t over Integer Ring with
    136136        modulus x^2 + 5
    137137
  • sage/structure/factory.pyx

    diff --git a/sage/structure/factory.pyx b/sage/structure/factory.pyx
    a b  
     1r"""
     2Factory for unique objects
     3
     4More general than :mod:`~sage.structure.unique_representation`, the
     5:class:`UniqueFactory` class can specify a subset of the arguments
     6that serve as the unique key. Typically, this is used to construct
     7objects that accept an optional ``check=[True|False]`` argument, but
     8whose result should be unique irregardless of said optional argument.
     9"""
     10
     11#*****************************************************************************
     12#  Copyright (C) 2008 Robert Bradshaw <robertwb@math.washington.edu>
     13#
     14#  Distributed under the terms of the GNU General Public License (GPL)
     15#
     16#    This code is distributed in the hope that it will be useful,
     17#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     18#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     19#    General Public License for more details.
     20#
     21#  The full text of the GPL is available at:
     22#
     23#                  http://www.gnu.org/licenses/
     24#******************************************************************************
     25
    126import weakref, types, copy_reg
    227
    328from sage_object cimport SageObject
     
    2853    will return the same object for the same version of Sage, and distinct
    2954    (but hopefully equal) objects for different versions of Sage.
    3055   
    31     Typically one only needs to implement create_key and create_object.
     56    Typically one only needs to implement :meth:`create_key` and
     57    :meth:`create_object`.
    3258    """
    3359   
    3460    cdef readonly _name
     
    3763    def __init__(self, name):
    3864        """
    3965        INPUT:
    40             name -- a name in the global namespace referring to self
    41                     or a fully qualified path name to self, which is
    42                     used to locate the factory on unpickling.
     66
     67        - ``name`` -- string. A name in the global namespace referring
     68          to self or a fully qualified path name to self, which is
     69          used to locate the factory on unpickling.
    4370                   
    44         EXAMPLES:
     71        EXAMPLES::
     72
    4573            sage: from sage.structure.factory import UniqueFactory
    4674            sage: fake_factory = UniqueFactory('ZZ')
    4775            sage: loads(dumps(fake_factory))
     
    5583       
    5684    def __reduce__(self):
    5785        """
    58         EXAMPLES:
     86        EXAMPLES::
     87
    5988            sage: A = FiniteField(127)
    6089            sage: A is loads(dumps(A)) # indirect doctest
    6190            True
     
    6998            sage: D is loads(dumps(D))
    7099            True
    71100           
    72         TESTS:
     101        TESTS::
     102
    73103            sage: loads(dumps(FiniteField)) is FiniteField
    74104            True
    75             sage: from sage.structure.factory import test_factory
     105            sage: from sage.structure.test_factory import test_factory
    76106            sage: loads(dumps(test_factory)) is test_factory
    77107            True
    78108        """
     
    88118        Do not override this method, override create_key and create_object and
    89119        put the docstring in the body of the class.
    90120       
    91         EXAMPLES:
    92             sage: from sage.structure.factory import test_factory
     121        EXAMPLES::
     122
     123            sage: from sage.structure.test_factory import test_factory
    93124            sage: _ = test_factory(1,2,3); _
    94125            Making object (1, 2, 3)
    95             <sage.structure.factory.A instance at ...>
     126            <sage.structure.test_factory.A instance at ...>
    96127           
    97         It already created one, so don't re-create.
     128        It already created one, so don't re-create::
     129
    98130            sage: test_factory(1,2,3)
    99             <sage.structure.factory.A instance at ...>
     131            <sage.structure.test_factory.A instance at ...>
    100132            sage: test_factory(1,2,3) is test_factory(1,2,3)
    101133            True
    102134           
    103         Of course, with a different key, a new object will be created.
     135        Of course, with a different key, a new object will be created::
     136
    104137            sage: test_factory(1,2,3) is test_factory(1,2,4)
    105138            Making object (1, 2, 4)
    106139            False
     
    115148        if necessary (for example, it isn't in the cache or it is unpickling
    116149        from an older version of Sage).
    117150       
    118         EXAMPLES:
    119             sage: from sage.structure.factory import test_factory
     151        EXAMPLES::
     152
     153            sage: from sage.structure.test_factory import test_factory
    120154            sage: a = test_factory.get_object(3.0, 'a', {}); a
    121155            Making object a
    122             <sage.structure.factory.A instance at ...>
     156            <sage.structure.test_factory.A instance at ...>
    123157            sage: test_factory.get_object(3.0, 'a', {}) is test_factory.get_object(3.0, 'a', {})
    124158            True
    125159            sage: test_factory.get_object(3.0, 'a', {}) is test_factory.get_object(3.1, 'a', {})
     
    171205        Defaults to the Sage version that is passed in, but courser
    172206        granularity can be provided.
    173207       
    174         EXAMPLES:
    175             sage: from sage.structure.factory import test_factory
     208        EXAMPLES::
     209
     210            sage: from sage.structure.test_factory import test_factory
    176211            sage: test_factory.get_version((3,1,0))
    177212            (3, 1, 0)
    178213        """
     
    183218        Return a tuple containing the key (uniquely defining data)
    184219        and any extra arguments (empty by default).
    185220       
    186         Defaults to \code{self.create_key}.
     221        Defaults to :meth:`create_key`.
    187222       
    188         EXAMPLES:
    189             sage: from sage.structure.factory import test_factory
     223        EXAMPLES::
     224
     225            sage: from sage.structure.test_factory import test_factory
    190226            sage: test_factory.create_key_and_extra_args(1, 2, key=5)
    191227            ((1, 2), {})
    192228            sage: GF.create_key_and_extra_args(3, foo='value')
     
    199235        Given the arguments and keywords, create a key that uniquely
    200236        determines this object.
    201237       
    202         EXAMPLES:
    203             sage: from sage.structure.factory import test_factory
     238        EXAMPLES::
     239
     240            sage: from sage.structure.test_factory import test_factory
    204241            sage: test_factory.create_key(1, 2, key=5)
    205242            (1, 2)
    206243        """
     
    211248        Create the object from the key and extra arguments. This is only
    212249        called if the object was not found in the cache.
    213250       
    214         EXAMPLES:
    215             sage: from sage.structure.factory import test_factory
     251        EXAMPLES::
     252
     253            sage: from sage.structure.test_factory import test_factory
    216254            sage: test_factory.create_object(0, (1,2,3))
    217255            Making object (1, 2, 3)
    218             <sage.structure.factory.A instance at ...>
     256            <sage.structure.test_factory.A instance at ...>
    219257            sage: test_factory('a')
    220258            Making object ('a',)
    221             <sage.structure.factory.A instance at ...>
     259            <sage.structure.test_factory.A instance at ...>
    222260            sage: test_factory('a') # NOT called again
    223             <sage.structure.factory.A instance at ...>
     261            <sage.structure.test_factory.A instance at ...>
    224262        """
    225263        raise NotImplementedError
    226264       
     
    230268        may result in a new (more specific) key. This allows the more specific
    231269        key to be cached as well, and used for pickling.
    232270
    233         EXAMPLES:
     271        EXAMPLES::
     272
    234273            sage: key, _ = GF.create_key_and_extra_args(27, 'k'); key
    235274            (27, ('k',), 'conway', None, '{}', 3, 3, True)
    236275            sage: K = GF.create_object(0, key); K
     
    247286       
    248287    cpdef reduce_data(self, obj):
    249288        """
    250         The results of this function can be returned from __reduce__. This is
    251         here so the factory internals can change without having to re-write
    252         __reduce__ methods that use it.
     289        The results of this function can be returned from
     290        :meth:`__reduce__`. This is here so the factory internals can
     291        change without having to re-write :meth:`__reduce__` methods
     292        that use it.
    253293       
    254         EXAMPLE:               
     294        EXAMPLE::
     295
    255296            sage: V = FreeModule(ZZ, 5)
    256297            sage: factory, data = FreeModule.reduce_data(V)
    257298            sage: factory(*data)
     
    259300            sage: factory(*data) is V
    260301            True
    261302
    262             sage: from sage.structure.factory import test_factory
     303            sage: from sage.structure.test_factory import test_factory
    263304            sage: a = test_factory(1, 2)
    264305            Making object (1, 2)
    265306            sage: test_factory.reduce_data(a)
    266307            (<built-in function generic_factory_unpickle>,
    267              (<class 'sage.structure.factory.UniqueFactoryTester'>,
     308             (<class 'sage.structure.test_factory.UniqueFactoryTester'>,
    268309              (...),
    269310              (1, 2),
    270311              {}))
    271312       
    272         NOTE: The (...) here is the Sage version.
     313        Note that the ellipsis ``(...)`` here stands for the Sage
     314        version.
    273315        """
    274316        return generic_factory_unpickle, obj._factory_data
    275317
     
    278320    """
    279321    Method used for unpickling the object.
    280322   
    281     The unpickling mechanism needs a plain Python function to call. 
    282     It takes a factory as the first argument, passes the rest of the 
    283     arguments onto the factory's get_object method.
     323    The unpickling mechanism needs a plain Python function to call.
     324    It takes a factory as the first argument, passes the rest of the
     325    arguments onto the factory's :meth:`UniqueFactory.get_object` method.
    284326   
    285     EXAMPLES:
     327    EXAMPLES::
     328
    286329        sage: V = FreeModule(ZZ, 5)
    287330        sage: func, data = FreeModule.reduce_data(V)
    288331        sage: func is sage.structure.factory.generic_factory_unpickle
     
    294337
    295338def generic_factory_reduce(self, proto):
    296339    """
    297     Used to provide a __reduce__ method if one does not already exist.
     340    Used to provide a ``__reduce__`` method if one does not already exist.
    298341   
    299     EXAMPLES:
     342    EXAMPLES::
     343
    300344        sage: V = QQ^6
    301345        sage: sage.structure.factory.generic_factory_reduce(V, 1) == V.__reduce_ex__(1)
    302346        True
     
    310354    """
    311355    Used in unpickling the factory itself.
    312356   
    313     EXAMPLES:
     357    EXAMPLES::
     358
    314359        sage: from sage.structure.factory import lookup_global
    315360        sage: lookup_global('ZZ')
    316361        Integer Ring
     
    325370    return getattr(all, name)
    326371
    327372
    328 class A:
    329     # something we can weakref
    330     pass
    331 
    332 class UniqueFactoryTester(UniqueFactory):
    333 
    334     def create_key(self, *args, **kwds):
    335         """
    336         EXAMPLES:
    337             sage: from sage.structure.factory import UniqueFactoryTester
    338             sage: test_factory = UniqueFactoryTester('foo')
    339             sage: test_factory.create_key(1, 2, 3)
    340             (1, 2, 3)
    341         """
    342         return args
    343    
    344     def create_object(self, version, key, **extra_args):
    345         """
    346         EXAMPLES:
    347             sage: from sage.structure.factory import UniqueFactoryTester
    348             sage: test_factory = UniqueFactoryTester('foo')
    349             sage: test_factory.create_object('version', key=(1, 2, 4))
    350             Making object (1, 2, 4)
    351             <sage.structure.factory.A instance at ...>
    352         """
    353         print "Making object", key
    354         return A()
    355 
    356 test_factory = UniqueFactoryTester('sage.structure.factory.test_factory')
     373# To make the pickle jar happy:
     374from sage.structure.test_factory import test_factory
  • new file sage/structure/test_factory.py

    diff --git a/sage/structure/test_factory.py b/sage/structure/test_factory.py
    new file mode 100644
    - +  
     1"""
     2Test of the :mod:`~sage.structure.factory` module.
     3"""
     4
     5#*****************************************************************************
     6#  Copyright (C) 2008 Robert Bradshaw <robertwb@math.washington.edu>
     7#
     8#  Distributed under the terms of the GNU General Public License (GPL)
     9#
     10#    This code is distributed in the hope that it will be useful,
     11#    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13#    General Public License for more details.
     14#
     15#  The full text of the GPL is available at:
     16#
     17#                  http://www.gnu.org/licenses/
     18#******************************************************************************
     19
     20from sage.structure.factory import UniqueFactory
     21
     22
     23class A:
     24    # something we can weakref
     25    pass
     26
     27class UniqueFactoryTester(UniqueFactory):
     28
     29    def create_key(self, *args, **kwds):
     30        """
     31        EXAMPLES::
     32
     33            sage: from sage.structure.test_factory import UniqueFactoryTester
     34            sage: test_factory = UniqueFactoryTester('foo')
     35            sage: test_factory.create_key(1, 2, 3)
     36            (1, 2, 3)
     37        """
     38        return args
     39   
     40    def create_object(self, version, key, **extra_args):
     41        """
     42        EXAMPLES::
     43 
     44            sage: from sage.structure.test_factory import UniqueFactoryTester
     45            sage: test_factory = UniqueFactoryTester('foo')
     46            sage: test_factory.create_object('version', key=(1, 2, 4))
     47            Making object (1, 2, 4)
     48            <sage.structure.test_factory.A instance at ...>
     49        """
     50        print "Making object", key
     51        return A()
     52
     53test_factory = UniqueFactoryTester('sage.structure.test_factory.test_factory')