taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 2.3-19

Exercise 2.3-19

not stated yet in Lean solution written

Rating15
KindK8, compute by machine: find a number or an object by a large computation from the written solution
SectionSection 2.3 of Volume 1

The task

Draw a List diagram for L=(a,(L))L = (a, (L)). Find L[2]L[2] and L[2,1,1]L[2,1,1].

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

The second element of LL is a List with one element, and that element is LL itself. In a diagram draw an arrow back to LL.

Solution

Show the solution

LL has two elements: the atom aa, and the List (L)(L). The List (L)(L) has one element, which is LL itself. So the diagram has a cycle.

L:  [ a , * ]
           |
           v
         [ * ]
           |
           +----> back to L

The second element of LL is (L)(L). So L[2]=(L)L[2] = (L). Then L[2,1]L[2,1] is the first element of (L)(L), which is LL. So L[2,1,1]L[2,1,1] is the first element of LL, namely the atom aa.

Answer: L[2]=(L)L[2] = (L) and L[2,1,1]=aL[2,1,1] = a.

Check

A python3 list with a self reference, L = ['a', None]; L[1] = [L], gives L[1] equal to [L], L[1][0] is L true, and L[1][0][0] equal to 'a'.

Remarks

A List can contain itself, so it need not be a tree. This is the main difference between Lists and trees.

This solution is drafted, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.