Skip to content

Commit 8aa0254

Browse files
author
Release Manager
committed
gh-35248: using "change_ring" in quadratic_forms <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> ### 📚 Description Deprecate the non-standard `base_change_to` in favor of the standard `change_ring` inside quadratic forms. <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If it resolves an open issue, please link to the issue here. For example "Closes #1337" --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [x] I have made sure that the title is self-explanatory and the description concisely explains the PR. - [ ] I have linked an issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open pull requests that this PR logically depends on --> <!-- - #xyz: short description why this is a dependency - #abc: ... --> URL: #35248 Reported by: Frédéric Chapoton Reviewer(s): Matthias Köppe
2 parents 211c2a1 + a6cd790 commit 8aa0254

File tree

5 files changed

+21
-29
lines changed

5 files changed

+21
-29
lines changed

src/sage/algebras/clifford_algebra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ def _coerce_map_from_(self, V):
571571
Q = self._quadratic_form
572572
try:
573573
return (V.variable_names() == self.variable_names() and
574-
V._quadratic_form.base_change_to(self.base_ring()) == Q)
575-
except Exception:
574+
V._quadratic_form.change_ring(self.base_ring()) == Q)
575+
except (TypeError, AttributeError):
576576
return False
577577

578578
if self.free_module().has_coerce_map_from(V):

src/sage/quadratic_forms/count_local_2.pyx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ def count_modp__by_gauss_sum(n, p, m, Qdet):
8888
return count
8989

9090

91-
92-
93-
94-
9591
cdef CountAllLocalTypesNaive_cdef(Q, p, k, m, zvec, nzvec):
9692
"""
9793
This Cython routine is documented in its Python wrapper method
@@ -102,26 +98,21 @@ cdef CountAllLocalTypesNaive_cdef(Q, p, k, m, zvec, nzvec):
10298
cdef long ptr # Used to increment the vector
10399
cdef long solntype # Used to store the kind of solution we find
104100

105-
106101
# Some shortcuts and definitions
107102
n = Q.dim()
108103
R = p ** k
109-
Q1 = Q.base_change_to(IntegerModRing(R))
110-
104+
Q1 = Q.change_ring(IntegerModRing(R))
111105

112106
# Cython Variables
113107
cdef IntegerMod_gmp zero, one
114108
zero = IntegerMod_gmp(IntegerModRing(R), 0)
115109
one = IntegerMod_gmp(IntegerModRing(R), 1)
116110

117-
118-
119111
# Initialize the counting vector
120-
count_vector = [0 for i in range(6)]
112+
count_vector = [0 for i in range(6)]
121113

122114
# Initialize v = (0, ... , 0)
123-
v = [Mod(0, R) for i in range(n)]
124-
115+
v = [Mod(0, R) for i in range(n)]
125116

126117
# Some declarations to speed up the loop
127118
R_n = R ** n
@@ -140,7 +131,6 @@ cdef CountAllLocalTypesNaive_cdef(Q, p, k, m, zvec, nzvec):
140131
if (ptr > 0):
141132
v[ptr-1] += 1
142133

143-
144134
# Evaluate Q(v) quickly
145135
tmp_val = Mod(0, R)
146136
for a from 0 <= a < n:
@@ -154,7 +144,6 @@ cdef CountAllLocalTypesNaive_cdef(Q, p, k, m, zvec, nzvec):
154144
if (solntype != 0):
155145
count_vector[solntype] += 1
156146

157-
158147
# Generate the Bad-type and Total counts
159148
count_vector[3] = count_vector[4] + count_vector[5]
160149
count_vector[0] = count_vector[1] + count_vector[2] + count_vector[3]

src/sage/quadratic_forms/quadratic_form.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
from sage.quadratic_forms.quadratic_form__evaluate import QFEvaluateVector, QFEvaluateMatrix
4242
from sage.structure.sage_object import SageObject
4343
from sage.combinat.integer_lists.invlex import IntegerListsLex
44+
from sage.misc.superseded import deprecated_function_alias
45+
4446

4547
def QuadraticForm__constructor(R, n=None, entries=None):
4648
"""
@@ -1542,7 +1544,7 @@ def Gram_det(self):
15421544
"""
15431545
return self.det() / ZZ(2**self.dim())
15441546

1545-
def base_change_to(self, R):
1547+
def change_ring(self, R):
15461548
"""
15471549
Alters the quadratic form to have all coefficients
15481550
defined over the new base_ring R. Here R must be
@@ -1555,10 +1557,12 @@ def base_change_to(self, R):
15551557
arithmetic evaluations.
15561558
15571559
INPUT:
1558-
R -- a ring
1560+
1561+
- R -- a ring
15591562
15601563
OUTPUT:
1561-
quadratic form
1564+
1565+
quadratic form
15621566
15631567
EXAMPLES::
15641568
@@ -1567,16 +1571,13 @@ def base_change_to(self, R):
15671571
[ 1 0 ]
15681572
[ * 1 ]
15691573
1570-
::
1571-
1572-
sage: Q1 = Q.base_change_to(IntegerModRing(5)); Q1
1574+
sage: Q1 = Q.change_ring(IntegerModRing(5)); Q1
15731575
Quadratic form in 2 variables over Ring of integers modulo 5 with coefficients:
15741576
[ 1 0 ]
15751577
[ * 1 ]
15761578
15771579
sage: Q1([35,11])
15781580
1
1579-
15801581
"""
15811582
# Check that a canonical coercion is possible
15821583
if not is_Ring(R):
@@ -1586,6 +1587,8 @@ def base_change_to(self, R):
15861587
# Return the coerced form
15871588
return QuadraticForm(R, self.dim(), [R(x) for x in self.coefficients()])
15881589

1590+
base_change_to = deprecated_function_alias(35248, change_ring)
1591+
15891592
def level(self):
15901593
r"""
15911594
Determines the level of the quadratic form over a PID, which is a

