Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/schemes/affine/affine_homset.py
8820 views
1
r"""
2
Set of homomorphisms between two affine schemes
3
4
For schemes `X` and `Y`, this module implements the set of morphisms
5
`Hom(X,Y)`. This is done by :class:`SchemeHomset_generic`.
6
7
As a special case, the Hom-sets can also represent the points of a
8
scheme. Recall that the `K`-rational points of a scheme `X` over `k`
9
can be identified with the set of morphisms `Spec(K) \to X`. In Sage
10
the rational points are implemented by such scheme morphisms. This is
11
done by :class:`SchemeHomset_points` and its subclasses.
12
13
.. note::
14
15
You should not create the Hom-sets manually. Instead, use the
16
:meth:`~sage.structure.parent.Hom` method that is inherited by all
17
schemes.
18
19
AUTHORS:
20
21
- William Stein (2006): initial version.
22
"""
23
24
25
#*****************************************************************************
26
# Copyright (C) 2006 William Stein <[email protected]>
27
#
28
# Distributed under the terms of the GNU General Public License (GPL)
29
# as published by the Free Software Foundation; either version 2 of
30
# the License, or (at your option) any later version.
31
# http://www.gnu.org/licenses/
32
#*****************************************************************************
33
34
35
from sage.rings.all import ZZ
36
from sage.rings.rational_field import is_RationalField
37
from sage.rings.finite_rings.constructor import is_FiniteField
38
39
import sage.schemes.generic.homset
40
41
#*******************************************************************
42
# Affine varieties
43
#*******************************************************************
44
class SchemeHomset_points_spec(sage.schemes.generic.homset.SchemeHomset_generic):
45
"""
46
Set of rational points of an affine variety.
47
48
INPUT:
49
50
See :class:`SchemeHomset_generic`.
51
52
EXAMPLES::
53
54
sage: from sage.schemes.affine.affine_homset import SchemeHomset_points_spec
55
sage: SchemeHomset_points_spec(Spec(QQ), Spec(QQ))
56
Set of rational points of Spectrum of Rational Field
57
"""
58
59
def _element_constructor_(self, *args, **kwds):
60
"""
61
The element contstructor.
62
63
EXAMPLES::
64
65
sage: X = Spec(QQ)
66
sage: ring_hom = QQ.hom((1,), QQ); ring_hom
67
Ring endomorphism of Rational Field
68
Defn: 1 |--> 1
69
sage: H = X.Hom(X)
70
sage: H(ring_hom)
71
Affine Scheme endomorphism of Spectrum of Rational Field
72
Defn: Ring endomorphism of Rational Field
73
Defn: 1 |--> 1
74
75
TESTS::
76
77
sage: H._element_constructor_(ring_hom)
78
Affine Scheme endomorphism of Spectrum of Rational Field
79
Defn: Ring endomorphism of Rational Field
80
Defn: 1 |--> 1
81
"""
82
return sage.schemes.generic.homset.SchemeHomset_generic._element_constructor_(self, *args, **kwds)
83
84
def _repr_(self):
85
"""
86
Return a string representation of ``self``.
87
88
OUTPUT:
89
90
A string.
91
92
EXAMPLES::
93
94
sage: from sage.schemes.affine.affine_homset import SchemeHomset_points_spec
95
sage: S = SchemeHomset_points_spec(Spec(QQ), Spec(QQ))
96
sage: S._repr_()
97
'Set of rational points of Spectrum of Rational Field'
98
"""
99
return 'Set of rational points of '+str(self.codomain())
100
101
102
103
#*******************************************************************
104
# Affine varieties
105
#*******************************************************************
106
class SchemeHomset_points_affine(sage.schemes.generic.homset.SchemeHomset_points):
107
"""
108
Set of rational points of an affine variety.
109
110
INPUT:
111
112
See :class:`SchemeHomset_generic`.
113
114
EXAMPLES::
115
116
sage: from sage.schemes.affine.affine_homset import SchemeHomset_points_affine
117
sage: SchemeHomset_points_affine(Spec(QQ), AffineSpace(ZZ,2))
118
Set of rational points of Affine Space of dimension 2 over Rational Field
119
"""
120
121
def points(self, B=0):
122
r"""
123
Return some or all rational points of an affine scheme.
124
125
INPUT:
126
127
- ``B`` -- integer (optional, default: 0). The bound for the
128
height of the coordinates.
129
130
OUTPUT:
131
132
- If the base ring is a finite field: all points of the scheme,
133
given by coordinate tuples.
134
135
- If the base ring is `\QQ` or `\ZZ`: the subset of points whose
136
coordinates have height ``B`` or less.
137
138
EXAMPLES: The bug reported at #11526 is fixed::
139
140
sage: A2 = AffineSpace(ZZ,2)
141
sage: F = GF(3)
142
sage: A2(F).points()
143
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]
144
145
sage: R = ZZ
146
sage: A.<x,y> = R[]
147
sage: I = A.ideal(x^2-y^2-1)
148
sage: V = AffineSpace(R,2)
149
sage: X = V.subscheme(I)
150
sage: M = X(R)
151
sage: M.points(1)
152
[(-1, 0), (1, 0)]
153
"""
154
R = self.value_ring()
155
if is_RationalField(R) or R == ZZ:
156
if not B > 0:
157
raise TypeError, "A positive bound B (= %s) must be specified."%B
158
from sage.schemes.affine.affine_rational_point import enum_affine_rational_field
159
return enum_affine_rational_field(self,B)
160
elif is_FiniteField(R):
161
from sage.schemes.affine.affine_rational_point import enum_affine_finite_field
162
return enum_affine_finite_field(self)
163
else:
164
raise TypeError, "Unable to enumerate points over %s."%R
165
166