forked from nipkow/fds_ss20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex01.thy
54 lines (37 loc) · 1.02 KB
/
ex01.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
theory ex01
imports Main
begin
value "2 + (2::nat)"
value "(2::nat) * (5 + 3)"
value "(3::nat) * 4 - 2 *(7 + 1)"
lemma "(x::nat) + (y + z) = (x + y) + z"
by auto
lemma "(x::nat) + y = y + x"
apply auto
done
fun count :: "'a list \<Rightarrow> 'a \<Rightarrow> nat" where
"count [] _ = 0" |
"count (x#xs) x' = (if x = x' then Suc (count xs x') else count xs x')"
value "count [(1::nat), 1, 1] 1"
theorem "count xs x \<le> length xs"
apply(induct xs)
apply auto
done
fun snoc::"'a list \<Rightarrow> 'a \<Rightarrow> 'a list" where
"snoc [] x' = [x']" |
"snoc (x#xs) x' = x # (snoc xs x')"
value "snoc [(1::nat),2,3,4] 5"
fun reverse :: "'a list \<Rightarrow> 'a list" where
"reverse [] = []" |
"reverse (x#xs) = snoc (reverse xs) x"
value "reverse [(1::nat),2,3,4]"
lemma "reverse [(1::nat),2,3,4] = [4,3,2,1]"
by simp
lemma reverse_snoc:
"reverse (snoc xs y) = y # reverse xs"
by (induct xs) auto
theorem "reverse (reverse xs) = xs"
apply(induct xs)
apply (auto simp add: reverse_snoc)
done
end