#707: Database for Knuth's Power Tree
------------------------------------+----------------------------
Reporter: boothby | Owner: boothby
Type: enhancement | Status: new
Priority: minor | Milestone: sage-feature
Component: basic arithmetic | Resolution:
Keywords: | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
------------------------------------+----------------------------
Comment (by chapoton):
To be able to see the tree, here is the code from codegolf, slightly
adapted to sage:
{{{
def chain(tree, x):
c = [x]
while x != 1:
x = tree[x]
c.append(x)
return c[::-1]
def knuth_tree(levels):
"""
EXAMPLES::
sage: knuth_tree(5).show(layout='tree',tree_root=1)
sage: G = knuth_tree(6)
sage: Poset(G).show(layout='tree')
"""
tree = {1: None}
leaves = [1]
for _ in range(levels):
newleaves = []
for m in leaves:
for i in chain(tree, m):
if i + m not in tree:
tree[i + m] = m
newleaves.append(i + m)
leaves = newleaves
return DiGraph([[i, tree[i]] for i in tree if not i == 1])
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/707#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.