author | wenzelm |
Wed, 25 Jun 2025 16:35:25 +0200 | |
changeset 82768 | 8f866fd6fae1 |
parent 76987 | 4c275405faae |
permissions | -rw-r--r-- |
39157
b98909faaea8
more explicit HOL-Proofs sessions, including former ex/Hilbert_Classical.thy which works in parallel mode without the antiquotation option "margin" (which is still critical);
wenzelm
parents:
37934
diff
changeset
|
1 |
(* Title: HOL/Proofs/Extraction/Higman.thy |
13405 | 2 |
Author: Stefan Berghofer, TU Muenchen |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
3 |
Author: Monika Seisenberger, LMU Muenchen |
13405 | 4 |
*) |
5 |
||
61986 | 6 |
section \<open>Higman's lemma\<close> |
13405 | 7 |
|
24221 | 8 |
theory Higman |
66258 | 9 |
imports Main |
24221 | 10 |
begin |
13405 | 11 |
|
61986 | 12 |
text \<open> |
13405 | 13 |
Formalization by Stefan Berghofer and Monika Seisenberger, |
76987 | 14 |
based on Coquand and Fridlender \<^cite>\<open>Coquand93\<close>. |
61986 | 15 |
\<close> |
13405 | 16 |
|
58310 | 17 |
datatype letter = A | B |
58272 | 18 |
|
23747 | 19 |
inductive emb :: "letter list \<Rightarrow> letter list \<Rightarrow> bool" |
22266 | 20 |
where |
63361 | 21 |
emb0 [Pure.intro]: "emb [] bs" |
22 |
| emb1 [Pure.intro]: "emb as bs \<Longrightarrow> emb as (b # bs)" |
|
23 |
| emb2 [Pure.intro]: "emb as bs \<Longrightarrow> emb (a # as) (a # bs)" |
|
13405 | 24 |
|
23747 | 25 |
inductive L :: "letter list \<Rightarrow> letter list list \<Rightarrow> bool" |
22266 | 26 |
for v :: "letter list" |
27 |
where |
|
63361 | 28 |
L0 [Pure.intro]: "emb w v \<Longrightarrow> L v (w # ws)" |
29 |
| L1 [Pure.intro]: "L v ws \<Longrightarrow> L v (w # ws)" |
|
13405 | 30 |
|
23747 | 31 |
inductive good :: "letter list list \<Rightarrow> bool" |
22266 | 32 |
where |
63361 | 33 |
good0 [Pure.intro]: "L w ws \<Longrightarrow> good (w # ws)" |
34 |
| good1 [Pure.intro]: "good ws \<Longrightarrow> good (w # ws)" |
|
13405 | 35 |
|
23747 | 36 |
inductive R :: "letter \<Rightarrow> letter list list \<Rightarrow> letter list list \<Rightarrow> bool" |
22266 | 37 |
for a :: letter |
38 |
where |
|
63361 | 39 |
R0 [Pure.intro]: "R a [] []" |
40 |
| R1 [Pure.intro]: "R a vs ws \<Longrightarrow> R a (w # vs) ((a # w) # ws)" |
|
13405 | 41 |
|
23747 | 42 |
inductive T :: "letter \<Rightarrow> letter list list \<Rightarrow> letter list list \<Rightarrow> bool" |
22266 | 43 |
for a :: letter |
44 |
where |
|
63361 | 45 |
T0 [Pure.intro]: "a \<noteq> b \<Longrightarrow> R b ws zs \<Longrightarrow> T a (w # zs) ((a # w) # zs)" |
46 |
| T1 [Pure.intro]: "T a ws zs \<Longrightarrow> T a (w # ws) ((a # w) # zs)" |
|
47 |
| T2 [Pure.intro]: "a \<noteq> b \<Longrightarrow> T a ws zs \<Longrightarrow> T a ws ((b # w) # zs)" |
|
13405 | 48 |
|
23747 | 49 |
inductive bar :: "letter list list \<Rightarrow> bool" |
22266 | 50 |
where |
63361 | 51 |
bar1 [Pure.intro]: "good ws \<Longrightarrow> bar ws" |
52 |
| bar2 [Pure.intro]: "(\<And>w. bar (w # ws)) \<Longrightarrow> bar ws" |
|
13405 | 53 |
|
63361 | 54 |
theorem prop1: "bar ([] # ws)" |
55 |
by iprover |
|
13405 | 56 |
|
22266 | 57 |
theorem lemma1: "L as ws \<Longrightarrow> L (a # as) ws" |
63361 | 58 |
by (erule L.induct) iprover+ |
13405 | 59 |
|
22266 | 60 |
lemma lemma2': "R a vs ws \<Longrightarrow> L as vs \<Longrightarrow> L (a # as) ws" |
71989
bad75618fb82
extraction of equations x = t from premises beneath meta-all
haftmann
parents:
66258
diff
changeset
|
61 |
supply [[simproc del: defined_all]] |
13969 | 62 |
apply (induct set: R) |
22266 | 63 |
apply (erule L.cases) |
13405 | 64 |
apply simp+ |
22266 | 65 |
apply (erule L.cases) |
13405 | 66 |
apply simp_all |
67 |
apply (rule L0) |
|
68 |
apply (erule emb2) |
|
69 |
apply (erule L1) |
|
70 |
done |
|
13969 | 71 |
|
22266 | 72 |
lemma lemma2: "R a vs ws \<Longrightarrow> good vs \<Longrightarrow> good ws" |
71989
bad75618fb82
extraction of equations x = t from premises beneath meta-all
haftmann
parents:
66258
diff
changeset
|
73 |
supply [[simproc del: defined_all]] |
13969 | 74 |
apply (induct set: R) |
17604 | 75 |
apply iprover |
22266 | 76 |
apply (erule good.cases) |
13405 | 77 |
apply simp_all |
78 |
apply (rule good0) |
|
79 |
apply (erule lemma2') |
|
71989
bad75618fb82
extraction of equations x = t from premises beneath meta-all
haftmann
parents:
66258
diff
changeset
|
80 |
apply assumption |
13405 | 81 |
apply (erule good1) |
82 |
done |
|
83 |
||
22266 | 84 |
lemma lemma3': "T a vs ws \<Longrightarrow> L as vs \<Longrightarrow> L (a # as) ws" |
71989
bad75618fb82
extraction of equations x = t from premises beneath meta-all
haftmann
parents:
66258
diff
changeset
|
85 |
supply [[simproc del: defined_all]] |
13969 | 86 |
apply (induct set: T) |
22266 | 87 |
apply (erule L.cases) |
13405 | 88 |
apply simp_all |
89 |
apply (rule L0) |
|
90 |
apply (erule emb2) |
|
91 |
apply (rule L1) |
|
92 |
apply (erule lemma1) |
|
22266 | 93 |
apply (erule L.cases) |
13405 | 94 |
apply simp_all |
17604 | 95 |
apply iprover+ |
13405 | 96 |
done |
97 |
||
22266 | 98 |
lemma lemma3: "T a ws zs \<Longrightarrow> good ws \<Longrightarrow> good zs" |
71989
bad75618fb82
extraction of equations x = t from premises beneath meta-all
haftmann
parents:
66258
diff
changeset
|
99 |
supply [[simproc del: defined_all]] |
13969 | 100 |
apply (induct set: T) |
22266 | 101 |
apply (erule good.cases) |
13405 | 102 |
apply simp_all |
103 |
apply (rule good0) |
|
104 |
apply (erule lemma1) |
|
105 |
apply (erule good1) |
|
22266 | 106 |
apply (erule good.cases) |
13405 | 107 |
apply simp_all |
108 |
apply (rule good0) |
|
109 |
apply (erule lemma3') |
|
17604 | 110 |
apply iprover+ |
13405 | 111 |
done |
112 |
||
22266 | 113 |
lemma lemma4: "R a ws zs \<Longrightarrow> ws \<noteq> [] \<Longrightarrow> T a ws zs" |
71989
bad75618fb82
extraction of equations x = t from premises beneath meta-all
haftmann
parents:
66258
diff
changeset
|
114 |
supply [[simproc del: defined_all]] |
13969 | 115 |
apply (induct set: R) |
17604 | 116 |
apply iprover |
13405 | 117 |
apply (case_tac vs) |
22266 | 118 |
apply (erule R.cases) |
13405 | 119 |
apply simp |
120 |
apply (case_tac a) |
|
121 |
apply (rule_tac b=B in T0) |
|
122 |
apply simp |
|
123 |
apply (rule R0) |
|
124 |
apply (rule_tac b=A in T0) |
|
125 |
apply simp |
|
126 |
apply (rule R0) |
|
127 |
apply simp |
|
128 |
apply (rule T1) |
|
129 |
apply simp |
|
130 |
done |
|
131 |
||
63361 | 132 |
lemma letter_neq: "a \<noteq> b \<Longrightarrow> c \<noteq> a \<Longrightarrow> c = b" for a b c :: letter |
13930 | 133 |
apply (case_tac a) |
134 |
apply (case_tac b) |
|
135 |
apply (case_tac c, simp, simp) |
|
136 |
apply (case_tac c, simp, simp) |
|
137 |
apply (case_tac b) |
|
138 |
apply (case_tac c, simp, simp) |
|
139 |
apply (case_tac c, simp, simp) |
|
140 |
done |
|
13405 | 141 |
|
63361 | 142 |
lemma letter_eq_dec: "a = b \<or> a \<noteq> b" for a b :: letter |
13405 | 143 |
apply (case_tac a) |
144 |
apply (case_tac b) |
|
145 |
apply simp |
|
146 |
apply simp |
|
147 |
apply (case_tac b) |
|
148 |
apply simp |
|
149 |
apply simp |
|
150 |
done |
|
151 |
||
13930 | 152 |
theorem prop2: |
22266 | 153 |
assumes ab: "a \<noteq> b" and bar: "bar xs" |
63361 | 154 |
shows "\<And>ys zs. bar ys \<Longrightarrow> T a xs zs \<Longrightarrow> T b ys zs \<Longrightarrow> bar zs" |
155 |
using bar |
|
13930 | 156 |
proof induct |
63361 | 157 |
fix xs zs |
158 |
assume "T a xs zs" and "good xs" |
|
159 |
then have "good zs" by (rule lemma3) |
|
23373 | 160 |
then show "bar zs" by (rule bar1) |
13930 | 161 |
next |
162 |
fix xs ys |
|
22266 | 163 |
assume I: "\<And>w ys zs. bar ys \<Longrightarrow> T a (w # xs) zs \<Longrightarrow> T b ys zs \<Longrightarrow> bar zs" |
164 |
assume "bar ys" |
|
63361 | 165 |
then show "\<And>zs. T a xs zs \<Longrightarrow> T b ys zs \<Longrightarrow> bar zs" |
13930 | 166 |
proof induct |
63361 | 167 |
fix ys zs |
168 |
assume "T b ys zs" and "good ys" |
|
23373 | 169 |
then have "good zs" by (rule lemma3) |
170 |
then show "bar zs" by (rule bar1) |
|
13930 | 171 |
next |
63361 | 172 |
fix ys zs |
173 |
assume I': "\<And>w zs. T a xs zs \<Longrightarrow> T b (w # ys) zs \<Longrightarrow> bar zs" |
|
174 |
and ys: "\<And>w. bar (w # ys)" and Ta: "T a xs zs" and Tb: "T b ys zs" |
|
22266 | 175 |
show "bar zs" |
13930 | 176 |
proof (rule bar2) |
177 |
fix w |
|
22266 | 178 |
show "bar (w # zs)" |
13930 | 179 |
proof (cases w) |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
180 |
case Nil |
63361 | 181 |
then show ?thesis by simp (rule prop1) |
13930 | 182 |
next |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
183 |
case (Cons c cs) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
184 |
from letter_eq_dec show ?thesis |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
185 |
proof |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
186 |
assume ca: "c = a" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
187 |
from ab have "bar ((a # cs) # zs)" by (iprover intro: I ys Ta Tb) |
63361 | 188 |
then show ?thesis by (simp add: Cons ca) |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
189 |
next |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
190 |
assume "c \<noteq> a" |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
191 |
with ab have cb: "c = b" by (rule letter_neq) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
192 |
from ab have "bar ((b # cs) # zs)" by (iprover intro: I' Ta Tb) |
63361 | 193 |
then show ?thesis by (simp add: Cons cb) |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
194 |
qed |
13930 | 195 |
qed |
196 |
qed |
|
197 |
qed |
|
198 |
qed |
|
13405 | 199 |
|
13930 | 200 |
theorem prop3: |
22266 | 201 |
assumes bar: "bar xs" |
63361 | 202 |
shows "\<And>zs. xs \<noteq> [] \<Longrightarrow> R a xs zs \<Longrightarrow> bar zs" |
203 |
using bar |
|
13930 | 204 |
proof induct |
205 |
fix xs zs |
|
23373 | 206 |
assume "R a xs zs" and "good xs" |
207 |
then have "good zs" by (rule lemma2) |
|
208 |
then show "bar zs" by (rule bar1) |
|
13930 | 209 |
next |
210 |
fix xs zs |
|
22266 | 211 |
assume I: "\<And>w zs. w # xs \<noteq> [] \<Longrightarrow> R a (w # xs) zs \<Longrightarrow> bar zs" |
63361 | 212 |
and xsb: "\<And>w. bar (w # xs)" and xsn: "xs \<noteq> []" and R: "R a xs zs" |
22266 | 213 |
show "bar zs" |
13930 | 214 |
proof (rule bar2) |
215 |
fix w |
|
22266 | 216 |
show "bar (w # zs)" |
13930 | 217 |
proof (induct w) |
218 |
case Nil |
|
219 |
show ?case by (rule prop1) |
|
220 |
next |
|
221 |
case (Cons c cs) |
|
222 |
from letter_eq_dec show ?case |
|
223 |
proof |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
224 |
assume "c = a" |
63361 | 225 |
then show ?thesis by (iprover intro: I [simplified] R) |
13930 | 226 |
next |
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
227 |
from R xsn have T: "T a xs zs" by (rule lemma4) |
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
31180
diff
changeset
|
228 |
assume "c \<noteq> a" |
63361 | 229 |
then show ?thesis by (iprover intro: prop2 Cons xsb xsn R T) |
13930 | 230 |
qed |
231 |
qed |
|
232 |
qed |
|
233 |
qed |
|
13405 | 234 |
|
22266 | 235 |
theorem higman: "bar []" |
13930 | 236 |
proof (rule bar2) |
237 |
fix w |
|
22266 | 238 |
show "bar [w]" |
13930 | 239 |
proof (induct w) |
22266 | 240 |
show "bar [[]]" by (rule prop1) |
13930 | 241 |
next |
22266 | 242 |
fix c cs assume "bar [cs]" |
63361 | 243 |
then show "bar [c # cs]" by (rule prop3) (simp, iprover) |
13930 | 244 |
qed |
245 |
qed |
|
13405 | 246 |
|
63361 | 247 |
primrec is_prefix :: "'a list \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> bool" |
25976 | 248 |
where |
63361 | 249 |
"is_prefix [] f = True" |
250 |
| "is_prefix (x # xs) f = (x = f (length xs) \<and> is_prefix xs f)" |
|
13405 | 251 |
|
22266 | 252 |
theorem L_idx: |
253 |
assumes L: "L w ws" |
|
63361 | 254 |
shows "is_prefix ws f \<Longrightarrow> \<exists>i. emb (f i) w \<and> i < length ws" |
255 |
using L |
|
22266 | 256 |
proof induct |
257 |
case (L0 v ws) |
|
63361 | 258 |
then have "emb (f (length ws)) w" by simp |
22266 | 259 |
moreover have "length ws < length (v # ws)" by simp |
260 |
ultimately show ?case by iprover |
|
261 |
next |
|
262 |
case (L1 ws v) |
|
263 |
then obtain i where emb: "emb (f i) w" and "i < length ws" |
|
264 |
by simp iprover |
|
63361 | 265 |
then have "i < length (v # ws)" by simp |
22266 | 266 |
with emb show ?case by iprover |
267 |
qed |
|
268 |
||
269 |
theorem good_idx: |
|
270 |
assumes good: "good ws" |
|
63361 | 271 |
shows "is_prefix ws f \<Longrightarrow> \<exists>i j. emb (f i) (f j) \<and> i < j" |
272 |
using good |
|
22266 | 273 |
proof induct |
274 |
case (good0 w ws) |
|
63361 | 275 |
then have "w = f (length ws)" and "is_prefix ws f" by simp_all |
22266 | 276 |
with good0 show ?case by (iprover dest: L_idx) |
277 |
next |
|
278 |
case (good1 ws w) |
|
63361 | 279 |
then show ?case by simp |
22266 | 280 |
qed |
281 |
||
282 |
theorem bar_idx: |
|
283 |
assumes bar: "bar ws" |
|
63361 | 284 |
shows "is_prefix ws f \<Longrightarrow> \<exists>i j. emb (f i) (f j) \<and> i < j" |
285 |
using bar |
|
22266 | 286 |
proof induct |
287 |
case (bar1 ws) |
|
63361 | 288 |
then show ?case by (rule good_idx) |
22266 | 289 |
next |
290 |
case (bar2 ws) |
|
63361 | 291 |
then have "is_prefix (f (length ws) # ws) f" by simp |
292 |
then show ?case by (rule bar2) |
|
22266 | 293 |
qed |
294 |
||
61986 | 295 |
text \<open> |
63361 | 296 |
Strong version: yields indices of words that can be embedded into each other. |
61986 | 297 |
\<close> |
22266 | 298 |
|
299 |
theorem higman_idx: "\<exists>(i::nat) j. emb (f i) (f j) \<and> i < j" |
|
300 |
proof (rule bar_idx) |
|
301 |
show "bar []" by (rule higman) |
|
302 |
show "is_prefix [] f" by simp |
|
303 |
qed |
|
304 |
||
61986 | 305 |
text \<open> |
63361 | 306 |
Weak version: only yield sequence containing words |
307 |
that can be embedded into each other. |
|
61986 | 308 |
\<close> |
22266 | 309 |
|
13405 | 310 |
theorem good_prefix_lemma: |
22266 | 311 |
assumes bar: "bar ws" |
63361 | 312 |
shows "is_prefix ws f \<Longrightarrow> \<exists>vs. is_prefix vs f \<and> good vs" |
313 |
using bar |
|
13930 | 314 |
proof induct |
315 |
case bar1 |
|
63361 | 316 |
then show ?case by iprover |
13930 | 317 |
next |
318 |
case (bar2 ws) |
|
23373 | 319 |
from bar2.prems have "is_prefix (f (length ws) # ws) f" by simp |
63361 | 320 |
then show ?case by (iprover intro: bar2) |
13930 | 321 |
qed |
13405 | 322 |
|
22266 | 323 |
theorem good_prefix: "\<exists>vs. is_prefix vs f \<and> good vs" |
13930 | 324 |
using higman |
325 |
by (rule good_prefix_lemma) simp+ |
|
13405 | 326 |
|
27982 | 327 |
end |