Skip to content

Commit eba0431

Browse files
Faster computation of cached Frobenius powers
Calling repeatedly PARI fffrobenius function involves redundant computations that can be avoided by reusing already computed powers.
1 parent 27b077e commit eba0431

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)