2021 02 15 MATH 3600 Trees

294 days ago by calkin

In this worksheet we'll explore creating the tree from the 3n+1 conjecture.

 

A graph is a dictionary containing pairs: v: L where v is a vertex, and L is a list of vertices adjacent to v

d = {0: [1,4,5], 1: [2,6], 2: [3,7], 3: [4,8], 4: [9], 5: [7, 8], 6: [8,9], 7: [9]}
G = Graph(d)
plot(G)


show(G)


G=Graph(d)


G


CollatzTree={}
for i in srange(2,10):
if i%3==1:
CollatzTree.update({i:[(i-1)/3,2*i]})
else:
CollatzTree.update({i:[2*i]})


print(CollatzTree)

{2: [4], 3: [6], 4: [1, 8], 5: [10], 6: [12], 7: [2, 14], 8: [16], 9:
[18]}

CollatzTree.update({16:[5,8]})
CollatzTree.update( {3:[6,10] })
CollatzTree.update( {9:[18,28] })
CollatzTree.update({14:[28]})

 

T=Graph(CollatzTree)


from sage.graphs.graph_plot import GraphPlot


T.show(layout='tree', tree_root=1)


T.is_tree()

True

show(T)


CollatzTree={}
for i in srange(1,27):
a=i
while a>1:
if is_even(a):
#if a<50:
CollatzTree.update({a:[a/2]})
a=a/2
else:
#if a<50:
CollatzTree.update({a:[3*a+1]})
a=3*a+1


T=Graph(CollatzTree)


show(T)


x=T.graphplot(layout='tree', tree_root=1,tree_orientation='up')


x.show(figsize=[25,20])


sage.graphs.graph_plot.DEFAULT_SHOW_OPTIONS['figsize'] = [10,10]


plot(x,figsize=[8,8])

 

d = {0: [1,4,5], 1: [2,6], 2: [3,7], 3: [4,8], 4: [9], 5: [7, 8], 6: [8,9], 7: [9]} G = Graph(d) plot(G) show(G) G=Graph(d) G 
       
Traceback (click to the left of this block for traceback)
...
TypeError: eval() got multiple values for keyword argument 'locals'
Traceback (most recent call last):           	
  File "", line 1, in <module>
    
  File "/usr/local/sage-6.10/local/lib/python2.7/site-packages/sagenb-0.11.4-py2.7.egg/sagenb/misc/support.py", line 438, in syseval
    return system.eval(cmd, sage_globals, locals = sage_globals)
  File "/usr/local/sage-6.10/local/lib/python2.7/site-packages/sage/misc/html.py", line 82, in wrapped
    output = method(*args, **kwds)
TypeError: eval() got multiple values for keyword argument 'locals'
CollatzTree={} for i in srange(2,10): if i%3==1: CollatzTree.update({i:[(i-1)/3,2*i]}) else: CollatzTree.update({i:[2*i]}) print(CollatzTree) {2: [4], 3: [6], 4: [1, 8], 5: [10], 6: [12], 7: [2, 14], 8: [16], 9: [18]} CollatzTree.update({16:[5,8]}) CollatzTree.update( {3:[6,10] }) CollatzTree.update( {9:[18,28] }) CollatzTree.update({14:[28]}) T=Graph(CollatzTree) from sage.graphs.graph_plot import GraphPlot T.show(layout='tree', tree_root=1) 
       
{2: [4], 3: [6], 4: [1, 8], 5: [10], 6: [12], 7: [2, 14], 8: [16], 9:
[18]}
{2: [4], 3: [6], 4: [1, 8], 5: [10], 6: [12], 7: [2, 14], 8: [16], 9: [18]}
CollatzTree={} for i in srange(1,27): a=i while a>1: if is_even(a): #if a<50: CollatzTree.update({a:[a/2]}) a=a/2 else: #if a<50: CollatzTree.update({a:[3*a+1]}) a=3*a+1 T=Graph(CollatzTree) show(T) x=T.graphplot(layout='tree', tree_root=1,tree_orientation='up') x.show(figsize=[25,20])