Skip to content

Commit efbaa0d

Browse files
author
Release Manager
committed
gh-35456: Faster computation of cached Frobenius powers ### 📚 Description Calling repeatedly PARI fffrobenius function involves redundant computations that can be avoided by reusing already computed powers. This is a follow-up to #35316 improving the performance of Frobenius on first call: ``` sage: p = next_prime(2**120) ....: K = GF(p**120, 'a') ....: x = K.random_element() sage: %time _ = [x.frobenius(i) for i in (0, 20, 40, 60, 80, 100)] Sage 9.8 CPU times: user 9.73 s, sys: 8 ms, total: 9.73 s Sage 10 beta 8 CPU times: user 6.84 s, sys: 194 µs, total: 6.84 s After patch CPU times: user 681 ms, sys: 0 ns, total: 681 ms When cached (10.0beta8) 30.9 ms ± 155 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) sage: K = GF(5**240, 'a') ....: x = K.random_element() sage: %time _ = [x.frobenius(i) for i in range(240)] Sage 9.8 CPU times: user 1.72 s, sys: 1.12 ms, total: 1.73 s Sage 10.0beta8 CPU times: user 1.02 s, sys: 1.02 ms, total: 1.02 s After patch CPU times: user 219 ms, sys: 12 µs, total: 219 ms When cached (10.0beta8) 168 ms ± 391 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) ``` ### 📝 Checklist - [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. URL: #35456 Reported by: Rémy Oudompheng Reviewer(s): Marc Mezzarobba
2 parents 7ecf985 + eba0431 commit efbaa0d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/sage/rings/finite_rings/finite_field_pari_ffelt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ def _pari_frobenius(self, k=1):
225225
raise ValueError("_pari_frobenius requires a non-zero exponent")
226226
g = self.gen()
227227
i = len(self.__pari_frobenius_powers)
228+
if i == 0:
229+
self.__pari_frobenius_powers.append(g.__pari__().fffrobenius(1))
230+
i = 1
231+
f1 = self.__pari_frobenius_powers[0]
228232
while i < k:
229233
i += 1
230-
self.__pari_frobenius_powers.append(g.__pari__().fffrobenius(i))
234+
fi = self.__pari_frobenius_powers[-1].ffcompomap(f1)
235+
self.__pari_frobenius_powers.append(fi)
231236
return self.__pari_frobenius_powers[k-1]

0 commit comments

Comments
 (0)