Jump to content

Knuth's power tree: Difference between revisions

m
tweak for addition-chain exponentiation
m (tweak for addition-chain exponentiation)
Line 981:
for i=1 to length(lvl) do
integer x = lvl[i]
sequence pypx = path(x)
for j=1 to length(pypx) do
integer y = x+pypx[j]
if getd_index(y,p)!=NULL then exit end if
setd(y,x,p)
Line 996:
include bigatom.e
function treepow(object x, integer n, sequence pn = {})
-- x can be atom or bigatom
-- (asides: sequence r uses out-by-1 indexing, ie r[1] is for 0.
-- pipa/pa/res perform useful type-checking, ie prevent
-- this from trying to use something not yet calculated.)
sequenceif pn ={} then pn=path(n) end if
sequence r = {BA_ONE,ba_new(x)}&repeat(0,max(0,n-1))
integer p = 0
Line 1,016:
 
procedure showpow(atom x, integer n)
printf(1,"%48ssequence : %3g ^ %dpn = %s\n", {sprint(path(n)),x,n,treepow(x,n)})
printf(1,"%48s : %3g ^ %d = %s\n", {sprint(pn),x,n,treepow(x,n,pn)})
end procedure
7,818

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.