248 primrec loose where |
248 primrec loose where |
249 "loose (Var j) k = (j \<ge> k)" | |
249 "loose (Var j) k = (j \<ge> k)" | |
250 "loose (Lam t) k = loose t (Suc k)" | |
250 "loose (Lam t) k = loose t (Suc k)" | |
251 "loose (App t u) k = (loose t k \<or> loose u k)" |
251 "loose (App t u) k = (loose t k \<or> loose u k)" |
252 |
252 |
253 primrec subst\<^isub>1 where |
253 primrec subst\<^sub>1 where |
254 "subst\<^isub>1 \<sigma> (Var j) = \<sigma> j" | |
254 "subst\<^sub>1 \<sigma> (Var j) = \<sigma> j" | |
255 "subst\<^isub>1 \<sigma> (Lam t) = |
255 "subst\<^sub>1 \<sigma> (Lam t) = |
256 Lam (subst\<^isub>1 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 1) t)" | |
256 Lam (subst\<^sub>1 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 1) t)" | |
257 "subst\<^isub>1 \<sigma> (App t u) = App (subst\<^isub>1 \<sigma> t) (subst\<^isub>1 \<sigma> u)" |
257 "subst\<^sub>1 \<sigma> (App t u) = App (subst\<^sub>1 \<sigma> t) (subst\<^sub>1 \<sigma> u)" |
258 |
258 |
259 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>1 \<sigma> t = t" |
259 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^sub>1 \<sigma> t = t" |
260 nitpick [verbose, expect = genuine] |
260 nitpick [verbose, expect = genuine] |
261 nitpick [eval = "subst\<^isub>1 \<sigma> t", expect = genuine] |
261 nitpick [eval = "subst\<^sub>1 \<sigma> t", expect = genuine] |
262 (* nitpick [dont_box, expect = unknown] *) |
262 (* nitpick [dont_box, expect = unknown] *) |
263 oops |
263 oops |
264 |
264 |
265 primrec subst\<^isub>2 where |
265 primrec subst\<^sub>2 where |
266 "subst\<^isub>2 \<sigma> (Var j) = \<sigma> j" | |
266 "subst\<^sub>2 \<sigma> (Var j) = \<sigma> j" | |
267 "subst\<^isub>2 \<sigma> (Lam t) = |
267 "subst\<^sub>2 \<sigma> (Lam t) = |
268 Lam (subst\<^isub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" | |
268 Lam (subst\<^sub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" | |
269 "subst\<^isub>2 \<sigma> (App t u) = App (subst\<^isub>2 \<sigma> t) (subst\<^isub>2 \<sigma> u)" |
269 "subst\<^sub>2 \<sigma> (App t u) = App (subst\<^sub>2 \<sigma> t) (subst\<^sub>2 \<sigma> u)" |
270 |
270 |
271 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>2 \<sigma> t = t" |
271 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^sub>2 \<sigma> t = t" |
272 nitpick [card = 1\<emdash>5, expect = none] |
272 nitpick [card = 1\<emdash>5, expect = none] |
273 sorry |
273 sorry |
274 |
274 |
275 subsection {* 2.11. Scope Monotonicity *} |
275 subsection {* 2.11. Scope Monotonicity *} |
276 |
276 |
352 |
352 |
353 subsection {* 3.1. A Context-Free Grammar *} |
353 subsection {* 3.1. A Context-Free Grammar *} |
354 |
354 |
355 datatype alphabet = a | b |
355 datatype alphabet = a | b |
356 |
356 |
357 inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where |
357 inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where |
358 "[] \<in> S\<^isub>1" |
358 "[] \<in> S\<^sub>1" |
359 | "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1" |
359 | "w \<in> A\<^sub>1 \<Longrightarrow> b # w \<in> S\<^sub>1" |
360 | "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1" |
360 | "w \<in> B\<^sub>1 \<Longrightarrow> a # w \<in> S\<^sub>1" |
361 | "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1" |
361 | "w \<in> S\<^sub>1 \<Longrightarrow> a # w \<in> A\<^sub>1" |
362 | "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1" |
362 | "w \<in> S\<^sub>1 \<Longrightarrow> b # w \<in> S\<^sub>1" |
363 | "\<lbrakk>v \<in> B\<^isub>1; v \<in> B\<^isub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>1" |
363 | "\<lbrakk>v \<in> B\<^sub>1; v \<in> B\<^sub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>1" |
364 |
364 |
365 theorem S\<^isub>1_sound: |
365 theorem S\<^sub>1_sound: |
366 "w \<in> S\<^isub>1 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
366 "w \<in> S\<^sub>1 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
367 nitpick [expect = genuine] |
367 nitpick [expect = genuine] |
368 oops |
368 oops |
369 |
369 |
370 inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where |
370 inductive_set S\<^sub>2 and A\<^sub>2 and B\<^sub>2 where |
371 "[] \<in> S\<^isub>2" |
371 "[] \<in> S\<^sub>2" |
372 | "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2" |
372 | "w \<in> A\<^sub>2 \<Longrightarrow> b # w \<in> S\<^sub>2" |
373 | "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2" |
373 | "w \<in> B\<^sub>2 \<Longrightarrow> a # w \<in> S\<^sub>2" |
374 | "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2" |
374 | "w \<in> S\<^sub>2 \<Longrightarrow> a # w \<in> A\<^sub>2" |
375 | "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2" |
375 | "w \<in> S\<^sub>2 \<Longrightarrow> b # w \<in> B\<^sub>2" |
376 | "\<lbrakk>v \<in> B\<^isub>2; v \<in> B\<^isub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>2" |
376 | "\<lbrakk>v \<in> B\<^sub>2; v \<in> B\<^sub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>2" |
377 |
377 |
378 theorem S\<^isub>2_sound: |
378 theorem S\<^sub>2_sound: |
379 "w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
379 "w \<in> S\<^sub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
380 nitpick [expect = genuine] |
380 nitpick [expect = genuine] |
381 oops |
381 oops |
382 |
382 |
383 inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where |
383 inductive_set S\<^sub>3 and A\<^sub>3 and B\<^sub>3 where |
384 "[] \<in> S\<^isub>3" |
384 "[] \<in> S\<^sub>3" |
385 | "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3" |
385 | "w \<in> A\<^sub>3 \<Longrightarrow> b # w \<in> S\<^sub>3" |
386 | "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3" |
386 | "w \<in> B\<^sub>3 \<Longrightarrow> a # w \<in> S\<^sub>3" |
387 | "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3" |
387 | "w \<in> S\<^sub>3 \<Longrightarrow> a # w \<in> A\<^sub>3" |
388 | "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3" |
388 | "w \<in> S\<^sub>3 \<Longrightarrow> b # w \<in> B\<^sub>3" |
389 | "\<lbrakk>v \<in> B\<^isub>3; w \<in> B\<^isub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>3" |
389 | "\<lbrakk>v \<in> B\<^sub>3; w \<in> B\<^sub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>3" |
390 |
390 |
391 theorem S\<^isub>3_sound: |
391 theorem S\<^sub>3_sound: |
392 "w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
392 "w \<in> S\<^sub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
393 nitpick [card = 1\<emdash>5, expect = none] |
393 nitpick [card = 1\<emdash>5, expect = none] |
394 sorry |
394 sorry |
395 |
395 |
396 theorem S\<^isub>3_complete: |
396 theorem S\<^sub>3_complete: |
397 "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>3" |
397 "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^sub>3" |
398 nitpick [expect = genuine] |
398 nitpick [expect = genuine] |
399 oops |
399 oops |
400 |
400 |
401 inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where |
401 inductive_set S\<^sub>4 and A\<^sub>4 and B\<^sub>4 where |
402 "[] \<in> S\<^isub>4" |
402 "[] \<in> S\<^sub>4" |
403 | "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4" |
403 | "w \<in> A\<^sub>4 \<Longrightarrow> b # w \<in> S\<^sub>4" |
404 | "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4" |
404 | "w \<in> B\<^sub>4 \<Longrightarrow> a # w \<in> S\<^sub>4" |
405 | "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4" |
405 | "w \<in> S\<^sub>4 \<Longrightarrow> a # w \<in> A\<^sub>4" |
406 | "\<lbrakk>v \<in> A\<^isub>4; w \<in> A\<^isub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^isub>4" |
406 | "\<lbrakk>v \<in> A\<^sub>4; w \<in> A\<^sub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^sub>4" |
407 | "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4" |
407 | "w \<in> S\<^sub>4 \<Longrightarrow> b # w \<in> B\<^sub>4" |
408 | "\<lbrakk>v \<in> B\<^isub>4; w \<in> B\<^isub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>4" |
408 | "\<lbrakk>v \<in> B\<^sub>4; w \<in> B\<^sub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>4" |
409 |
409 |
410 theorem S\<^isub>4_sound: |
410 theorem S\<^sub>4_sound: |
411 "w \<in> S\<^isub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
411 "w \<in> S\<^sub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
412 nitpick [card = 1\<emdash>5, expect = none] |
412 nitpick [card = 1\<emdash>5, expect = none] |
413 sorry |
413 sorry |
414 |
414 |
415 theorem S\<^isub>4_complete: |
415 theorem S\<^sub>4_complete: |
416 "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>4" |
416 "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^sub>4" |
417 nitpick [card = 1\<emdash>5, expect = none] |
417 nitpick [card = 1\<emdash>5, expect = none] |
418 sorry |
418 sorry |
419 |
419 |
420 theorem S\<^isub>4_A\<^isub>4_B\<^isub>4_sound_and_complete: |
420 theorem S\<^sub>4_A\<^sub>4_B\<^sub>4_sound_and_complete: |
421 "w \<in> S\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
421 "w \<in> S\<^sub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
422 "w \<in> A\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] + 1" |
422 "w \<in> A\<^sub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] + 1" |
423 "w \<in> B\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = b] = length [x \<leftarrow> w. x = a] + 1" |
423 "w \<in> B\<^sub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = b] = length [x \<leftarrow> w. x = a] + 1" |
424 nitpick [card = 1\<emdash>5, expect = none] |
424 nitpick [card = 1\<emdash>5, expect = none] |
425 sorry |
425 sorry |
426 |
426 |
427 subsection {* 3.2. AA Trees *} |
427 subsection {* 3.2. AA Trees *} |
428 |
428 |
482 "wf t \<Longrightarrow> skew t = t" |
482 "wf t \<Longrightarrow> skew t = t" |
483 "wf t \<Longrightarrow> split t = t" |
483 "wf t \<Longrightarrow> split t = t" |
484 nitpick [card = 1\<emdash>5, expect = none] |
484 nitpick [card = 1\<emdash>5, expect = none] |
485 sorry |
485 sorry |
486 |
486 |
487 primrec insort\<^isub>1 where |
487 primrec insort\<^sub>1 where |
488 "insort\<^isub>1 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | |
488 "insort\<^sub>1 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | |
489 "insort\<^isub>1 (N y k t u) x = |
489 "insort\<^sub>1 (N y k t u) x = |
490 (* (split \<circ> skew) *) (N y k (if x < y then insort\<^isub>1 t x else t) |
490 (* (split \<circ> skew) *) (N y k (if x < y then insort\<^sub>1 t x else t) |
491 (if x > y then insort\<^isub>1 u x else u))" |
491 (if x > y then insort\<^sub>1 u x else u))" |
492 |
492 |
493 theorem wf_insort\<^isub>1: "wf t \<Longrightarrow> wf (insort\<^isub>1 t x)" |
493 theorem wf_insort\<^sub>1: "wf t \<Longrightarrow> wf (insort\<^sub>1 t x)" |
494 nitpick [expect = genuine] |
494 nitpick [expect = genuine] |
495 oops |
495 oops |
496 |
496 |
497 theorem wf_insort\<^isub>1_nat: "wf t \<Longrightarrow> wf (insort\<^isub>1 t (x\<Colon>nat))" |
497 theorem wf_insort\<^sub>1_nat: "wf t \<Longrightarrow> wf (insort\<^sub>1 t (x\<Colon>nat))" |
498 nitpick [eval = "insort\<^isub>1 t x", expect = genuine] |
498 nitpick [eval = "insort\<^sub>1 t x", expect = genuine] |
499 oops |
499 oops |
500 |
500 |
501 primrec insort\<^isub>2 where |
501 primrec insort\<^sub>2 where |
502 "insort\<^isub>2 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | |
502 "insort\<^sub>2 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | |
503 "insort\<^isub>2 (N y k t u) x = |
503 "insort\<^sub>2 (N y k t u) x = |
504 (split \<circ> skew) (N y k (if x < y then insort\<^isub>2 t x else t) |
504 (split \<circ> skew) (N y k (if x < y then insort\<^sub>2 t x else t) |
505 (if x > y then insort\<^isub>2 u x else u))" |
505 (if x > y then insort\<^sub>2 u x else u))" |
506 |
506 |
507 theorem wf_insort\<^isub>2: "wf t \<Longrightarrow> wf (insort\<^isub>2 t x)" |
507 theorem wf_insort\<^sub>2: "wf t \<Longrightarrow> wf (insort\<^sub>2 t x)" |
508 nitpick [card = 1\<emdash>5, expect = none] |
508 nitpick [card = 1\<emdash>5, expect = none] |
509 sorry |
509 sorry |
510 |
510 |
511 theorem dataset_insort\<^isub>2: "dataset (insort\<^isub>2 t x) = {x} \<union> dataset t" |
511 theorem dataset_insort\<^sub>2: "dataset (insort\<^sub>2 t x) = {x} \<union> dataset t" |
512 nitpick [card = 1\<emdash>5, expect = none] |
512 nitpick [card = 1\<emdash>5, expect = none] |
513 sorry |
513 sorry |
514 |
514 |
515 end |
515 end |