CachedPower SΒΆ
cachedpow.spad line 38 [edit on github]
S: SemiGroup
CachedPower(S
) stores together with an element also its powers. Each power is only computed once.
- coerce: % -> S
from CoercibleTo S
- coerce: S -> %
from CoercibleFrom S
- power!: (%, Integer) -> S if S has MagmaWithUnit
power!(x, n)
extracts then
-th power ofx
, if that has already been computed. Otherwise it computes then
-th power by repeated squaring and stores all intermediately computed powers ofx
including then
-th power in the cache and only then returns the result.
- power!: (%, PositiveInteger) -> S
power!(x, n)
extracts then
-th power ofx
, if that has already been computed. Otherwise it computes then
-th power by repeated squaring and stores all intermediately computed powers ofx
including then
-th power in the cache and only then returns the result.