src/sage/quadratic_forms/quadratic_form__local_field_invariants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _rational_diagonal_form_and_transformation(self):
223223
"""
224224
n = self.dim()
225225
K = self.base_ring().fraction_field()
226-
Q = self.base_change_to(K)
226+
Q = self.change_ring(K)
227227
MS = MatrixSpace(K, n, n)
228228

229229
try:

src/sage/quadratic_forms/quadratic_form__mass__Siegel_densities.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Copyright by Jonathan Hanke 2007 <[email protected]>
1111
########################################################################
1212

13-
import copy
13+
from copy import deepcopy
1414

1515
from sage.arith.misc import kronecker, legendre_symbol, prime_divisors
1616
from sage.functions.all import sgn
@@ -191,7 +191,7 @@ def Watson_mass_at_2(self):
191191
192192
"""
193193
# Make a 0-dim'l quadratic form (for initialization purposes)
194-
Null_Form = copy.deepcopy(self)
194+
Null_Form = deepcopy(self)
195195
Null_Form.__init__(ZZ, 0)
196196

197197
# Step 0: Compute Jordan blocks and bounds of the scales to keep track of
@@ -230,7 +230,7 @@ def Watson_mass_at_2(self):
230230
eps_dict = {}
231231
for j in range(s_min, s_max+3):
232232
two_form = (diag_dict[j-2] + diag_dict[j] + dim2_dict[j]).scale_by_factor(2)
233-
j_form = (two_form + diag_dict[j-1]).base_change_to(IntegerModRing(4))
233+
j_form = (two_form + diag_dict[j-1]).change_ring(IntegerModRing(4))
234234

235235
if j_form.dim() == 0:
236236
eps_dict[j] = 1
@@ -279,7 +279,7 @@ def Kitaoka_mass_at_2(self):
279279
280280
"""
281281
# Make a 0-dim'l quadratic form (for initialization purposes)
282-
Null_Form = copy.deepcopy(self)
282+
Null_Form = deepcopy(self)
283283
Null_Form.__init__(ZZ, 0)
284284

285285
# Step 0: Compute Jordan blocks and bounds of the scales to keep track of
@@ -372,7 +372,7 @@ def mass_at_two_by_counting_mod_power(self, k):
372372
4
373373
"""
374374
R = IntegerModRing(2**k)
375-
Q1 = self.base_change_to(R)
375+
Q1 = self.change_ring(R)
376376
n = self.dim()
377377
MS = MatrixSpace(R, n)
378378

0 commit comments

Comments
 (0)