Proof: List Contains Element Example
Let's prove the following theorem:
stack [ 2, [ 4, [ 6, [ ] ] ] ] contains 4 = True
In this example, we prove that the list [2, [4, [6,[]]]] contains 4.
At each step, we observe the first element in the list. If the first element is 4, then we have shown that the list contains 4. If not, then pop the first element off the list and start over.
For instance, the first element of the following:
[ 2, [ 4, [ 6, [ ] ] ] ]
is 2, which is not 4. After we pop 2, the list becomes:
[ 4, [ 6, [ ] ] ]
The first element is 4, so we have found our value, and the proof is complete.
Proof:
# | Claim | Reason |
---|---|---|
1 | not (2 = 4) | not (2 = 4) |
2 | stack [ 2, [ 4, [ 6, [ ] ] ] ] contains 4 = stack [ 4, [ 6, [ ] ] ] contains 4 | if not (2 = 4), then stack [ 2, [ 4, [ 6, [ ] ] ] ] contains 4 = stack [ 4, [ 6, [ ] ] ] contains 4 |
3 | 4 = 4 | 4 = 4 |
4 | stack [ 4, [ 6, [ ] ] ] contains 4 = True | if 4 = 4, then stack [ 4, [ 6, [ ] ] ] contains 4 = True |
5 | stack [ 2, [ 4, [ 6, [ ] ] ] ] contains 4 = True | if stack [ 2, [ 4, [ 6, [ ] ] ] ] contains 4 = stack [ 4, [ 6, [ ] ] ] contains 4 and stack [ 4, [ 6, [ ] ] ] contains 4 = True, then stack [ 2, [ 4, [ 6, [ ] ] ] ] contains 4 = True |
Comments
Please log in to add comments