2 theory Tree imports Main begin
6 Define the datatype of \rmindex{binary trees}:
9 datatype 'a tree = Tip | Node "'a tree" 'a "'a tree";(*<*)
11 primrec mirror :: "'a tree \<Rightarrow> 'a tree" where
13 "mirror (Node l x r) = Node (mirror r) x (mirror l)";(*>*)
16 Define a function @{term"mirror"} that mirrors a binary tree
17 by swapping subtrees recursively. Prove
20 lemma mirror_mirror: "mirror(mirror t) = t";
25 primrec flatten :: "'a tree => 'a list" where
27 "flatten (Node l x r) = flatten l @ [x] @ flatten r";
31 Define a function @{term"flatten"} that flattens a tree into a list
32 by traversing it in infix order. Prove
35 lemma "flatten(mirror t) = rev(flatten t)";