-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyList.thy
45 lines (32 loc) · 878 Bytes
/
MyList.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
(* author: wzh*)
theory MyList
imports Main
begin
datatype 'a list = Nil | Cons 'a "'a list"
(*app means add two lists*)
fun app :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list" where
"app Nil xs = xs" |
"app (Cons x xs) ys = Cons x (app xs ys)"
(*rev means reverse a list*)
fun rev :: "'a list \<Rightarrow> 'a list" where
"rev Nil = Nil" |
"rev (Cons x xs) = app (rev xs) (Cons x Nil)"
value "rev(Cons True (Cons False Nil))"
value "rev(Cons a (Cons b Nil))"
lemma app_Nil2 [simp]: "app xs Nil = xs"
apply(induction xs)
apply(auto)
done
lemma app_assoc [simp]: "app (app xs ys) zs = app xs (app ys zs)"
apply(induction xs)
apply(auto)
done
lemma rev_app [simp]: "rev (app xs ys) = app (rev ys) (rev xs)"
apply(induction xs)
apply(auto)
done
theorem rev_rev [simp]: "rev (rev xs) = xs"
apply(induction xs)
apply(auto)
done
end