src/HOL/ex/Primrec.thy
author wenzelm
Wed, 17 May 2006 22:34:44 +0200
changeset 19676 187234ec6050
parent 16731 124b4782944f
child 19736 d8d0f8f51d69
permissions -rw-r--r--
renamed CONST to CONSTANT;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
     1
(*  Title:      HOL/ex/Primrec.thy
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
     2
    ID:         $Id$
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
     4
    Copyright   1997  University of Cambridge
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
     5
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
     6
Primitive Recursive Functions.  Demonstrates recursive definitions,
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
     7
the TFL package.
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
     8
*)
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
     9
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    10
header {* Primitive Recursive Functions *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    11
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 11704
diff changeset
    12
theory Primrec imports Main begin
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    13
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    14
text {*
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    15
  Proof adopted from
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    16
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    17
  Nora Szasz, A Machine Checked Proof that Ackermann's Function is not
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    18
  Primitive Recursive, In: Huet \& Plotkin, eds., Logical Environments
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    19
  (CUP, 1993), 317-338.
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    20
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    21
  See also E. Mendelson, Introduction to Mathematical Logic.  (Van
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    22
  Nostrand, 1964), page 250, exercise 11.
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    23
  \medskip
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    24
*}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    25
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    26
consts ack :: "nat * nat => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    27
recdef ack  "less_than <*lex*> less_than"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    28
  "ack (0, n) =  Suc n"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    29
  "ack (Suc m, 0) = ack (m, 1)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    30
  "ack (Suc m, Suc n) = ack (m, ack (Suc m, n))"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    31
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    32
consts list_add :: "nat list => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    33
primrec
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    34
  "list_add [] = 0"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    35
  "list_add (m # ms) = m + list_add ms"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    36
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    37
consts zeroHd :: "nat list => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    38
primrec
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    39
  "zeroHd [] = 0"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    40
  "zeroHd (m # ms) = m"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    41
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    42
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    43
text {* The set of primitive recursive functions of type @{typ "nat list => nat"}. *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    44
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    45
constdefs
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    46
  SC :: "nat list => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    47
  "SC l == Suc (zeroHd l)"
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
    48
19676
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
    49
  CONSTANT :: "nat => nat list => nat"
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
    50
  "CONSTANT k l == k"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    51
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    52
  PROJ :: "nat => nat list => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    53
  "PROJ i l == zeroHd (drop i l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    54
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    55
  COMP :: "(nat list => nat) => (nat list => nat) list => nat list => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    56
  "COMP g fs l == g (map (\<lambda>f. f l) fs)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    57
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    58
  PREC :: "(nat list => nat) => (nat list => nat) => nat list => nat"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    59
  "PREC f g l ==
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    60
    case l of
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    61
      [] => 0
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    62
    | x # l' => nat_rec (f l') (\<lambda>y r. g (r # y # l')) x"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    63
  -- {* Note that @{term g} is applied first to @{term "PREC f g y"} and then to @{term y}! *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    64
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    65
consts PRIMREC :: "(nat list => nat) set"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    66
inductive PRIMREC
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    67
  intros
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    68
    SC: "SC \<in> PRIMREC"
19676
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
    69
    CONSTANT: "CONSTANT k \<in> PRIMREC"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    70
    PROJ: "PROJ i \<in> PRIMREC"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    71
    COMP: "g \<in> PRIMREC ==> fs \<in> lists PRIMREC ==> COMP g fs \<in> PRIMREC"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    72
    PREC: "f \<in> PRIMREC ==> g \<in> PRIMREC ==> PREC f g \<in> PRIMREC"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    73
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    74
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    75
text {* Useful special cases of evaluation *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    76
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    77
lemma SC [simp]: "SC (x # l) = Suc x"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    78
  apply (simp add: SC_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    79
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    80
19676
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
    81
lemma CONSTANT [simp]: "CONSTANT k l = k"
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
    82
  apply (simp add: CONSTANT_def)
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    83
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    84
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    85
lemma PROJ_0 [simp]: "PROJ 0 (x # l) = x"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    86
  apply (simp add: PROJ_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    87
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    88
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    89
lemma COMP_1 [simp]: "COMP g [f] l = g [f l]"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    90
  apply (simp add: COMP_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    91
  done
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
    92
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    93
lemma PREC_0 [simp]: "PREC f g (0 # l) = f l"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    94
  apply (simp add: PREC_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    95
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    96
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    97
lemma PREC_Suc [simp]: "PREC f g (Suc x # l) = g (PREC f g (x # l) # x # l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    98
  apply (simp add: PREC_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
    99
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   100
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   101
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   102
text {* PROPERTY A 4 *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   103
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   104
lemma less_ack2 [iff]: "j < ack (i, j)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   105
  apply (induct i j rule: ack.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   106
    apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   107
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   108
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   109
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   110
text {* PROPERTY A 5-, the single-step lemma *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   111
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   112
lemma ack_less_ack_Suc2 [iff]: "ack(i, j) < ack (i, Suc j)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   113
  apply (induct i j rule: ack.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   114
    apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   115
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   116
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   117
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   118
text {* PROPERTY A 5, monotonicity for @{text "<"} *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   119
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   120
lemma ack_less_mono2: "j < k ==> ack (i, j) < ack (i, k)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   121
  apply (induct i k rule: ack.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   122
    apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   123
  apply (blast elim!: less_SucE intro: less_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   124
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   125
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   126
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   127
text {* PROPERTY A 5', monotonicity for @{text \<le>} *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   128
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   129
lemma ack_le_mono2: "j \<le> k ==> ack (i, j) \<le> ack (i, k)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   130
  apply (simp add: order_le_less)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   131
  apply (blast intro: ack_less_mono2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   132
  done
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   133
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   134
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   135
text {* PROPERTY A 6 *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   136
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   137
lemma ack2_le_ack1 [iff]: "ack (i, Suc j) \<le> ack (Suc i, j)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   138
  apply (induct j)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   139
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   140
  apply (blast intro: ack_le_mono2 less_ack2 [THEN Suc_leI] le_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   141
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   142
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   143
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   144
text {* PROPERTY A 7-, the single-step lemma *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   145
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   146
lemma ack_less_ack_Suc1 [iff]: "ack (i, j) < ack (Suc i, j)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   147
  apply (blast intro: ack_less_mono2 less_le_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   148
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   149
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   150
19676
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
   151
text {* PROPERTY A 4'? Extra lemma needed for @{term CONSTANT} case, constant functions *}
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   152
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   153
lemma less_ack1 [iff]: "i < ack (i, j)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   154
  apply (induct i)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   155
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   156
  apply (blast intro: Suc_leI le_less_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   157
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   158
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   159
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   160
text {* PROPERTY A 8 *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   161
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   162
lemma ack_1 [simp]: "ack (Suc 0, j) = j + 2"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   163
  apply (induct j)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   164
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   165
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   166
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   167
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11464
diff changeset
   168
text {* PROPERTY A 9.  The unary @{text 1} and @{text 2} in @{term
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   169
  ack} is essential for the rewriting. *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   170
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   171
lemma ack_2 [simp]: "ack (Suc (Suc 0), j) = 2 * j + 3"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   172
  apply (induct j)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   173
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   174
  done
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   175
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   176
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   177
text {* PROPERTY A 7, monotonicity for @{text "<"} [not clear why
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   178
  @{thm [source] ack_1} is now needed first!] *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   179
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   180
lemma ack_less_mono1_aux: "ack (i, k) < ack (Suc (i +i'), k)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   181
  apply (induct i k rule: ack.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   182
    apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   183
   prefer 2
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   184
   apply (blast intro: less_trans ack_less_mono2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   185
  apply (induct_tac i' n rule: ack.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   186
    apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   187
  apply (blast intro: Suc_leI [THEN le_less_trans] ack_less_mono2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   188
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   189
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   190
lemma ack_less_mono1: "i < j ==> ack (i, k) < ack (j, k)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   191
  apply (drule less_imp_Suc_add)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   192
  apply (blast intro!: ack_less_mono1_aux)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   193
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   194
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   195
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   196
text {* PROPERTY A 7', monotonicity for @{text "\<le>"} *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   197
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   198
lemma ack_le_mono1: "i \<le> j ==> ack (i, k) \<le> ack (j, k)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   199
  apply (simp add: order_le_less)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   200
  apply (blast intro: ack_less_mono1)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   201
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   202
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   203
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   204
text {* PROPERTY A 10 *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   205
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   206
lemma ack_nest_bound: "ack(i1, ack (i2, j)) < ack (2 + (i1 + i2), j)"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   207
  apply (simp add: numerals)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   208
  apply (rule ack2_le_ack1 [THEN [2] less_le_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   209
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   210
  apply (rule le_add1 [THEN ack_le_mono1, THEN le_less_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   211
  apply (rule ack_less_mono1 [THEN ack_less_mono2])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   212
  apply (simp add: le_imp_less_Suc le_add2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   213
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   214
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   215
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   216
text {* PROPERTY A 11 *}
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   217
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   218
lemma ack_add_bound: "ack (i1, j) + ack (i2, j) < ack (4 + (i1 + i2), j)"
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11464
diff changeset
   219
  apply (rule_tac j = "ack (Suc (Suc 0), ack (i1 + i2, j))" in less_trans)
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   220
   prefer 2
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   221
   apply (rule ack_nest_bound [THEN less_le_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   222
   apply (simp add: Suc3_eq_add_3)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   223
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   224
  apply (cut_tac i = i1 and m1 = i2 and k = j in le_add1 [THEN ack_le_mono1])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   225
  apply (cut_tac i = "i2" and m1 = i1 and k = j in le_add2 [THEN ack_le_mono1])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   226
  apply auto
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   227
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   228
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   229
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   230
text {* PROPERTY A 12.  Article uses existential quantifier but the ALF proof
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   231
  used @{text "k + 4"}.  Quantified version must be nested @{text
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   232
  "\<exists>k'. \<forall>i j. ..."} *}
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   233
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   234
lemma ack_add_bound2: "i < ack (k, j) ==> i + j < ack (4 + k, j)"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   235
  apply (rule_tac j = "ack (k, j) + ack (0, j)" in less_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   236
   prefer 2
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   237
   apply (rule ack_add_bound [THEN less_le_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   238
   apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   239
  apply (rule add_less_mono less_ack2 | assumption)+
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   240
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   241
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   242
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   243
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   244
text {* Inductive definition of the @{term PR} functions *}
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   245
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   246
text {* MAIN RESULT *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   247
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   248
lemma SC_case: "SC l < ack (1, list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   249
  apply (unfold SC_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   250
  apply (induct l)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   251
  apply (simp_all add: le_add1 le_imp_less_Suc)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   252
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   253
19676
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
   254
lemma CONSTANT_case: "CONSTANT k l < ack (k, list_add l)"
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   255
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   256
  done
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   257
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   258
lemma PROJ_case [rule_format]: "\<forall>i. PROJ i l < ack (0, list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   259
  apply (simp add: PROJ_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   260
  apply (induct l)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   261
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   262
  apply (rule allI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   263
  apply (case_tac i)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   264
  apply (simp (no_asm_simp) add: le_add1 le_imp_less_Suc)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   265
  apply (simp (no_asm_simp))
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   266
  apply (blast intro: less_le_trans intro!: le_add2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   267
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   268
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   269
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   270
text {* @{term COMP} case *}
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   271
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   272
lemma COMP_map_aux: "fs \<in> lists (PRIMREC \<inter> {f. \<exists>kf. \<forall>l. f l < ack (kf, list_add l)})
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   273
  ==> \<exists>k. \<forall>l. list_add (map (\<lambda>f. f l) fs) < ack (k, list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   274
  apply (erule lists.induct)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   275
  apply (rule_tac x = 0 in exI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   276
   apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   277
  apply safe
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   278
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   279
  apply (rule exI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   280
  apply (blast intro: add_less_mono ack_add_bound less_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   281
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   282
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   283
lemma COMP_case:
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   284
  "\<forall>l. g l < ack (kg, list_add l) ==>
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   285
  fs \<in> lists(PRIMREC Int {f. \<exists>kf. \<forall>l. f l < ack(kf, list_add l)})
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   286
  ==> \<exists>k. \<forall>l. COMP g fs  l < ack(k, list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   287
  apply (unfold COMP_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   288
  apply (frule Int_lower1 [THEN lists_mono, THEN subsetD])
16588
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   289
    --{*Now, if meson tolerated map, we could finish with
16731
124b4782944f fixed antiquotation;
wenzelm
parents: 16588
diff changeset
   290
  @{text "(drule COMP_map_aux, meson ack_less_mono2 ack_nest_bound less_trans)"} *}
16588
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   291
  apply (erule COMP_map_aux [THEN exE])
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   292
  apply (rule exI)
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   293
  apply (rule allI)
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   294
  apply (drule spec)+
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   295
  apply (erule less_trans)
8de758143786 stricter first-order check for meson
paulson
parents: 16563
diff changeset
   296
  apply (blast intro: ack_less_mono2 ack_nest_bound less_trans)
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   297
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   298
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   299
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   300
text {* @{term PREC} case *}
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   301
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   302
lemma PREC_case_aux:
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   303
  "\<forall>l. f l + list_add l < ack (kf, list_add l) ==>
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   304
    \<forall>l. g l + list_add l < ack (kg, list_add l) ==>
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   305
    PREC f g l + list_add l < ack (Suc (kf + kg), list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   306
  apply (unfold PREC_def)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   307
  apply (case_tac l)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   308
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   309
   apply (blast intro: less_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   310
  apply (erule ssubst) -- {* get rid of the needless assumption *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   311
  apply (induct_tac a)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   312
   apply simp_all
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   313
   txt {* base case *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   314
   apply (blast intro: le_add1 [THEN le_imp_less_Suc, THEN ack_less_mono1] less_trans)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   315
  txt {* induction step *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   316
  apply (rule Suc_leI [THEN le_less_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   317
   apply (rule le_refl [THEN add_le_mono, THEN le_less_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   318
    prefer 2
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   319
    apply (erule spec)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   320
   apply (simp add: le_add2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   321
  txt {* final part of the simplification *}
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   322
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   323
  apply (rule le_add2 [THEN ack_le_mono1, THEN le_less_trans])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   324
  apply (erule ack_less_mono2)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   325
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   326
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   327
lemma PREC_case:
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   328
  "\<forall>l. f l < ack (kf, list_add l) ==>
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   329
    \<forall>l. g l < ack (kg, list_add l) ==>
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   330
    \<exists>k. \<forall>l. PREC f g l < ack (k, list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   331
  apply (rule exI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   332
  apply (rule allI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   333
  apply (rule le_less_trans [OF le_add1 PREC_case_aux])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   334
   apply (blast intro: ack_add_bound2)+
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   335
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   336
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   337
lemma ack_bounds_PRIMREC: "f \<in> PRIMREC ==> \<exists>k. \<forall>l. f l < ack (k, list_add l)"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   338
  apply (erule PRIMREC.induct)
19676
187234ec6050 renamed CONST to CONSTANT;
wenzelm
parents: 16731
diff changeset
   339
      apply (blast intro: SC_case CONSTANT_case PROJ_case COMP_case PREC_case)+
11024
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   340
  done
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   341
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   342
lemma ack_not_PRIMREC: "(\<lambda>l. case l of [] => 0 | x # l' => ack (x, x)) \<notin> PRIMREC"
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   343
  apply (rule notI)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   344
  apply (erule ack_bounds_PRIMREC [THEN exE])
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   345
  apply (rule less_irrefl)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   346
  apply (drule_tac x = "[x]" in spec)
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   347
  apply simp
23bf8d787b04 converted to new-style theories;
wenzelm
parents: 8703
diff changeset
   348
  done
3335
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   349
b0139b83a5ee New example ported from ZF
paulson
parents:
diff changeset
   350
end