Skip to content

Commit dce64d6

Browse files
committed
a few more details
1 parent 7c8291c commit dce64d6

File tree

2 files changed

+69
-78
lines changed

2 files changed

+69
-78
lines changed

src/sage/quadratic_forms/quadratic_form.py

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def quadratic_form_from_invariants(F, rk, det, P, sminus):
125125
"""
126126
from sage.arith.misc import hilbert_symbol
127127
# normalize input
128-
if F!=QQ:
128+
if F != QQ:
129129
raise NotImplementedError('base field must be QQ. If you want this over any field, implement weak approximation.')
130130
P = [ZZ(p) for p in P]
131131
rk = ZZ(rk)
@@ -153,33 +153,33 @@ def quadratic_form_from_invariants(F, rk, det, P, sminus):
153153
else:
154154
a = ZZ(1)
155155
elif rk == 3:
156-
Pprime = [p for p in P if hilbert_symbol(-1, -d, p)==1]
157-
Pprime += [p for p in (2*d).prime_divisors()
158-
if hilbert_symbol(-1, -d, p)==-1 and p not in P]
156+
Pprime = [p for p in P if hilbert_symbol(-1, -d, p) == 1]
157+
Pprime += [p for p in (2 * d).prime_divisors()
158+
if hilbert_symbol(-1, -d, p) == -1 and p not in P]
159159
if sminus > 0:
160160
a = ZZ(-1)
161161
else:
162162
a = ZZ(1)
163163
for p in Pprime:
164164
if d.valuation(p) % 2 == 0:
165165
a *= p
166-
assert all((a*d).valuation(p)%2==1 for p in Pprime)
166+
assert all((a * d).valuation(p) % 2 == 1 for p in Pprime)
167167
elif rk == 2:
168168
S = P
169169
if sminus == 2:
170170
S += [-1]
171-
a = QQ.hilbert_symbol_negative_at_S(S,-d)
171+
a = QQ.hilbert_symbol_negative_at_S(S, -d)
172172
a = ZZ(a)
173173
P = ([p for p in P if hilbert_symbol(a, -d, p) == 1]
174-
+[p for p in (2*a*d).prime_divisors()
175-
if hilbert_symbol(a, -d, p)==-1 and p not in P])
176-
sminus = max(0, sminus-1)
174+
+ [p for p in (2 * a * d).prime_divisors()
175+
if hilbert_symbol(a, -d, p) == -1 and p not in P])
176+
sminus = max(0, sminus - 1)
177177
rk = rk - 1
178-
d = a*d
178+
d = a * d
179179
D.append(a.squarefree_part())
180180
d = d.squarefree_part()
181181
D.append(d)
182-
return DiagonalQuadraticForm(QQ,D)
182+
return DiagonalQuadraticForm(QQ, D)
183183

184184

185185
class QuadraticForm(SageObject):
@@ -606,10 +606,10 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_
606606
self.__coeffs = []
607607
for i in range(M.nrows()):
608608
for j in range(i, M.nrows()):
609-
if (i == j):
610-
self.__coeffs += [ M_ring(M[i,j] / 2) ]
609+
if i == j:
610+
self.__coeffs += [M_ring(M[i, j] / 2)]
611611
else:
612-
self.__coeffs += [ M_ring(M[i,j]) ]
612+
self.__coeffs += [M_ring(M[i, j])]
613613

614614
return
615615

@@ -649,8 +649,8 @@ def __init__(self, R, n=None, entries=None, unsafe_initialization=False, number_
649649
# Set the number of automorphisms
650650
if number_of_automorphisms is not None:
651651
self.set_number_of_automorphisms(number_of_automorphisms)
652-
#self.__number_of_automorphisms = number_of_automorphisms
653-
#self.__external_initialization_list.append('number_of_automorphisms')
652+
# self.__number_of_automorphisms = number_of_automorphisms
653+
# self.__external_initialization_list.append('number_of_automorphisms')
654654

655655
# Set the determinant
656656
if determinant is not None:
@@ -827,7 +827,7 @@ def __setitem__(self, ij, coeff):
827827

828828
# Set the entry
829829
try:
830-
self.__coeffs[i*self.__n - i*(i-1)//2 + j -i] = self.__base_ring(coeff)
830+
self.__coeffs[i*self.__n - i*(i-1)//2 + j - i] = self.__base_ring(coeff)
831831
except Exception:
832832
raise RuntimeError("this coefficient cannot be coerced to an element of the base ring for the quadratic form")
833833

@@ -934,47 +934,42 @@ def sum_by_coefficients_with(self, right):
934934
"""
935935
if not isinstance(right, QuadraticForm):
936936
raise TypeError("cannot add these objects since they are not both quadratic forms")
937-
elif (self.__n != right.__n):
937+
elif self.__n != right.__n:
938938
raise TypeError("cannot add these since the quadratic forms do not have the same sizes")
939-
elif (self.__base_ring != right.__base_ring):
939+
elif self.__base_ring != right.__base_ring:
940940
raise TypeError("cannot add these since the quadratic forms do not have the same base rings")
941-
return QuadraticForm(self.__base_ring, self.__n, [self.__coeffs[i] + right.__coeffs[i] for i in range(len(self.__coeffs))])
942-
943-
# ======================== CHANGE THIS TO A TENSOR PRODUCT?!? Even in Characteristic 2?!? =======================
944-
# def __mul__(self, right):
945-
# """
946-
# Multiply (on the right) the quadratic form Q by an element of the ring that Q is defined over.
947-
#
948-
# EXAMPLES::
949-
#
950-
# sage: Q = QuadraticForm(ZZ, 2, [1,4,10])
951-
# sage: Q*2
952-
# Quadratic form in 2 variables over Integer Ring with coefficients:
953-
# [ 2 8 ]
954-
# [ * 20 ]
955-
#
956-
# sage: Q+Q == Q*2
957-
# True
958-
#
959-
# """
960-
# try:
961-
# c = self.base_ring()(right)
962-
# except Exception:
963-
# raise TypeError, "Oh no! The multiplier cannot be coerced into the base ring of the quadratic form. =("
964-
#
965-
# return QuadraticForm(self.base_ring(), self.dim(), [c * self.__coeffs[i] for i in range(len(self.__coeffs))])
966-
967-
# =================================================================
941+
return QuadraticForm(self.__base_ring, self.__n, [self.__coeffs[i] + right.__coeffs[i] for i in range(len(self.__coeffs))])
942+
943+
# ======================== CHANGE THIS TO A TENSOR PRODUCT?!? Even in Characteristic 2?!? =======================
944+
# def __mul__(self, right):
945+
# """
946+
# Multiply (on the right) the quadratic form Q by an element of the ring that Q is defined over.
947+
#
948+
# EXAMPLES::
949+
#
950+
# sage: Q = QuadraticForm(ZZ, 2, [1,4,10])
951+
# sage: Q*2
952+
# Quadratic form in 2 variables over Integer Ring with coefficients:
953+
# [ 2 8 ]
954+
# [ * 20 ]
955+
#
956+
# sage: Q+Q == Q*2
957+
# True
958+
# """
959+
# try:
960+
# c = self.base_ring()(right)
961+
# except Exception:
962+
# raise TypeError("the multiplier cannot be coerced into the base ring of the quadratic form")
963+
# return QuadraticForm(self.base_ring(), self.dim(), [c * self.__coeffs[i] for i in range(len(self.__coeffs))])
968964

