src/HOL/Proofs/Extraction/Higman.thy
author wenzelm
Wed, 25 Jun 2025 16:35:25 +0200
changeset 82768 8f866fd6fae1
parent 76987 4c275405faae
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
     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
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
     4
*)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
     5
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
     6
section \<open>Higman's lemma\<close>
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
     7
24221
dd4a7ea0e64a code generator setup improved
haftmann
parents: 23810
diff changeset
     8
theory Higman
66258
2b83dd24b301 dropped superfluous theory imports
haftmann
parents: 63361
diff changeset
     9
imports Main
24221
dd4a7ea0e64a code generator setup improved
haftmann
parents: 23810
diff changeset
    10
begin
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    11
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
    12
text \<open>
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    13
  Formalization by Stefan Berghofer and Monika Seisenberger,
76987
4c275405faae isabelle update -u cite;
wenzelm
parents: 71989
diff changeset
    14
  based on Coquand and Fridlender \<^cite>\<open>Coquand93\<close>.
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
    15
\<close>
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    16
58310
91ea607a34d8 updated news
blanchet
parents: 58279
diff changeset
    17
datatype letter = A | B
58272
61d94335ef6c ported HOL-Proofs-Extraction to new datatypes
blanchet
parents: 45047
diff changeset
    18
23747
b07cff284683 Renamed inductive2 to inductive.
berghofe
parents: 23373
diff changeset
    19
inductive emb :: "letter list \<Rightarrow> letter list \<Rightarrow> bool"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    20
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    21
  emb0 [Pure.intro]: "emb [] bs"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    22
| emb1 [Pure.intro]: "emb as bs \<Longrightarrow> emb as (b # bs)"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    23
| emb2 [Pure.intro]: "emb as bs \<Longrightarrow> emb (a # as) (a # bs)"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    24
23747
b07cff284683 Renamed inductive2 to inductive.
berghofe
parents: 23373
diff changeset
    25
inductive L :: "letter list \<Rightarrow> letter list list \<Rightarrow> bool"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    26
  for v :: "letter list"
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    27
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    28
  L0 [Pure.intro]: "emb w v \<Longrightarrow> L v (w # ws)"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    29
| L1 [Pure.intro]: "L v ws \<Longrightarrow> L v (w # ws)"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    30
23747
b07cff284683 Renamed inductive2 to inductive.
berghofe
parents: 23373
diff changeset
    31
inductive good :: "letter list list \<Rightarrow> bool"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    32
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    33
  good0 [Pure.intro]: "L w ws \<Longrightarrow> good (w # ws)"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    34
| good1 [Pure.intro]: "good ws \<Longrightarrow> good (w # ws)"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    35
23747
b07cff284683 Renamed inductive2 to inductive.
berghofe
parents: 23373
diff changeset
    36
inductive R :: "letter \<Rightarrow> letter list list \<Rightarrow> letter list list \<Rightarrow> bool"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    37
  for a :: letter
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    38
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    39
  R0 [Pure.intro]: "R a [] []"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    40
| R1 [Pure.intro]: "R a vs ws \<Longrightarrow> R a (w # vs) ((a # w) # ws)"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    41
23747
b07cff284683 Renamed inductive2 to inductive.
berghofe
parents: 23373
diff changeset
    42
inductive T :: "letter \<Rightarrow> letter list list \<Rightarrow> letter list list \<Rightarrow> bool"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    43
  for a :: letter
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    44
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    45
  T0 [Pure.intro]: "a \<noteq> b \<Longrightarrow> R b ws zs \<Longrightarrow> T a (w # zs) ((a # w) # zs)"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    46
| T1 [Pure.intro]: "T a ws zs \<Longrightarrow> T a (w # ws) ((a # w) # zs)"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    47
| T2 [Pure.intro]: "a \<noteq> b \<Longrightarrow> T a ws zs \<Longrightarrow> T a ws ((b # w) # zs)"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    48
23747
b07cff284683 Renamed inductive2 to inductive.
berghofe
parents: 23373
diff changeset
    49
