From the benchmark page:
sage: R.<x,y,z> = PolynomialRing(GF(13))
sage: time _ = expand((x+y+z+1)**100)
CPU times: user 0.07 s,...
Since (a+b)^p=a^p+b^p over a finite field with charachteristic p and
a^p+b^p has got only two terms this gives the idea to expand the
exponent of the polynom in base p and use this in the powering:
# still a naive code, because sage is not use that the computation of
(a+b+c+..)^p is easy
By this code the above task:
time _ = expand(fastpower(x+y+z+1,100,13))
takes only 0.01 sec. (the original code takes 0.14 sec. on my
time _ = expand(fastpower(x+y+z+1,500,13))
takes only 0.12 sec. (the original code takes 13.79 sec.), means an
about 115 times faster code.