Skip to content

Commit a05fbaa

Browse files
committed
proj_bdd_height.py: ZZ/QQ_points_of_bounded_height now requires ProjectiveSpace as argument; IQ and general points_of_bounded_height do not need normalizing
1 parent 1ed8870 commit a05fbaa

File tree

1 file changed

+31
-44
lines changed

1 file changed

+31
-44
lines changed

src/sage/schemes/projective/proj_bdd_height.py

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
from sage.geometry.polyhedron.constructor import Polyhedron
3636

3737

38-
def ZZ_points_of_bounded_height(dim, bound):
38+
def ZZ_points_of_bounded_height(PS, dim, bound):
3939
r"""
4040
Return an iterator of the points in ``self`` of absolute multiplicative
4141
height of at most ``bound`` in the rational field.
4242
4343
INPUT:
4444
45+
- ``PS`` -- a projective space
46+
4547
- ``dim`` -- a positive integer
4648
4749
- ``bound`` -- a positive integer
@@ -53,14 +55,16 @@ def ZZ_points_of_bounded_height(dim, bound):
5355
EXAMPLES:
5456
5557
sage: from sage.schemes.projective.proj_bdd_height import ZZ_points_of_bounded_height
56-
sage: sorted(list(ZZ_points_of_bounded_height(1, 1)))
58+
sage: PS = ProjectiveSpace(ZZ, 1)
59+
sage: sorted(list(ZZ_points_of_bounded_height(PS, 1, 1)))
5760
[(-1 : -1), (-1 : 0), (-1 : 1), (0 : -1)]
58-
sage: len(list(ZZ_points_of_bounded_height(1, 5)))
61+
sage: len(list(ZZ_points_of_bounded_height(PS, 1, 5)))
5962
40
60-
sage: sorted(list(ZZ_points_of_bounded_height(1, 2)))
63+
sage: sorted(list(ZZ_points_of_bounded_height(PS, 1, 2)))
6164
[(-2 : -1), (-2 : 1), (-1 : -2), (-1 : -1),
6265
(-1 : 0), (-1 : 1), (-1 : 2), (0 : -1)]
63-
sage: sorted(list(ZZ_points_of_bounded_height(2, 1)))
66+
sage: PS = ProjectiveSpace(ZZ, 2)
67+
sage: sorted(list(ZZ_points_of_bounded_height(PS, 2, 1)))
6468
[(-1 : -1 : -1), (-1 : -1 : 0), (-1 : -1 : 1), (-1 : 0 : -1),
6569
(-1 : 0 : 0), (-1 : 0 : 1), (-1 : 1 : -1), (-1 : 1 : 0),
6670
(-1 : 1 : 1), (0 : -1 : -1), (0 : -1 : 0), (0 : -1 : 1),
@@ -69,32 +73,32 @@ def ZZ_points_of_bounded_height(dim, bound):
6973
There are no points of negative height::
7074
7175
sage: from sage.schemes.projective.proj_bdd_height import ZZ_points_of_bounded_height
72-
sage: list(ZZ_points_of_bounded_height(1, -3))
76+
sage: PS = ProjectiveSpace(ZZ, 1)
77+
sage: list(ZZ_points_of_bounded_height(PS, 1, -3))
7378
[]
7479
"""
7580
if bound < 1:
7681
return iter(set([]))
7782

78-
PN = ProjectiveSpace(ZZ, dim)
7983
points_of_bounded_height = set([])
8084

81-
all_tuples = itertools.product(range(-bound, bound+1), repeat=dim+1)
82-
83-
for t in all_tuples:
85+
for t in itertools.product(range(-bound, bound+1), repeat=dim+1):
8486
if gcd(t) == 1:
85-
point = PN(t)
87+
point = PS(t)
8688
if point not in points_of_bounded_height:
8789
points_of_bounded_height.add(point)
8890
yield point
8991

9092