inductive bar :: "letter list list \<Rightarrow> bool"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    50
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    51
  bar1 [Pure.intro]: "good ws \<Longrightarrow> bar ws"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    52
| bar2 [Pure.intro]: "(\<And>w. bar (w # ws)) \<Longrightarrow> bar ws"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    53
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    54
theorem prop1: "bar ([] # ws)"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    55
  by iprover
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    56
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    57
theorem lemma1: "L as ws \<Longrightarrow> L (a # as) ws"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
    58
  by (erule L.induct) iprover+
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    59
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    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
3aa8c0bb3080 Some tuning:
berghofe
parents: 13930
diff changeset
    62
  apply (induct set: R)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    63
  apply (erule L.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    64
  apply simp+
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    65
  apply (erule L.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    66
  apply simp_all
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    67
  apply (rule L0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    68
  apply (erule emb2)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    69
  apply (erule L1)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    70
  done
13969
3aa8c0bb3080 Some tuning:
berghofe
parents: 13930
diff changeset
    71
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    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
3aa8c0bb3080 Some tuning:
berghofe
parents: 13930
diff changeset
    74
  apply (induct set: R)
17604
5f30179fbf44 rules -> iprover
nipkow
parents: 17145
diff changeset
    75
  apply iprover
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    76
  apply (erule good.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    77
  apply simp_all
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    78
  apply (rule good0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    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
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    81
  apply (erule good1)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    82
  done
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    83
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    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
3aa8c0bb3080 Some tuning:
berghofe
parents: 13930
diff changeset
    86
  apply (induct set: T)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    87
  apply (erule L.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    88
  apply simp_all
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    89
  apply (rule L0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    90
  apply (erule emb2)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    91
  apply (rule L1)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    92
  apply (erule lemma1)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    93
  apply (erule L.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    94
  apply simp_all
17604
5f30179fbf44 rules -> iprover
nipkow
parents: 17145
diff changeset
    95
  apply iprover+
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    96
  done
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
    97
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
    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
3aa8c0bb3080 Some tuning:
berghofe
parents: 13930
diff changeset
   100
  apply (induct set: T)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   101
  apply (erule good.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   102
  apply simp_all
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   103
  apply (rule good0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   104
  apply (erule lemma1)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   105
  apply (erule good1)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   106
  apply (erule good.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   107
  apply simp_all
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   108
  apply (rule good0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   109
  apply (erule lemma3')
17604
5f30179fbf44 rules -> iprover
nipkow
parents: 17145
diff changeset
   110
  apply iprover+
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   111
  done
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   112
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   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
3aa8c0bb3080 Some tuning:
berghofe
parents: 13930
diff changeset
   115
  apply (induct set: R)
17604
5f30179fbf44 rules -> iprover
nipkow
parents: 17145
diff changeset
   116
  apply iprover
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   117
  apply (case_tac vs)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   118
  apply (erule R.cases)
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   119
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   120
  apply (case_tac a)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   121
  apply (rule_tac b=B in T0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   122
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   123
  apply (rule R0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   124
  apply (rule_tac b=A in T0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   125
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   126
  apply (rule R0)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   127
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   128
  apply (rule T1)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   129
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   130
  done
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   131
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   132
lemma letter_neq: "a \<noteq> b \<Longrightarrow> c \<noteq> a \<Longrightarrow> c = b" for a b c :: letter
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   133
  apply (case_tac a)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   134
  apply (case_tac b)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   135
  apply (case_tac c, simp, simp)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   136
  apply (case_tac c, simp, simp)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   137
  apply (case_tac b)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   138
  apply (case_tac c, simp, simp)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   139
  apply (case_tac c, simp, simp)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   140
  done
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   141
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   142
lemma letter_eq_dec: "a = b \<or> a \<noteq> b" for a b :: letter
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   143
  apply (case_tac a)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   144
  apply (case_tac b)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   145
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   146
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   147
  apply (case_tac b)
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   148
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   149
  apply simp
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   150
  done
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   151
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   152
theorem prop2:
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   153
  assumes ab: "a \<noteq> b" and bar: "bar xs"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   154
  shows "\<And>ys zs. bar ys \<Longrightarrow> T a xs zs \<Longrightarrow> T b ys zs \<Longrightarrow> bar zs"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   155
  using bar
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   156
proof induct
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   157
  fix xs zs
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   158
  assume "T a xs zs" and "good xs"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   159
  then have "good zs" by (rule lemma3)
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   160
  then show "bar zs" by (rule bar1)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   161
next
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   162
  fix xs ys
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   163
  assume I: "\<And>w ys zs. bar ys \<Longrightarrow> T a (w # xs) zs \<Longrightarrow> T b ys zs \<Longrightarrow> bar zs"
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   164
  assume "bar ys"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   165
  then show "\<And>zs. T a xs zs \<Longrightarrow> T b ys zs \<Longrightarrow> bar zs"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   166
  proof induct
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   167
    fix ys zs
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   168
    assume "T b ys zs" and "good ys"
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   169
    then have "good zs" by (rule lemma3)
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   170
    then show "bar zs" by (rule bar1)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   171
  next
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   172
    fix ys zs
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   173
    assume I': "\<And>w zs. T a xs zs \<Longrightarrow> T b (w # ys) zs \<Longrightarrow> bar zs"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   174
      and ys: "\<And>w. bar (w # ys)" and Ta: "T a xs zs" and Tb: "T b ys zs"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   175
    show "bar zs"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   176
    proof (rule bar2)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   177
      fix w
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   178
      show "bar (w # zs)"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   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
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   181
        then show ?thesis by simp (rule prop1)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   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
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   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
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   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
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   195
      qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   196
    qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   197
  qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   198
qed
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   199
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   200
theorem prop3:
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   201
  assumes bar: "bar xs"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   202
  shows "\<And>zs. xs \<noteq> [] \<Longrightarrow> R a xs zs \<Longrightarrow> bar zs"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   203
  using bar
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   204
proof induct
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   205
  fix xs zs
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   206
  assume "R a xs zs" and "good xs"
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   207
  then have "good zs" by (rule lemma2)
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   208
  then show "bar zs" by (rule bar1)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   209
next
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   210
  fix xs zs
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   211
  assume I: "\<And>w zs. w # xs \<noteq> [] \<Longrightarrow> R a (w # xs) zs \<Longrightarrow> bar zs"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   212
    and xsb: "\<And>w. bar (w # xs)" and xsn: "xs \<noteq> []" and R: "R a xs zs"
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   213
  show "bar zs"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   214
  proof (rule bar2)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   215
    fix w
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   216
    show "bar (w # zs)"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   217
    proof (induct w)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   218
      case Nil
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   219
      show ?case by (rule prop1)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   220
    next
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   221
      case (Cons c cs)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   222
      from letter_eq_dec show ?case
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   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
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   225
        then show ?thesis by (iprover intro: I [simplified] R)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   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
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   229
        then show ?thesis by (iprover intro: prop2 Cons xsb xsn R T)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   230
      qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   231
    qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   232
  qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   233
qed
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   234
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   235
theorem higman: "bar []"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   236
proof (rule bar2)
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   237
  fix w
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   238
  show "bar [w]"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   239
  proof (induct w)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   240
    show "bar [[]]" by (rule prop1)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   241
  next
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   242
    fix c cs assume "bar [cs]"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   243
    then show "bar [c # cs]" by (rule prop3) (simp, iprover)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   244
  qed
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   245
qed
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   246
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   247
primrec is_prefix :: "'a list \<Rightarrow> (nat \<Rightarrow> 'a) \<Rightarrow> bool"
25976
11c6811f232c modernized primrec;
wenzelm
parents: 25417
diff changeset
   248
where
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   249
  "is_prefix [] f = True"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   250
| "is_prefix (x # xs) f = (x = f (length xs) \<and> is_prefix xs f)"
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   251
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   252
theorem L_idx:
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   253
  assumes L: "L w ws"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   254
  shows "is_prefix ws f \<Longrightarrow> \<exists>i. emb (f i) w \<and> i < length ws"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   255
  using L
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   256
proof induct
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   257
  case (L0 v ws)
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   258
  then have "emb (f (length ws)) w" by simp
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   259
  moreover have "length ws < length (v # ws)" by simp
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   260
  ultimately show ?case by iprover
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   261
next
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   262
  case (L1 ws v)
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   263
  then obtain i where emb: "emb (f i) w" and "i < length ws"
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   264
    by simp iprover
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   265
  then have "i < length (v # ws)" by simp
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   266
  with emb show ?case by iprover
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   267
qed
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   268
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   269
theorem good_idx:
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   270
  assumes good: "good ws"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   271
  shows "is_prefix ws f \<Longrightarrow> \<exists>i j. emb (f i) (f j) \<and> i < j"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   272
  using good
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   273
proof induct
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   274
  case (good0 w ws)
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   275
  then have "w = f (length ws)" and "is_prefix ws f" by simp_all
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   276
  with good0 show ?case by (iprover dest: L_idx)
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   277
next
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   278
  case (good1 ws w)
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   279
  then show ?case by simp
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   280
qed
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   281
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   282
theorem bar_idx:
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   283
  assumes bar: "bar ws"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   284
  shows "is_prefix ws f \<Longrightarrow> \<exists>i j. emb (f i) (f j) \<and> i < j"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   285
  using bar
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   286
proof induct
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   287
  case (bar1 ws)
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   288
  then show ?case by (rule good_idx)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   289
next
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   290
  case (bar2 ws)
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   291
  then have "is_prefix (f (length ws) # ws) f" by simp
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   292
  then show ?case by (rule bar2)
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   293
qed
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   294
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   295
text \<open>
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   296
  Strong version: yields indices of words that can be embedded into each other.
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   297
\<close>
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   298
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   299
theorem higman_idx: "\<exists>(i::nat) j. emb (f i) (f j) \<and> i < j"
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   300
proof (rule bar_idx)
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   301
  show "bar []" by (rule higman)
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   302
  show "is_prefix [] f" by simp
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   303
qed
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   304
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   305
text \<open>
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   306
  Weak version: only yield sequence containing words
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   307
  that can be embedded into each other.
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   308
\<close>
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   309
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   310
theorem good_prefix_lemma:
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   311
  assumes bar: "bar ws"
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   312
  shows "is_prefix ws f \<Longrightarrow> \<exists>vs. is_prefix vs f \<and> good vs"
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   313
  using bar
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   314
proof induct
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   315
  case bar1
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   316
  then show ?case by iprover
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   317
next
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   318
  case (bar2 ws)
23373
ead82c82da9e tuned proofs: avoid implicit prems;
wenzelm
parents: 22921
diff changeset
   319
  from bar2.prems have "is_prefix (f (length ws) # ws) f" by simp
63361
d10eab0672f9 misc tuning and modernization;
wenzelm
parents: 61986
diff changeset
   320
  then show ?case by (iprover intro: bar2)
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   321
qed
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   322
22266
9f3198585c89 Adapted to new inductive definition package.
berghofe
parents: 21545
diff changeset
   323
theorem good_prefix: "\<exists>vs. is_prefix vs f \<and> good vs"
13930
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   324
  using higman
562fd03b266d Converted main proofs to Isar.
berghofe
parents: 13711
diff changeset
   325
  by (rule good_prefix_lemma) simp+
13405
d20a4e67afc8 Examples for program extraction in HOL.
berghofe
parents:
diff changeset
   326
27982
2aaa4a5569a6 default replaces arbitrary
haftmann
parents: 27436
diff changeset
   327
end