-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP21.thy
58 lines (44 loc) · 1.25 KB
/
P21.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
theory P21 imports Main begin
datatype tree = Tp | Nd tree tree
fun tips :: "tree \<Rightarrow> nat" where
"tips Tp = 1" |
"tips (Nd l r) = tips l + tips r"
fun height :: "tree \<Rightarrow> nat" where
"height Tp = 0" |
"height (Nd l r) = 1 + max (height l) (height r)"
primrec cbt :: "nat \<Rightarrow> tree" where
"cbt 0 = Tp" |
"cbt (Suc n) = Nd (cbt n) (cbt n)"
fun iscbt :: "(tree \<Rightarrow> 'a) \<Rightarrow> tree \<Rightarrow> bool" where
"iscbt f Tp = True" |
"iscbt f (Nd l r) = (f l = f r \<and> iscbt f l \<and> iscbt f r)"
lemma [simp]: "iscbt height t \<Longrightarrow> tips t = 2 ^ (height t)"
apply (induct t)
apply auto
done
theorem "iscbt height t = iscbt tips t"
apply (induct t)
apply auto
done
lemma [simp]: "tips t = size t + 1"
apply (induct t)
apply auto
done
theorem "(iscbt tips t = iscbt size t)"
apply (induct t)
apply auto
done
theorem "iscbt height (cbt n)"
apply (induct n)
apply auto
done
theorem "iscbt height t \<Longrightarrow> t = cbt (height t)"
apply (induct t)
apply auto
done
theorem "iscbt (\<lambda>t. False) \<noteq> (iscbt size)"
apply (rule notI)
apply (metis add_cancel_right_left iscbt.simps(1) iscbt.simps(2) nat.distinct(1)
tree.size(3) tree.size(4))
done
end