Path: blob/master/src/sage/schemes/affine/affine_homset.py
8820 views
r"""1Set of homomorphisms between two affine schemes23For schemes `X` and `Y`, this module implements the set of morphisms4`Hom(X,Y)`. This is done by :class:`SchemeHomset_generic`.56As a special case, the Hom-sets can also represent the points of a7scheme. Recall that the `K`-rational points of a scheme `X` over `k`8can be identified with the set of morphisms `Spec(K) \to X`. In Sage9the rational points are implemented by such scheme morphisms. This is10done by :class:`SchemeHomset_points` and its subclasses.1112.. note::1314You should not create the Hom-sets manually. Instead, use the15:meth:`~sage.structure.parent.Hom` method that is inherited by all16schemes.1718AUTHORS:1920- William Stein (2006): initial version.21"""222324#*****************************************************************************25# Copyright (C) 2006 William Stein <[email protected]>26#27# Distributed under the terms of the GNU General Public License (GPL)28# as published by the Free Software Foundation; either version 2 of29# the License, or (at your option) any later version.30# http://www.gnu.org/licenses/31#*****************************************************************************323334from sage.rings.all import ZZ35from sage.rings.rational_field import is_RationalField36from sage.rings.finite_rings.constructor import is_FiniteField3738import sage.schemes.generic.homset3940#*******************************************************************41# Affine varieties42#*******************************************************************43class SchemeHomset_points_spec(sage.schemes.generic.homset.SchemeHomset_generic):44"""45Set of rational points of an affine variety.4647INPUT:4849See :class:`SchemeHomset_generic`.5051EXAMPLES::5253sage: from sage.schemes.affine.affine_homset import SchemeHomset_points_spec54sage: SchemeHomset_points_spec(Spec(QQ), Spec(QQ))55Set of rational points of Spectrum of Rational Field56"""5758def _element_constructor_(self, *args, **kwds):59"""60The element contstructor.6162EXAMPLES::6364sage: X = Spec(QQ)65sage: ring_hom = QQ.hom((1,), QQ); ring_hom66Ring endomorphism of Rational Field67Defn: 1 |--> 168sage: H = X.Hom(X)69sage: H(ring_hom)70Affine Scheme endomorphism of Spectrum of Rational Field71Defn: Ring endomorphism of Rational Field72Defn: 1 |--> 17374TESTS::7576sage: H._element_constructor_(ring_hom)77Affine Scheme endomorphism of Spectrum of Rational Field78Defn: Ring endomorphism of Rational Field79Defn: 1 |--> 180"""81return sage.schemes.generic.homset.SchemeHomset_generic._element_constructor_(self, *args, **kwds)8283def _repr_(self):84"""85Return a string representation of ``self``.8687OUTPUT:8889A string.9091EXAMPLES::9293sage: from sage.schemes.affine.affine_homset import SchemeHomset_points_spec94sage: S = SchemeHomset_points_spec(Spec(QQ), Spec(QQ))95sage: S._repr_()96'Set of rational points of Spectrum of Rational Field'97"""98return 'Set of rational points of '+str(self.codomain())99100101102#*******************************************************************103# Affine varieties104#*******************************************************************105class SchemeHomset_points_affine(sage.schemes.generic.homset.SchemeHomset_points):106"""107Set of rational points of an affine variety.108109INPUT:110111See :class:`SchemeHomset_generic`.112113EXAMPLES::114115sage: from sage.schemes.affine.affine_homset import SchemeHomset_points_affine116sage: SchemeHomset_points_affine(Spec(QQ), AffineSpace(ZZ,2))117Set of rational points of Affine Space of dimension 2 over Rational Field118"""119120def points(self, B=0):121r"""122Return some or all rational points of an affine scheme.123124INPUT:125126- ``B`` -- integer (optional, default: 0). The bound for the127height of the coordinates.128129OUTPUT:130131- If the base ring is a finite field: all points of the scheme,132given by coordinate tuples.133134- If the base ring is `\QQ` or `\ZZ`: the subset of points whose135coordinates have height ``B`` or less.136137EXAMPLES: The bug reported at #11526 is fixed::138139sage: A2 = AffineSpace(ZZ,2)140sage: F = GF(3)141sage: A2(F).points()142[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]143144sage: R = ZZ145sage: A.<x,y> = R[]146sage: I = A.ideal(x^2-y^2-1)147sage: V = AffineSpace(R,2)148sage: X = V.subscheme(I)149sage: M = X(R)150sage: M.points(1)151[(-1, 0), (1, 0)]152"""153R = self.value_ring()154if is_RationalField(R) or R == ZZ:155if not B > 0:156raise TypeError, "A positive bound B (= %s) must be specified."%B157from sage.schemes.affine.affine_rational_point import enum_affine_rational_field158return enum_affine_rational_field(self,B)159elif is_FiniteField(R):160from sage.schemes.affine.affine_rational_point import enum_affine_finite_field161return enum_affine_finite_field(self)162else:163raise TypeError, "Unable to enumerate points over %s."%R164165166