Skip to content

Commit 3205f9d

Browse files
author
Release Manager
committed
gh-35959: some details in dirichlet.py <!-- ^^^^^ 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" --> <!-- Describe your changes here in detail --> Just a few minor changes in the modified file. Notably using the faster factorial and binomial <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 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! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35959 Reported by: Frédéric Chapoton Reviewer(s): Travis Scrimshaw
2 parents 7315f73 + 464df29 commit 3205f9d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/sage/modular/dirichlet.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363

6464
from sage.arith.functions import lcm
6565
from sage.arith.misc import bernoulli, kronecker, factor, gcd, fundamental_discriminant, euler_phi, valuation
66+
from sage.arith.misc import binomial, factorial
6667
from sage.categories.map import Map
6768
from sage.categories.objects import Objects
68-
from sage.functions.other import binomial, factorial
6969
from sage.libs.pari import pari
7070
from sage.misc.cachefunc import cached_method
7171
from sage.misc.fast_methods import WithEqualityById
@@ -75,10 +75,9 @@
7575
from sage.rings.finite_rings.integer_mod import Mod
7676
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
7777
from sage.rings.integer import Integer
78-
from sage.rings.integer_ring import ZZ
7978
from sage.rings.number_field.number_field import CyclotomicField, NumberField, NumberField_generic
8079
from sage.rings.power_series_ring import PowerSeriesRing
81-
from sage.rings.rational_field import RationalField, QQ, is_RationalField
80+
from sage.rings.rational_field import QQ, is_RationalField
8281
from sage.rings.ring import is_Ring
8382
from sage.structure.element import MultiplicativeGroupElement
8483
from sage.structure.factory import UniqueFactory
@@ -88,7 +87,7 @@
8887
from sage.structure.sequence import Sequence
8988

9089

91-
def trivial_character(N, base_ring=RationalField()):
90+
def trivial_character(N, base_ring=QQ):
9291
r"""
9392
Return the trivial character of the given modulus, with values in the given
9493
base ring.
@@ -135,14 +134,14 @@ def kronecker_character(d):
135134
raise ValueError("d must be nonzero")
136135

137136
D = fundamental_discriminant(d)
138-
G = DirichletGroup(abs(D), RationalField())
137+
G = DirichletGroup(abs(D), QQ)
139138
return G([kronecker(D, u) for u in G.unit_gens()])
140139

141140

142141
def kronecker_character_upside_down(d):
143142
"""
144143
Return the quadratic Dirichlet character (./d) of conductor d, for
145-
d0.
144+
d > 0.
146145
147146
EXAMPLES::
148147
@@ -157,11 +156,11 @@ def kronecker_character_upside_down(d):
157156
if d <= 0:
158157
raise ValueError("d must be positive")
159158

160-
G = DirichletGroup(d, RationalField())
159+
G = DirichletGroup(d, QQ)
161160
return G([kronecker(u.lift(), d) for u in G.unit_gens()])
162161

163162

164-
def is_DirichletCharacter(x):
163+
def is_DirichletCharacter(x) -> bool:
165164
r"""
166165
Return ``True`` if ``x`` is of type ``DirichletCharacter``.
167166
@@ -639,7 +638,7 @@ def bernoulli(self, k, algorithm='recurrence', cache=True, **opts):
639638
.. MATH::
640639
641640
\sum_{a=1}^N \frac{\varepsilon(a) t e^{at}}{e^{Nt}-1}
642-
= sum_{k=0}^{\infty} \frac{B_{k,\varepsilon}}{k!} t^k.
641+
= \sum_{k=0}^{\infty} \frac{B_{k,\varepsilon}}{k!} t^k.
643642
644643
ALGORITHM:
645644
@@ -707,8 +706,9 @@ def bernoulli(self, k, algorithm='recurrence', cache=True, **opts):
707706

708707
def S(n):
709708
return sum(v[r] * r**n for r in range(1, N))
710-
ber = K(sum(binomial(k, j) * bernoulli(j, **opts) *
711-
N**(j - 1) * S(k - j) for j in range(k + 1)))
709+
710+
ber = sum(binomial(k, j) * bernoulli(j, **opts) *
711+
N**(j - 1) * S(k - j) for j in range(k + 1))
712712
elif algorithm == "definition":
713713
# This is better since it computes the same thing, but requires
714714
# no arith in a poly ring over a number field.
@@ -721,7 +721,7 @@ def S(n):
721721
h = [0] + [g * ((n * t).exp(prec)) for n in range(1, N + 1)]
722722
ber = sum([self(a) * h[a][k] for a in range(1, N + 1)]) * factorial(k)
723723
else:
724-
raise ValueError("algorithm = '%s' unknown" % algorithm)
724+
raise ValueError(f"algorithm = '{algorithm}' unknown")
725725

726726
if cache:
727727
self.__bernoulli[k] = ber
@@ -998,7 +998,7 @@ def fixed_field_polynomial(self, algorithm="pari"):
998998
G, chi = self._pari_init_()
999999
K = pari.charker(G, chi)
10001000
H = pari.galoissubcyclo(G, K)
1001-
P = PolynomialRing(RationalField(), "x")
1001+
P = PolynomialRing(QQ, "x")
10021002
x = P.gen()
10031003
return H.sage({"x": x})
10041004

@@ -2943,7 +2943,7 @@ def _automorphisms(self):
29432943
if p == 0:
29442944
Auts = [e for e in range(1, n) if gcd(e, n) == 1]
29452945
else:
2946-
if not ZZ(p).is_prime():
2946+
if not Integer(p).is_prime():
29472947
raise NotImplementedError("Automorphisms for finite non-field base rings not implemented")
29482948
# The automorphisms in characteristic p are
29492949
# k-th powering for

src/sage/sandpiles/sandpile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
from sage.combinat.set_partition import SetPartitions
327327
from sage.combinat.vector_partition import IntegerVectorsIterator
328328
from sage.functions.log import exp
329-
from sage.functions.other import binomial
329+
from sage.arith.misc import binomial
330330
from sage.geometry.polyhedron.constructor import Polyhedron
331331
from sage.graphs.graph import Graph
332332
from sage.graphs.digraph import DiGraph

0 commit comments

Comments
 (0)