This is an old revision of the document!


Recall the ADTs defined in the previous lab and lecture (together with their operators):

  • Binary Tree
  • List
  • Nat

And the following definition of reverse:

$ reverse : List \rightarrow List$ $ reverse(Empty) = Empty$ $ reverse(Cons(x, xs)) = append(reverse(xs), Cons(x, Empty))$

1. Prove the following properties are true, using structural induction:

  • $ \forall t \in \texttt{Tree}. size(t) = size(mirror(t))$
  • $ \forall t \in \texttt{Tree}. size(t) = length(flatten(t))$
  • $ \forall t \in \texttt{Tree}. flatten(mirror(t)) = reverse(flatten(t))$
  • $ \forall a, b, c \in \texttt{Nat}. add(a, add(b, c)) = add(add(a, b), c)$
  • $ \forall l \in \texttt{List}. append(l, Empty) = l$
  • $ \forall l1, l2, l3 \in \texttt{List}. append(l1, append(l2, l3)) = append(append(l1, l2), l3))$
  • $ \forall l1, l2 \in \texttt{List}. length(append(l1, l2)) = length(append(l2, l1))$
  • $ \forall l1, l2 \in \texttt{List}. reverse(append(l1, l2)) = append(reverse(l2), reverse(l1))$ .