91-
def QQ_points_of_bounded_height(dim, bound, normalize=False):
93+
def QQ_points_of_bounded_height(PS, dim, bound, normalize=False):
9294
r"""
9395
Return an iterator of the points in ``self`` of absolute multiplicative
9496
height of at most ``bound`` in the rational field.
9597
9698
INPUT:
9799
100+
- ``PS`` -- a projective space
101+
98102
- ``dim`` -- a positive integer
99103
100104
- ``bound`` -- a real number
@@ -109,35 +113,36 @@ def QQ_points_of_bounded_height(dim, bound, normalize=False):
109113
EXAMPLES:
110114
111115
sage: from sage.schemes.projective.proj_bdd_height import QQ_points_of_bounded_height
112-
sage: sorted(list(QQ_points_of_bounded_height(1, 1)))
116+
sage: PS = ProjectiveSpace(QQ, 1)
117+
sage: sorted(list(QQ_points_of_bounded_height(PS, 1, 1)))
113118
[(-1 : 1), (0 : 1), (1 : 0), (1 : 1)]
114-
sage: len(list(QQ_points_of_bounded_height(1, 5)))
119+
sage: len(list(QQ_points_of_bounded_height(PS, 1, 5)))
115120
40
116-
sage: sorted(list(QQ_points_of_bounded_height(1, 2)))
121+
sage: sorted(list(QQ_points_of_bounded_height(PS, 1, 2)))
117122
[(-2 : 1), (-1 : 1), (-1/2 : 1), (0 : 1),
118123
(1/2 : 1), (1 : 0), (1 : 1), (2 : 1)]
119-
sage: sorted(list(QQ_points_of_bounded_height(1, 2, normalize=True)))
124+
sage: sorted(list(QQ_points_of_bounded_height(PS, 1, 2, normalize=True)))
120125
[(-2 : 1), (-1 : 1), (-1 : 2), (0 : 1),
121126
(1 : 0), (1 : 1), (1 : 2), (2 : 1)]
122127
123128
There are no points of negative height::
124129
125130
sage: from sage.schemes.projective.proj_bdd_height import QQ_points_of_bounded_height
126-
sage: list(QQ_points_of_bounded_height(1, -3))
131+
sage: PS = ProjectiveSpace(QQ, 1)
132+
sage: list(QQ_points_of_bounded_height(PS, 1, -3))
127133
[]
128134
"""
129135
if bound < 1:
130136
return iter(set([]))
131137

132-
PN = ProjectiveSpace(QQ, dim)
133138
unit_tuples = list(itertools.product([-1, 1], repeat=dim))
134139
points_of_bounded_height = set([])
135140
increasing_tuples = itertools.combinations_with_replacement(range(floor(bound + 1)), dim + 1)
136141
for t in increasing_tuples:
137142
if gcd(t) == 1:
138143
for p in itertools.permutations(t):
139144
for u in unit_tuples:
140-
point = PN([a*b for a, b in zip(u, p)] + [p[dim]])
145+
point = PS([a*b for a, b in zip(u, p)] + [p[dim]])
141146
if point not in points_of_bounded_height:
142147
if normalize:
143148
point.scale_by(lcm([point[i].denominator() for i in range(dim + 1)]))
@@ -146,24 +151,21 @@ def QQ_points_of_bounded_height(dim, bound, normalize=False):
146151
yield point
147152

148153

