13739
|
1 |
(*<*)
|
|
2 |
theory a1 = Main:
|
|
3 |
(*>*)
|
|
4 |
subsection {* Lists *}
|
|
5 |
|
|
6 |
text {* Define a universal and an existential quantifier on lists.
|
|
7 |
Expression @{term "alls P xs"} should be true iff @{term "P x"} holds
|
|
8 |
for every element @{term x} of @{term xs}, and @{term "exs P xs"}
|
|
9 |
should be true iff @{term "P x"} holds for some element @{term x} of
|
|
10 |
@{term xs}.
|
|
11 |
*}
|
|
12 |
consts
|
|
13 |
alls :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
|
|
14 |
exs :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool"
|
|
15 |
|
|
16 |
text {*
|
|
17 |
Prove or disprove (by counter example) the following theorems.
|
|
18 |
You may have to prove some lemmas first.
|
|
19 |
|
|
20 |
Use the @{text "[simp]"}-attribute only if the equation is truly a
|
|
21 |
simplification and is necessary for some later proof.
|
|
22 |
*}
|
|
23 |
|
|
24 |
lemma "alls (\<lambda>x. P x \<and> Q x) xs = (alls P xs \<and> alls Q xs)"
|
|
25 |
(*<*)oops(*>*)
|
|
26 |
|
|
27 |
lemma "alls P (rev xs) = alls P xs"
|
|
28 |
(*<*)oops(*>*)
|
|
29 |
|
|
30 |
lemma "exs (\<lambda>x. P x \<and> Q x) xs = (exs P xs \<and> exs Q xs)"
|
|
31 |
(*<*)oops(*>*)
|
|
32 |
|
|
33 |
lemma "exs P (map f xs) = exs (P o f) xs"
|
|
34 |
(*<*)oops(*>*)
|
|
35 |
|
|
36 |
lemma "exs P (rev xs) = exs P xs"
|
|
37 |
(*<*)oops(*>*)
|
|
38 |
|
|
39 |
text {* Find a term @{text Z} such that the following equation holds: *}
|
|
40 |
lemma "exs (\<lambda>x. P x \<or> Q x) xs = Z"
|
|
41 |
(*<*)oops(*>*)
|
|
42 |
|
|
43 |
text {* Express the existential via the universal quantifier ---
|
|
44 |
@{text exs} should not occur on the right-hand side: *}
|
|
45 |
lemma "exs P xs = Z"
|
|
46 |
(*<*)oops(*>*)
|
|
47 |
|
|
48 |
text {*
|
|
49 |
Define a function @{term "is_in x xs"} that checks if @{term x} occurs in
|
|
50 |
@{term xs} vorkommt. Now express @{text is_in} via @{term exs}:
|
|
51 |
*}
|
|
52 |
lemma "is_in a xs = Z"
|
|
53 |
(*<*)oops(*>*)
|
|
54 |
|
|
55 |
text {* Define a function @{term "nodups xs"} that is true iff
|
|
56 |
@{term xs} does not contain duplicates, and a function @{term "deldups
|
|
57 |
xs"} that removes all duplicates. Note that @{term "deldups[x,y,x]"}
|
|
58 |
(where @{term x} and @{term y} are distinct) can be either
|
|
59 |
@{term "[x,y]"} or @{term "[y,x]"}.
|
|
60 |
|
|
61 |
Prove or disprove (by counter example) the following theorems.
|
|
62 |
*}
|
|
63 |
lemma "length (deldups xs) <= length xs"
|
|
64 |
(*<*)oops(*>*)
|
|
65 |
|
|
66 |
lemma "nodups (deldups xs)"
|
|
67 |
(*<*)oops(*>*)
|
|
68 |
|
|
69 |
lemma "deldups (rev xs) = rev (deldups xs)"
|
|
70 |
(*<*)oops(*>*)
|
|
71 |
|
|
72 |
(*<*)
|
|
73 |
end
|
|
74 |
(*>*) |