969965
def __call__(self, v):
970966
r"""
971967
Evaluate this quadratic form `Q` on a vector or matrix of elements
972968
coercible to the base ring of the quadratic form.
973969
974-
If a vector
975-
is given then the output will be the ring element `Q(v)`, but if a
976-
matrix is given then the output will be the quadratic form `Q'`
977-
which in matrix notation is given by:
970+
If a vector is given then the output will be the ring element
971+
`Q(v)`, but if a matrix is given then the output will be the
972+
quadratic form `Q'` which in matrix notation is given by:
978973
979974
.. MATH::
980975
@@ -1116,23 +1111,17 @@ def _is_even_symmetric_matrix_(self, A, R=None):
11161111
if not isinstance(R, Ring):
11171112
raise TypeError("R is not a ring.")
11181113

1119-
if not A.is_square():
1114+
if not (A.is_square() and A.is_symmetric()):
11201115
return False
11211116

1122-
# Test that the matrix is symmetric
1123-
n = A.nrows()
1124-
for i in range(n):
1125-
for j in range(i+1, n):
1126-
if A[i,j] != A[j,i]:
1127-
return False
1128-
11291117
# Test that all entries coerce to R
1118+
n = A.nrows()
11301119
if not ((A.base_ring() == R) or ring_coerce_test):
11311120
try:
11321121
for i in range(n):
11331122
for j in range(i, n):
1134-
R(A[i,j])
1135-
except Exception:
1123+
R(A[i, j])
1124+
except (TypeError, ValueError):
11361125
return False
11371126

11381127
# Test that the diagonal is even (if 1/2 isn't in R)
@@ -1180,10 +1169,10 @@ def Hessian_matrix(self):
11801169
mat_entries = []
11811170
for i in range(self.dim()):
11821171
for j in range(self.dim()):
1183-
if (i == j):
1184-
mat_entries += [ 2 * self[i,j] ]
1172+
if i == j:
1173+
mat_entries += [2 * self[i, j]]
11851174
else:
1186-
mat_entries += [ self[i,j] ]
1175+
mat_entries += [self[i, j]]
11871176

11881177
return matrix(self.base_ring(), self.dim(), self.dim(), mat_entries)
11891178

@@ -1384,11 +1373,11 @@ def from_polynomial(poly):
13841373
if not isinstance(R, MPolynomialRing_base):
13851374
raise TypeError(f'not a multivariate polynomial ring: {R}')
13861375
if not all(mon.degree() == 2 for mon in poly.monomials()):
1387-
raise ValueError(f'polynomial has monomials of degree != 2')
1376+
raise ValueError('polynomial has monomials of degree != 2')
13881377
base = R.base_ring()
13891378
vs = R.gens()
13901379
coeffs = []
1391-
for i,v in enumerate(vs):
1380+
for i, v in enumerate(vs):
13921381
for w in vs[i:]:
13931382
coeffs.append(poly.monomial_coefficient(v*w))
13941383
return QuadraticForm(base, len(vs), coeffs)
@@ -1625,7 +1614,7 @@ def level(self):
16251614
# Warn the user if the form is defined over a field!
16261615
if self.base_ring().is_field():
16271616
warn("Warning -- The level of a quadratic form over a field is always 1. Do you really want to do this?!?")
1628-
#raise RuntimeError, "Warning -- The level of a quadratic form over a field is always 1. Do you really want to do this?!?"
1617+
# raise RuntimeError("Warning -- The level of a quadratic form over a field is always 1. Do you really want to do this?!?")
16291618

16301619
# Check invertibility and find the inverse
16311620
try:
@@ -1747,7 +1736,7 @@ def bilinear_map(self, v, w):
17471736
raise TypeError("vectors must have length " + str(self.dim()))
17481737
if self.base_ring().characteristic() == 2:
17491738
raise TypeError("not defined for rings of characteristic 2")
1750-
return (self(v+w) - self(v) - self(w))/2
1739+
return (self(v + w) - self(v) - self(w)) / 2
17511740

17521741

17531742
def DiagonalQuadraticForm(R, diag):

src/sage/schemes/elliptic_curves/ell_rational_field.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6627,22 +6627,23 @@ def reduction_at(p):
66276627
raise RuntimeError('Unexpected intermediate result. Please try another Mordell-Weil base')
66286628
d_L_0 = R(b1_norm**2 / c1_LLL)
66296629

6630-
#Reducing of upper bound
6630+
# Reducing of upper bound
66316631
Q = r * H_q**2
66326632
T = (1 + (Z(3)/2*r*H_q))/2
66336633
if d_L_0 < R(T**2+Q):
66346634
d_L_0 = 10*(T**2*Q)
66356635
low_bound = (R(d_L_0 - Q).sqrt() - T) / c
66366636

6637-
##new bound according to low_bound and upper bound
6638-
##[k5*k6 exp(-k7**H_q^2)]
6637+
# new bound according to low_bound and upper bound
6638+
# [k5*k6 exp(-k7**H_q^2)]
66396639
if low_bound != 0:
66406640
H_q_infinity = R(((low_bound/(k6)).log()/(-k7)).sqrt())
6641-
return (H_q_infinity.ceil())
6641+
return H_q_infinity.ceil()
66426642
else:
6643-
return (H_q)
6644-
#<-------------------------------------------------------------------------
6645-
#>-------------------------------------------------------------------------
6643+
return H_q
6644+
6645+
# --------------------------------------------------------------------
6646+
# --------------------------------------------------------------------
66466647

66476648
def S_integral_points_with_bounded_mw_coeffs():
66486649
r"""
@@ -6726,8 +6727,9 @@ def test_with_T(R):
67266727
Pi[i] = Pi[i-1] + mw_baseN[i]
67276728

67286729
return xs
6729-
#<-------------------------------------------------------------------------
6730-
#>-------------------------------------------------------------------------
6730+
6731+
# --------------------------------------------------------------------
6732+
# --------------------------------------------------------------------
67316733

67326734
def S_integral_x_coords_with_abs_bounded_by(abs_bound):
67336735
r"""
@@ -6802,8 +6804,8 @@ def S_integral_x_coords_with_abs_bounded_by(abs_bound):
68026804
xs += [-tmp]
68036805

68046806
return set(xs)
6805-
#<-------------------------------------------------------------------------
6806-
#End internal functions ###############################################
6807+
# -------------------------------------------------------------------
6808+
# End internal functions ############################################
68076809
from sage.misc.mrange import cartesian_product_iterator
68086810

68096811
E = self

0 commit comments

Comments
 (0)