CachedPower SΒΆ

cachedpow.spad line 38 [edit on github]

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 the n-th power of x, if that has already been computed. Otherwise it computes the n-th power by repeated squaring and stores all intermediately computed powers of x including the n-th power in the cache and only then returns the result.

power!: (%, PositiveInteger) -> S

power!(x, n) extracts the n-th power of x, if that has already been computed. Otherwise it computes the n-th power by repeated squaring and stores all intermediately computed powers of x including the n-th power in the cache and only then returns the result.

CoercibleFrom S

CoercibleTo S