Question: Lambda terms in de Bruijn notation are represented as trees with unary lambda nodes and binary application nodes, with de Bruijn indices (starting at 0)
Lambda terms in de Bruijn notation are represented as trees with unary lambda nodes and binary application nodes, with de Bruijn indices (starting at 0) marking their leaf nodes. Write a Python program, that given a lambda term in de Bruijn notation, displays it as a tree. The program must use Python tuples for both our lambda nodes and application nodes. To facilitate testing with easier to read inputs, we define: def l(x) : return ('l',x) def a(x,y) : return ('a',x,y) As an example, the Python expression l(l(a(a(0,l(3)),a(l(0),0)))) returns the tree ('l', ('l', ('a', ('a', 0, ('l', 3)), ('a', ('l', 0), 0)))) that can be displayed like this: l | | l | | a __|_ / \ a a | | / \ / \ 0 l l 0 | | | | 3 0 While you can choose to write your own algorithm that outputs the tree using ASCII characters as in the picture above, you can also opt for using any of the available Python packages to help drawing nicer looking trees. The following test set needs to be displayed by the program. l(a(a(1,a(l(l(0)),1)),1)) l(l(l(l(a(0,a(1,l(l(a(0,a(2,0)))))))))) l(l(l(a(a(0,a(1,a(a(l(l(0)),0),2))),1)))) l(l(l(a(l(1),a(l(a(1,0)),a(a(a(2,0),0),0)))))) l(l(l(a(l(a(2,a(a(l(0),l(a(1,a(1,a(1,l(1)))))),l(0)))),a(2,0)))))
- there is a post with an attempted answer but doesn't nearly explain enough or compile the graph
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
