Knuth's power tree: Difference between revisions

Content added Content deleted
(Added 11l)
Line 99: Line 99:
R path(:p[n]) [+] [n]
R path(:p[n]) [+] [n]


F tree_pow_i(x, n)
F tree_pow(x, n)
V (r, p) = ([0 = BigInt(1), 1 = BigInt(x)], 0)
T Ty = T(x)
L(i) path(n)
V (r, p) = ([0 = Ty(1), 1 = x], 0)
r[i] = r[i - p] * r[p]
p = i
R r[n]

F tree_pow_f(x, n)
V (r, p) = ([0 = 1.0, 1 = x], 0)
L(i) path(n)
L(i) path(n)
r[i] = r[i - p] * r[p]
r[i] = r[i - p] * r[p]
Line 114: Line 108:


F show_pow_i(x, n)
F show_pow_i(x, n)
print("#.: #.\n#.^#. = #.\n".format(n, path(n), x, n, tree_pow_i(x, n)))
print("#.: #.\n#.^#. = #.\n".format(n, path(n), x, n, tree_pow(BigInt(x), n)))


F show_pow_f(x, n)
F show_pow_f(x, n)
print("#.: #.\n#.^#. = #.6\n".format(n, path(n), x, n, tree_pow_f(x, n)))
print("#.: #.\n#.^#. = #.6\n".format(n, path(n), x, n, tree_pow(x, n)))


L(x) 18
L(x) 18