149-
def IQ_points_of_bounded_height(PN, K, dim, bound, normalize=False):
154+
def IQ_points_of_bounded_height(PS, K, dim, bound):
150155
r"""
151156
Return an iterator of the points in ``self`` of absolute multiplicative
152157
height of at most ``bound`` in the imaginary quadratic field ``K``.
153158
154159
INPUT:
155160
156-
- ``PN`` -- a projective space
161+
- ``PS`` -- a projective space
157162
158163
- ``K`` -- a number field
159164
160165
- ``dim`` -- a positive interger
161166
162167
- ``bound`` -- a real number
163168
164-
- ``normalize`` -- boolean (optional, default: ``False``); whether to
165-
normalize the coordinates of returned points
166-
167169
OUTPUT:
168170
169171
- an iterator of points of bounded height
@@ -217,18 +219,14 @@ def IQ_points_of_bounded_height(PN, K, dim, bound, normalize=False):
217219
if a == K.ideal(point_coordinates):
218220
for p in itertools.permutations(point_coordinates):
219221
for u in unit_tuples:
220-
point = PN([i*j for i, j in zip(u, p)] + [p[dim]])
222+
point = PS([i*j for i, j in zip(u, p)] + [p[dim]])
221223

222224
if point not in points_in_class_a:
223-
if normalize:
224-
denom = K.ideal(list(point)).absolute_norm().denominator()
225-
point.scale_by(denom)
226-
227225
points_in_class_a.add(point)
228226
yield point
229227

230228

231-
def points_of_bounded_height(PN, K, dim, bound, prec=53, normalize=False):
229+
def points_of_bounded_height(PS, K, dim, bound, prec=53):
232230
r"""
233231
Return an iterator of the points in ``K`` with dimension ``dim`` of
234232
absolute multiplicative height of at most ``bound``.
@@ -239,7 +237,7 @@ def points_of_bounded_height(PN, K, dim, bound, prec=53, normalize=False):
239237
240238
INPUT:
241239
242-
- ``PN`` -- a projective space
240+
- ``PS`` -- a projective space
243241
244242
- ``K`` -- a number field
245243
@@ -249,9 +247,6 @@ def points_of_bounded_height(PN, K, dim, bound, prec=53, normalize=False):
249247
250248
- ``prec`` -- (default: 53) a positive integer
251249
252-
- ``normalize`` -- boolean (optional, default: ``False``); whether to
253-
normalize the coordinates of returned points
254-
255250
OUTPUT:
256251
257252
- an iterator of points of bounded height
@@ -275,16 +270,14 @@ def points_of_bounded_height(PN, K, dim, bound, prec=53, normalize=False):
275270
sage: P.<z,w> = ProjectiveSpace(O, 1)
276271
sage: len(list(P.points_of_bounded_height(bound=2)))
277272
44
278-
sage: len(list(P.points_of_bounded_height(bound=2, normalize=True)))
279-
44
280273
281274
::
282275
283276
sage: R.<x> = QQ[]
284277
sage: K.<a> = NumberField(3*x^2 + 1)
285278
sage: O = K.maximal_order()
286279
sage: P.<z,w> = ProjectiveSpace(O, 1)
287-
sage: sorted(list(P.points_of_bounded_height(bound=1, normalize=True)))
280+
sage: sorted(list(P.points_of_bounded_height(bound=1)))
288281
[(-1 : 1), (-3/2*a - 1/2 : 1), (3/2*a - 1/2 : 1), (0 : 1),
289282
(-3/2*a + 1/2 : 0), (-3/2*a + 1/2 : 1), (3/2*a + 1/2 : 1), (1 : 1)]
290283
@@ -309,8 +302,6 @@ def points_of_bounded_height(PN, K, dim, bound, prec=53, normalize=False):
309302
else:
310303
K_degree = K.degree()
311304

312-
O = K.maximal_order()
313-
314305
roots_of_unity = K.roots_of_unity()
315306
unit_tuples = list(itertools.product(roots_of_unity, repeat=dim))
316307

@@ -457,12 +448,8 @@ def points_of_bounded_height(PN, K, dim, bound, prec=53, normalize=False):
457448
if log_arch_height <= log_arch_height_bound and a == K.ideal(point_coordinates):
458449
for p in itertools.permutations(point_coordinates):
459450
for u in unit_tuples:
460-
point = PN([i*j for i, j in zip(u, p)] + [p[dim]])
451+
point = PS([i*j for i, j in zip(u, p)] + [p[dim]])
461452

462453
if point not in points_in_class_a:
463-
if normalize:
464-
denom = K.ideal(list(point)).absolute_norm().denominator()
465-
point.scale_by(denom)
466-
467454
points_in_class_a.add(point)
468455
yield point

0 commit comments

Comments
 (0)