author | zhangx |
Tue, 15 Dec 2015 21:45:46 +0800 | |
changeset 58 | ad57323fd4d6 |
parent 1 | c4783e4ef43f |
permissions | -rw-r--r-- |
1
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
theory Lsp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports Main |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
fun lsp :: "('a \<Rightarrow> ('b::linorder)) \<Rightarrow> 'a list \<Rightarrow> ('a list \<times> 'a list \<times> 'a list)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
where |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
"lsp f [] = ([], [], [])" | |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
"lsp f [x] = ([], [x], [])" | |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
"lsp f (x#xs) = (case (lsp f xs) of |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
(l, [], r) \<Rightarrow> ([], [x], []) | |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
(l, y#ys, r) \<Rightarrow> if f x \<ge> f y then ([], [x], xs) else (x#l, y#ys, r))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
inductive lsp_p :: "('a \<Rightarrow> ('b::linorder)) \<Rightarrow> 'a list \<Rightarrow> ('a list \<times> 'a list \<times> 'a list) \<Rightarrow> bool" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
for f :: "('a \<Rightarrow> ('b::linorder))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
where |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
lsp_nil [intro]: "lsp_p f [] ([], [], [])" | |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
lsp_single [intro]: "lsp_p f [x] ([], [x], [])" | |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
lsp_cons_1 [intro]: "\<lbrakk>xs \<noteq> []; lsp_p f xs (l, [m], r); f x \<ge> f m\<rbrakk> \<Longrightarrow> lsp_p f (x#xs) ([], [x], xs)" | |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
lsp_cons_2 [intro]: "\<lbrakk>xs \<noteq> []; lsp_p f xs (l, [m], r); f x < f m\<rbrakk> \<Longrightarrow> lsp_p f (x#xs) (x#l, [m], r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
lemma lsp_p_lsp_1: "lsp_p f x y \<Longrightarrow> y = lsp f x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
proof (induct rule:lsp_p.induct) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
case (lsp_cons_1 xs l m r x) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
assume lsp_xs [symmetric]: "(l, [m], r) = lsp f xs" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
25 |
and le_mx: "f m \<le> f x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
26 |
show ?case (is "?L = ?R") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
27 |
proof(cases xs, simp) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
28 |
case (Cons v vs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
apply (simp add:Cons) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
apply (fold Cons) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
by (simp add:lsp_xs le_mx) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
33 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
case (lsp_cons_2 xs l m r x) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
36 |
assume lsp_xs [symmetric]: "(l, [m], r) = lsp f xs" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
and lt_xm: "f x < f m" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
show ?case (is "?L = ?R") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
39 |
proof(cases xs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
40 |
case (Cons v vs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
42 |
apply (simp add:Cons) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
apply (fold Cons) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
44 |
apply (simp add:lsp_xs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
45 |
by (insert lt_xm, auto) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
46 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
case Nil |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
48 |
from prems show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
49 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
qed auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
51 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
52 |
lemma lsp_mid_nil: "lsp f xs = (a, [], c) \<Longrightarrow> xs = []" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
53 |
apply (induct xs arbitrary:a c, auto) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
54 |
apply (case_tac xs, auto) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
55 |
by (case_tac "(lsp f (ab # list))", auto split:if_splits list.splits) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
56 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
58 |
lemma lsp_mid_length: "lsp f x = (u, v, w) \<Longrightarrow> length v \<le> 1" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
59 |
proof(induct x arbitrary:u v w, simp) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
60 |
case (Cons x xs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
61 |
assume ih: "\<And> u v w. lsp f xs = (u, v, w) \<Longrightarrow> length v \<le> 1" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
62 |
and h: "lsp f (x # xs) = (u, v, w)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
63 |
show "length v \<le> 1" using h |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
64 |
proof(cases xs, simp add:h) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
65 |
case (Cons z zs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
assume eq_xs: "xs = z # zs" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
proof(cases "lsp f xs") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
69 |
fix l m r |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
assume eq_lsp: "lsp f xs = (l, m, r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
71 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
72 |
proof(cases m) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
case Nil |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
74 |
from Nil and eq_lsp have "lsp f xs = (l, [], r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
from lsp_mid_nil [OF this] have "xs = []" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
with h show ?thesis by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
78 |
case (Cons y ys) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
assume eq_m: "m = y # ys" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
80 |
from ih [OF eq_lsp] have eq_xs_1: "length m \<le> 1" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
82 |
proof(cases "f x \<ge> f y") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
case True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
from eq_xs eq_xs_1 True h eq_lsp show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
85 |
by (auto split:list.splits if_splits) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
86 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
87 |
case False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
88 |
from eq_xs eq_xs_1 False h eq_lsp show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
89 |
by (auto split:list.splits if_splits) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
92 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
93 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
94 |
assume "[] = u \<and> [x] = v \<and> [] = w" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
95 |
hence "v = [x]" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
thus "length v \<le> Suc 0" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
99 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
100 |
lemma lsp_p_lsp_2: "lsp_p f x (lsp f x)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
101 |
proof(induct x, auto) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
102 |
case (Cons x xs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
assume ih: "lsp_p f xs (lsp f xs)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
show ?case |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
proof(cases xs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
106 |
case Nil |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
107 |
thus ?thesis by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
108 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
case (Cons v vs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
111 |
proof(cases "xs") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
112 |
case Nil |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
113 |
thus ?thesis by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
114 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
case (Cons v vs) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
116 |
assume eq_xs: "xs = v # vs" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
proof(cases "lsp f xs") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
119 |
fix l m r |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
120 |
assume eq_lsp_xs: "lsp f xs = (l, m, r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
121 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
proof(cases m) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
case Nil |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
from eq_lsp_xs and Nil have "lsp f xs = (l, [], r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
from lsp_mid_nil [OF this] have eq_xs: "xs = []" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
hence "lsp f (x#xs) = ([], [x], [])" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
with eq_xs show ?thesis by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
case (Cons y ys) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
130 |
assume eq_m: "m = y # ys" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
131 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
132 |
proof(cases "f x \<ge> f y") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
133 |
case True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
from eq_xs eq_lsp_xs Cons True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
have eq_lsp: "lsp f (x#xs) = ([], [x], v # vs)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
proof (simp add:eq_lsp) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
138 |
show "lsp_p f (x # xs) ([], [x], v # vs)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
139 |
proof(fold eq_xs, rule lsp_cons_1 [OF _]) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
140 |
from eq_xs show "xs \<noteq> []" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
from lsp_mid_length [OF eq_lsp_xs] and Cons |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
have "m = [y]" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
with eq_lsp_xs have "lsp f xs = (l, [y], r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
with ih show "lsp_p f xs (l, [y], r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
146 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
from True show "f y \<le> f x" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
148 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
150 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
151 |
case False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
152 |
from eq_xs eq_lsp_xs Cons False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
153 |
have eq_lsp: "lsp f (x#xs) = (x # l, y # ys, r) " by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
155 |
proof (simp add:eq_lsp) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
156 |
from lsp_mid_length [OF eq_lsp_xs] and eq_m |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
157 |
have "ys = []" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
moreover have "lsp_p f (x # xs) (x # l, [y], r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
proof(rule lsp_cons_2) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
160 |
from eq_xs show "xs \<noteq> []" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
162 |
from lsp_mid_length [OF eq_lsp_xs] and Cons |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
have "m = [y]" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
with eq_lsp_xs have "lsp f xs = (l, [y], r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
165 |
with ih show "lsp_p f xs (l, [y], r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
from False show "f x < f y" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
168 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
ultimately show "lsp_p f (x # xs) (x # l, y # ys, r)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
170 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
171 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
172 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
173 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
176 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
lemma lsp_induct: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
179 |
fixes f x1 x2 P |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
assumes h: "lsp f x1 = x2" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
and p1: "P [] ([], [], [])" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
182 |
and p2: "\<And>x. P [x] ([], [x], [])" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
and p3: "\<And>xs l m r x. \<lbrakk>xs \<noteq> []; lsp f xs = (l, [m], r); P xs (l, [m], r); f m \<le> f x\<rbrakk> \<Longrightarrow> P (x # xs) ([], [x], xs)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
and p4: "\<And>xs l m r x. \<lbrakk>xs \<noteq> []; lsp f xs = (l, [m], r); P xs (l, [m], r); f x < f m\<rbrakk> \<Longrightarrow> P (x # xs) (x # l, [m], r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
shows "P x1 x2" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
186 |
proof(rule lsp_p.induct) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
from lsp_p_lsp_2 and h |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
show "lsp_p f x1 x2" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
189 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
190 |
from p1 show "P [] ([], [], [])" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
191 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
from p2 show "\<And>x. P [x] ([], [x], [])" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
193 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
fix xs l m r x |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
assume h1: "xs \<noteq> []" and h2: "lsp_p f xs (l, [m], r)" and h3: "P xs (l, [m], r)" and h4: "f m \<le> f x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
show "P (x # xs) ([], [x], xs)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
proof(rule p3 [OF h1 _ h3 h4]) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
from h2 and lsp_p_lsp_1 show "lsp f xs = (l, [m], r)" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
200 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
201 |
fix xs l m r x |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
assume h1: "xs \<noteq> []" and h2: "lsp_p f xs (l, [m], r)" and h3: "P xs (l, [m], r)" and h4: "f x < f m" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
show "P (x # xs) (x # l, [m], r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
proof(rule p4 [OF h1 _ h3 h4]) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
205 |
from h2 and lsp_p_lsp_1 show "lsp f xs = (l, [m], r)" by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
lemma lsp_set_eq: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
210 |
fixes f x u v w |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
assumes h: "lsp f x = (u, v, w)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
212 |
shows "x = u@v@w" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
have "\<And> f x r. lsp f x = r \<Longrightarrow> \<forall> u v w. (r = (u, v, w) \<longrightarrow> x = u@v@w)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
by (erule lsp_induct, simp+) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
216 |
from this [rule_format, OF h] show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
217 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
lemma lsp_set: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
assumes h: "(u, v, w) = lsp f x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
shows "set (u@v@w) = set x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
from lsp_set_eq [OF h[symmetric]] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
225 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
227 |
lemma max_insert_gt: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
fixes S fx |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
assumes h: "fx < Max S" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
230 |
and np: "S \<noteq> {}" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
and fn: "finite S" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
232 |
shows "Max S = Max (insert fx S)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
from Max_insert [OF fn np] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
have "Max (insert fx S) = max fx (Max S)" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
236 |
moreover have "\<dots> = Max S" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
237 |
proof(cases "fx \<le> Max S") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
case False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
239 |
with h |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
show ?thesis by (simp add:max_def) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
242 |
case True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
thus ?thesis by (simp add:max_def) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
245 |
ultimately show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
246 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
248 |
lemma max_insert_le: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
249 |
fixes S fx |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
250 |
assumes h: "Max S \<le> fx" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
and fn: "finite S" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
shows "fx = Max (insert fx S)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
253 |
proof(cases "S = {}") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
case True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
thus ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
256 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
257 |
case False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
258 |
from Max_insert [OF fn False] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
259 |
have "Max (insert fx S) = max fx (Max S)" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
moreover have "\<dots> = fx" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
proof(cases "fx \<le> Max S") |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
262 |
case False |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
263 |
thus ?thesis by (simp add:max_def) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
264 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
265 |
case True |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
have hh: "\<And> x y. \<lbrakk> x \<le> (y::('a::linorder)); y \<le> x\<rbrakk> \<Longrightarrow> x = y" by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
267 |
from hh [OF True h] |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
268 |
have "fx = Max S" . |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
thus ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
270 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
271 |
ultimately show ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
272 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
273 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
lemma lsp_max: |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
275 |
fixes f x u m w |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
276 |
assumes h: "lsp f x = (u, [m], w)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
shows "f m = Max (f ` (set x))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
278 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
279 |
{ fix y |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
280 |
have "lsp f x = y \<Longrightarrow> \<forall> u m w. y = (u, [m], w) \<longrightarrow> f m = Max (f ` (set x))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
281 |
proof(erule lsp_induct, simp) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
282 |
{ fix x u m w |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
assume "(([]::'a list), ([x]::'a list), ([]::'a list)) = (u, [m], w)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
284 |
hence "f m = Max (f ` set [x])" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
285 |
} thus "\<And>x. \<forall>u m w. ([], [x], []) = (u, [m], w) \<longrightarrow> f m = Max (f ` set [x])" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
286 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
287 |
fix xs l m r x |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
288 |
assume h1: "xs \<noteq> []" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
289 |
and h2: " lsp f xs = (l, [m], r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
290 |
and h3: "\<forall>u ma w. (l, [m], r) = (u, [ma], w) \<longrightarrow> f ma = Max (f ` set xs)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
291 |
and h4: "f m \<le> f x" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
292 |
show " \<forall>u m w. ([], [x], xs) = (u, [m], w) \<longrightarrow> f m = Max (f ` set (x # xs))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
294 |
have "f x = Max (f ` set (x # xs))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
295 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
296 |
from h2 h3 have "f m = Max (f ` set xs)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
297 |
with h4 show ?thesis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
298 |
apply auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
299 |
by (rule_tac max_insert_le, auto) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
300 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
301 |
thus ?thesis by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
302 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
303 |
next |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
304 |
fix xs l m r x |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
305 |
assume h1: "xs \<noteq> []" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
306 |
and h2: " lsp f xs = (l, [m], r)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
307 |
and h3: " \<forall>u ma w. (l, [m], r) = (u, [ma], w) \<longrightarrow> f ma = Max (f ` set xs)" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
308 |
and h4: "f x < f m" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
309 |
show "\<forall>u ma w. (x # l, [m], r) = (u, [ma], w) \<longrightarrow> f ma = Max (f ` set (x # xs))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
310 |
proof - |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
from h2 h3 have "f m = Max (f ` set xs)" by simp |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
312 |
with h4 |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
313 |
have "f m = Max (f ` set (x # xs))" |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
314 |
apply auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
apply (rule_tac max_insert_gt, simp+) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
316 |
by (insert h1, simp+) |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
thus ?thesis by auto |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
318 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
320 |
} with h show ?thesis by metis |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
321 |
qed |
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
322 |
|
c4783e4ef43f
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
323 |
end |