-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExercises2_02.thy
48 lines (40 loc) · 971 Bytes
/
Exercises2_02.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
theory Exercises2_02
imports Main
begin
(*---------------- Exercise 2.2----------------*)
(* add function *)
fun add :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
"add m 0 = m" |
"add m (Suc n) = Suc(add m n)"
(* prove associativity of add *)
theorem add_associative : "add x (add y z) = add (add x y) z"
apply(induction z)
apply(auto)
done
(* prove commutativity of add *)
(* lemma 1*)
lemma add2zero : "add 0 x = x"
apply(induction x)
apply(auto)
done
(* lemma 2 *)
lemma suc_add : "Suc (add y x) = add (Suc y) x"
apply(induction x)
apply(auto)
done
theorem add_commutative : "add x y = add y x"
apply(induction y)
apply(auto)
apply(simp add: add2zero)
apply(simp add: suc_add)
done
(* double function *)
fun double :: "nat \<Rightarrow> nat" where
"double 0 = 0" |
"double (Suc m) = 2 + (double m)"
theorem double_add : "double m = add m m"
apply(induction m)
apply(auto)
apply(simp add: add_commutative)
done
end