Proof: List Get Item Example
Let's prove the following theorem:
the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = 14
In this example, we prove that the element at index 2 of list [10, [12, [14,[]]]] is 14.
At each step, we pop an element from the front of the list and at the same time, decrease the index by 1. When the index reaches 0, we have found our element.
For instance, the following:
the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ]
is equal to:
the element at index 1 of stack [ 12, [ 14, [ ] ] ]
which is equal to:
the element at index 0 of stack [ 14, [ ] ]
which is finally equal to 14
Proof:
# | Claim | Reason |
---|---|---|
1 | the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index (2 - 1) of stack [ 12, [ 14, [ ] ] ] | the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index (2 - 1) of stack [ 12, [ 14, [ ] ] ] |
2 | 2 - 1 = 1 | 2 - 1 = 1 |
3 | the element at index (2 - 1) of stack [ 12, [ 14, [ ] ] ] = the element at index 1 of stack [ 12, [ 14, [ ] ] ] | if 2 - 1 = 1, then the element at index (2 - 1) of stack [ 12, [ 14, [ ] ] ] = the element at index 1 of stack [ 12, [ 14, [ ] ] ] |
4 | the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index 1 of stack [ 12, [ 14, [ ] ] ] | if the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index (2 - 1) of stack [ 12, [ 14, [ ] ] ] and the element at index (2 - 1) of stack [ 12, [ 14, [ ] ] ] = the element at index 1 of stack [ 12, [ 14, [ ] ] ], then the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index 1 of stack [ 12, [ 14, [ ] ] ] |
5 | the element at index 1 of stack [ 12, [ 14, [ ] ] ] = the element at index (1 - 1) of stack [ 14, [ ] ] | the element at index 1 of stack [ 12, [ 14, [ ] ] ] = the element at index (1 - 1) of stack [ 14, [ ] ] |
6 | 1 - 1 = 0 | 1 - 1 = 0 |
7 | the element at index (1 - 1) of stack [ 14, [ ] ] = the element at index 0 of stack [ 14, [ ] ] | if 1 - 1 = 0, then the element at index (1 - 1) of stack [ 14, [ ] ] = the element at index 0 of stack [ 14, [ ] ] |
8 | the element at index 1 of stack [ 12, [ 14, [ ] ] ] = the element at index 0 of stack [ 14, [ ] ] | if the element at index 1 of stack [ 12, [ 14, [ ] ] ] = the element at index (1 - 1) of stack [ 14, [ ] ] and the element at index (1 - 1) of stack [ 14, [ ] ] = the element at index 0 of stack [ 14, [ ] ], then the element at index 1 of stack [ 12, [ 14, [ ] ] ] = the element at index 0 of stack [ 14, [ ] ] |
9 | the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index 0 of stack [ 14, [ ] ] | if the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index 1 of stack [ 12, [ 14, [ ] ] ] and the element at index 1 of stack [ 12, [ 14, [ ] ] ] = the element at index 0 of stack [ 14, [ ] ], then the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index 0 of stack [ 14, [ ] ] |
10 | the element at index 0 of stack [ 14, [ ] ] = 14 | the element at index 0 of stack [ 14, [ ] ] = 14 |
11 | the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = 14 | if the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = the element at index 0 of stack [ 14, [ ] ] and the element at index 0 of stack [ 14, [ ] ] = 14, then the element at index 2 of stack [ 10, [ 12, [ 14, [ ] ] ] ] = 14 |
Comments
Please log in to add comments