src/ZF/ex/Primrec.ML
author lcp
Tue Aug 16 18:58:42 1994 +0200 (1994-08-16)
changeset 532 851df239ac8b
parent 515 abcc438e7c27
child 760 f0200e91b272
permissions -rw-r--r--
ZF/Makefile,ROOT.ML, ZF/ex/Integ.thy: updated for EquivClass
lcp@515
     1
(*  Title: 	ZF/ex/Primrec
lcp@515
     2
    ID:         $Id$
lcp@515
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
lcp@515
     4
    Copyright   1994  University of Cambridge
lcp@515
     5
lcp@515
     6
Primitive Recursive Functions
lcp@515
     7
lcp@515
     8
Proof adopted from
lcp@515
     9
Nora Szasz, 
lcp@515
    10
A Machine Checked Proof that Ackermann's Function is not Primitive Recursive,
lcp@515
    11
In: Huet & Plotkin, eds., Logical Environments (CUP, 1993), 317-338.
lcp@515
    12
lcp@515
    13
See also E. Mendelson, Introduction to Mathematical Logic.
lcp@515
    14
(Van Nostrand, 1964), page 250, exercise 11.
lcp@515
    15
*)
lcp@515
    16
lcp@515
    17
open Primrec;
lcp@515
    18
lcp@515
    19
val pr_typechecks = 
lcp@515
    20
    nat_typechecks @ list.intrs @ 
lcp@515
    21
    [lam_type, list_case_type, drop_type, map_type, apply_type, rec_type];
lcp@515
    22
lcp@515
    23
(** Useful special cases of evaluation ***)
lcp@515
    24
lcp@515
    25
val pr_ss = arith_ss 
lcp@515
    26
    addsimps list.case_eqns
lcp@515
    27
    addsimps [list_rec_Nil, list_rec_Cons, 
lcp@515
    28
	      drop_0, drop_Nil, drop_succ_Cons,
lcp@515
    29
	      map_Nil, map_Cons]
lcp@515
    30
    setsolver (type_auto_tac pr_typechecks);
lcp@515
    31
lcp@515
    32
goalw Primrec.thy [SC_def]
lcp@515
    33
    "!!x l. [| x:nat;  l: list(nat) |] ==> SC ` (Cons(x,l)) = succ(x)";
lcp@515
    34
by (asm_simp_tac pr_ss 1);
lcp@515
    35
val SC = result();
lcp@515
    36
lcp@515
    37
goalw Primrec.thy [CONST_def]
lcp@515
    38
    "!!l. [| l: list(nat) |] ==> CONST(k) ` l = k";
lcp@515
    39
by (asm_simp_tac pr_ss 1);
lcp@515
    40
val CONST = result();
lcp@515
    41
lcp@515
    42
goalw Primrec.thy [PROJ_def]
lcp@515
    43
    "!!l. [| x: nat;  l: list(nat) |] ==> PROJ(0) ` (Cons(x,l)) = x";
lcp@515
    44
by (asm_simp_tac pr_ss 1);
lcp@515
    45
val PROJ_0 = result();
lcp@515
    46
lcp@515
    47
goalw Primrec.thy [COMP_def]
lcp@515
    48
    "!!l. [| l: list(nat) |] ==> COMP(g,[f]) ` l = g` [f`l]";
lcp@515
    49
by (asm_simp_tac pr_ss 1);
lcp@515
    50
val COMP_1 = result();
lcp@515
    51
lcp@515
    52
goalw Primrec.thy [PREC_def]
lcp@515
    53
    "!!l. l: list(nat) ==> PREC(f,g) ` (Cons(0,l)) = f`l";
lcp@515
    54
by (asm_simp_tac pr_ss 1);
lcp@515
    55
val PREC_0 = result();
lcp@515
    56
lcp@515
    57
goalw Primrec.thy [PREC_def]
lcp@515
    58
    "!!l. [| x:nat;  l: list(nat) |] ==>  \
lcp@515
    59
\         PREC(f,g) ` (Cons(succ(x),l)) = \
lcp@515
    60
\         g ` Cons(PREC(f,g)`(Cons(x,l)), Cons(x,l))";
lcp@515
    61
by (asm_simp_tac pr_ss 1);
lcp@515
    62
val PREC_succ = result();
lcp@515
    63
lcp@515
    64
(*** Inductive definition of the PR functions ***)
lcp@515
    65
lcp@515
    66
(* c: primrec ==> c: list(nat) -> nat *)
lcp@515
    67
val primrec_into_fun = primrec.dom_subset RS subsetD;
lcp@515
    68
lcp@515
    69
val pr_ss = pr_ss 
lcp@515
    70
    setsolver (type_auto_tac ([primrec_into_fun] @ 
lcp@515
    71
			      pr_typechecks @ primrec.intrs));
lcp@515
    72
lcp@515
    73
goalw Primrec.thy [ACK_def] "!!i. i:nat ==> ACK(i): primrec";
lcp@515
    74
by (etac nat_induct 1);
lcp@515
    75
by (ALLGOALS (asm_simp_tac pr_ss));
lcp@515
    76
val ACK_in_primrec = result();
lcp@515
    77
lcp@515
    78
val ack_typechecks =
lcp@515
    79
    [ACK_in_primrec, primrec_into_fun RS apply_type,
lcp@515
    80
     add_type, list_add_type, nat_into_Ord] @ 
lcp@515
    81
    nat_typechecks @ list.intrs @ primrec.intrs;
lcp@515
    82
lcp@515
    83
(*strict typechecking for the Ackermann proof; instantiates no vars*)
lcp@515
    84
fun tc_tac rls =
lcp@515
    85
    REPEAT
lcp@515
    86
      (SOMEGOAL (test_assume_tac ORELSE' match_tac (rls @ ack_typechecks)));
lcp@515
    87
lcp@515
    88
goal Primrec.thy "!!i j. [| i:nat;  j:nat |] ==>  ack(i,j): nat";
lcp@515
    89
by (tc_tac []);
lcp@515
    90
val ack_type = result();
lcp@515
    91
lcp@515
    92
(** Ackermann's function cases **)
lcp@515
    93
lcp@515
    94
(*PROPERTY A 1*)
lcp@515
    95
goalw Primrec.thy [ACK_def] "!!j. j:nat ==> ack(0,j) = succ(j)";
lcp@515
    96
by (asm_simp_tac (pr_ss addsimps [SC]) 1);
lcp@515
    97
val ack_0 = result();
lcp@515
    98
lcp@515
    99
(*PROPERTY A 2*)
lcp@515
   100
goalw Primrec.thy [ACK_def] "ack(succ(i), 0) = ack(i,1)";
lcp@515
   101
by (asm_simp_tac (pr_ss addsimps [CONST,PREC_0]) 1);
lcp@515
   102
val ack_succ_0 = result();
lcp@515
   103
lcp@515
   104
(*PROPERTY A 3*)
lcp@515
   105
(*Could be proved in Primrec0, like the previous two cases, but using
lcp@515
   106
  primrec_into_fun makes type-checking easier!*)
lcp@515
   107
goalw Primrec.thy [ACK_def]
lcp@515
   108
    "!!i j. [| i:nat;  j:nat |] ==> \
lcp@515
   109
\           ack(succ(i), succ(j)) = ack(i, ack(succ(i), j))";
lcp@515
   110
by (asm_simp_tac (pr_ss addsimps [CONST,PREC_succ,COMP_1,PROJ_0]) 1);
lcp@515
   111
val ack_succ_succ = result();
lcp@515
   112
lcp@515
   113
val ack_ss = 
lcp@515
   114
    pr_ss addsimps [ack_0, ack_succ_0, ack_succ_succ, 
lcp@515
   115
		    ack_type, nat_into_Ord];
lcp@515
   116
lcp@515
   117
(*PROPERTY A 4*)
lcp@515
   118
goal Primrec.thy "!!i. i:nat ==> ALL j:nat. j < ack(i,j)";
lcp@515
   119
by (etac nat_induct 1);
lcp@515
   120
by (asm_simp_tac ack_ss 1);
lcp@515
   121
by (rtac ballI 1);
lcp@515
   122
by (eres_inst_tac [("n","j")] nat_induct 1);
lcp@515
   123
by (DO_GOAL [rtac (nat_0I RS nat_0_le RS lt_trans),
lcp@515
   124
	     asm_simp_tac ack_ss] 1);
lcp@515
   125
by (DO_GOAL [etac (succ_leI RS lt_trans1),
lcp@515
   126
	     asm_simp_tac ack_ss] 1);
lcp@515
   127
val lt_ack2_lemma = result();
lcp@515
   128
val lt_ack2 = standard (lt_ack2_lemma RS bspec);
lcp@515
   129
lcp@515
   130
(*PROPERTY A 5-, the single-step lemma*)
lcp@515
   131
goal Primrec.thy "!!i j. [| i:nat; j:nat |] ==> ack(i,j) < ack(i, succ(j))";
lcp@515
   132
by (etac nat_induct 1);
lcp@515
   133
by (ALLGOALS (asm_simp_tac (ack_ss addsimps [lt_ack2])));
lcp@515
   134
val ack_lt_ack_succ2 = result();
lcp@515
   135
lcp@515
   136
(*PROPERTY A 5, monotonicity for < *)
lcp@515
   137
goal Primrec.thy "!!i j k. [| j<k; i:nat; k:nat |] ==> ack(i,j) < ack(i,k)";
lcp@515
   138
by (forward_tac [lt_nat_in_nat] 1 THEN assume_tac 1);
lcp@515
   139
by (etac succ_lt_induct 1);
lcp@515
   140
by (assume_tac 1);
lcp@515
   141
by (rtac lt_trans 2);
lcp@515
   142
by (REPEAT (ares_tac ([ack_lt_ack_succ2, ack_type] @ pr_typechecks) 1));
lcp@515
   143
val ack_lt_mono2 = result();
lcp@515
   144
lcp@515
   145
(*PROPERTY A 5', monotonicity for le *)
lcp@515
   146
goal Primrec.thy
lcp@515
   147
    "!!i j k. [| j le k;  i: nat;  k:nat |] ==> ack(i,j) le ack(i,k)";
lcp@515
   148
by (res_inst_tac [("f", "%j.ack(i,j)")] Ord_lt_mono_imp_le_mono 1);
lcp@515
   149
by (REPEAT (ares_tac [ack_lt_mono2, ack_type RS nat_into_Ord] 1));
lcp@515
   150
val ack_le_mono2 = result();
lcp@515
   151
lcp@515
   152
(*PROPERTY A 6*)
lcp@515
   153
goal Primrec.thy
lcp@515
   154
    "!!i j. [| i:nat;  j:nat |] ==> ack(i, succ(j)) le ack(succ(i), j)";
lcp@515
   155
by (nat_ind_tac "j" [] 1);
lcp@515
   156
by (ALLGOALS (asm_simp_tac ack_ss));
lcp@515
   157
by (rtac ack_le_mono2 1);
lcp@515
   158
by (rtac (lt_ack2 RS succ_leI RS le_trans) 1);
lcp@515
   159
by (REPEAT (ares_tac (ack_typechecks) 1));
lcp@515
   160
val ack2_le_ack1 = result();
lcp@515
   161
lcp@515
   162
(*PROPERTY A 7-, the single-step lemma*)
lcp@515
   163
goal Primrec.thy "!!i j. [| i:nat; j:nat |] ==> ack(i,j) < ack(succ(i),j)";
lcp@515
   164
by (rtac (ack_lt_mono2 RS lt_trans2) 1);
lcp@515
   165
by (rtac ack2_le_ack1 4);
lcp@515
   166
by (REPEAT (ares_tac ([nat_le_refl, ack_type] @ pr_typechecks) 1));
lcp@515
   167
val ack_lt_ack_succ1 = result();
lcp@515
   168
lcp@515
   169
(*PROPERTY A 7, monotonicity for < *)
lcp@515
   170
goal Primrec.thy "!!i j k. [| i<j; j:nat; k:nat |] ==> ack(i,k) < ack(j,k)";
lcp@515
   171
by (forward_tac [lt_nat_in_nat] 1 THEN assume_tac 1);
lcp@515
   172
by (etac succ_lt_induct 1);
lcp@515
   173
by (assume_tac 1);
lcp@515
   174
by (rtac lt_trans 2);
lcp@515
   175
by (REPEAT (ares_tac ([ack_lt_ack_succ1, ack_type] @ pr_typechecks) 1));
lcp@515
   176
val ack_lt_mono1 = result();
lcp@515
   177
lcp@515
   178
(*PROPERTY A 7', monotonicity for le *)
lcp@515
   179
goal Primrec.thy
lcp@515
   180
    "!!i j k. [| i le j; j:nat; k:nat |] ==> ack(i,k) le ack(j,k)";
lcp@515
   181
by (res_inst_tac [("f", "%j.ack(j,k)")] Ord_lt_mono_imp_le_mono 1);
lcp@515
   182
by (REPEAT (ares_tac [ack_lt_mono1, ack_type RS nat_into_Ord] 1));
lcp@515
   183
val ack_le_mono1 = result();
lcp@515
   184
lcp@515
   185
(*PROPERTY A 8*)
lcp@515
   186
goal Primrec.thy "!!j. j:nat ==> ack(1,j) = succ(succ(j))";
lcp@515
   187
by (etac nat_induct 1);
lcp@515
   188
by (ALLGOALS (asm_simp_tac ack_ss));
lcp@515
   189
val ack_1 = result();
lcp@515
   190
lcp@515
   191
(*PROPERTY A 9*)
lcp@515
   192
goal Primrec.thy "!!j. j:nat ==> ack(succ(1),j) = succ(succ(succ(j#+j)))";
lcp@515
   193
by (etac nat_induct 1);
lcp@515
   194
by (ALLGOALS (asm_simp_tac (ack_ss addsimps [ack_1, add_succ_right])));
lcp@515
   195
val ack_2 = result();
lcp@515
   196
lcp@515
   197
(*PROPERTY A 10*)
lcp@515
   198
goal Primrec.thy
lcp@515
   199
    "!!i1 i2 j. [| i1:nat; i2:nat; j:nat |] ==> \
lcp@515
   200
\               ack(i1, ack(i2,j)) < ack(succ(succ(i1#+i2)), j)";
lcp@515
   201
by (rtac (ack2_le_ack1 RSN (2,lt_trans2)) 1);
lcp@515
   202
by (asm_simp_tac ack_ss 1);
lcp@515
   203
by (rtac (add_le_self RS ack_le_mono1 RS lt_trans1) 1);
lcp@515
   204
by (rtac (add_le_self2 RS ack_lt_mono1 RS ack_lt_mono2) 5);
lcp@515
   205
by (tc_tac []);
lcp@515
   206
val ack_nest_bound = result();
lcp@515
   207
lcp@515
   208
(*PROPERTY A 11*)
lcp@515
   209
goal Primrec.thy
lcp@515
   210
    "!!i1 i2 j. [| i1:nat; i2:nat; j:nat |] ==> \
lcp@515
   211
\          ack(i1,j) #+ ack(i2,j) < ack(succ(succ(succ(succ(i1#+i2)))), j)";
lcp@515
   212
by (res_inst_tac [("j", "ack(succ(1), ack(i1 #+ i2, j))")] lt_trans 1);
lcp@515
   213
by (asm_simp_tac (ack_ss addsimps [ack_2]) 1);
lcp@515
   214
by (rtac (ack_nest_bound RS lt_trans2) 2);
lcp@515
   215
by (asm_simp_tac ack_ss 5);
lcp@515
   216
by (rtac (add_le_mono RS leI RS leI) 1);
lcp@515
   217
by (REPEAT (ares_tac ([add_le_self, add_le_self2, ack_le_mono1] @
lcp@515
   218
                      ack_typechecks) 1));
lcp@515
   219
val ack_add_bound = result();
lcp@515
   220
lcp@515
   221
(*PROPERTY A 12.  Article uses existential quantifier but the ALF proof
lcp@515
   222
  used k#+4.  Quantified version must be nested EX k'. ALL i,j... *)
lcp@515
   223
goal Primrec.thy
lcp@515
   224
    "!!i j k. [| i < ack(k,j);  j:nat;  k:nat |] ==> \
lcp@515
   225
\             i#+j < ack(succ(succ(succ(succ(k)))), j)";
lcp@515
   226
by (res_inst_tac [("j", "ack(k,j) #+ ack(0,j)")] lt_trans 1);
lcp@515
   227
by (rtac (ack_add_bound RS lt_trans2) 2);
lcp@515
   228
by (asm_simp_tac (ack_ss addsimps [add_0_right]) 5);
lcp@515
   229
by (REPEAT (ares_tac ([add_lt_mono, lt_ack2] @ ack_typechecks) 1));
lcp@515
   230
val ack_add_bound2 = result();
lcp@515
   231
lcp@515
   232
(*** MAIN RESULT ***)
lcp@515
   233
lcp@515
   234
val ack2_ss =
lcp@515
   235
    ack_ss addsimps [list_add_Nil, list_add_Cons, list_add_type, nat_into_Ord];
lcp@515
   236
lcp@515
   237
goalw Primrec.thy [SC_def]
lcp@515
   238
    "!!l. l: list(nat) ==> SC ` l < ack(1, list_add(l))";
lcp@515
   239
by (etac list.elim 1);
lcp@515
   240
by (asm_simp_tac (ack2_ss addsimps [succ_iff]) 1);
lcp@515
   241
by (asm_simp_tac (ack2_ss addsimps [ack_1, add_le_self]) 1);
lcp@515
   242
val SC_case = result();
lcp@515
   243
lcp@515
   244
(*PROPERTY A 4'? Extra lemma needed for CONST case, constant functions*)
lcp@515
   245
goal Primrec.thy "!!j. [| i:nat; j:nat |] ==> i < ack(i,j)";
lcp@515
   246
by (etac nat_induct 1);
lcp@515
   247
by (asm_simp_tac (ack_ss addsimps [nat_0_le]) 1);
lcp@515
   248
by (etac ([succ_leI, ack_lt_ack_succ1] MRS lt_trans1) 1);
lcp@515
   249
by (tc_tac []);
lcp@515
   250
val lt_ack1 = result();
lcp@515
   251
lcp@515
   252
goalw Primrec.thy [CONST_def]
lcp@515
   253
    "!!l. [| l: list(nat);  k: nat |] ==> CONST(k) ` l < ack(k, list_add(l))";
lcp@515
   254
by (asm_simp_tac (ack2_ss addsimps [lt_ack1]) 1);
lcp@515
   255
val CONST_case = result();
lcp@515
   256
lcp@515
   257
goalw Primrec.thy [PROJ_def]
lcp@515
   258
    "!!l. l: list(nat) ==> ALL i:nat. PROJ(i) ` l < ack(0, list_add(l))";
lcp@515
   259
by (asm_simp_tac ack2_ss 1);
lcp@515
   260
by (etac list.induct 1);
lcp@515
   261
by (asm_simp_tac (ack2_ss addsimps [nat_0_le]) 1);
lcp@515
   262
by (asm_simp_tac ack2_ss 1);
lcp@515
   263
by (rtac ballI 1);
lcp@515
   264
by (eres_inst_tac [("n","x")] natE 1);
lcp@515
   265
by (asm_simp_tac (ack2_ss addsimps [add_le_self]) 1);
lcp@515
   266
by (asm_simp_tac ack2_ss 1);
lcp@515
   267
by (etac (bspec RS lt_trans2) 1);
lcp@515
   268
by (rtac (add_le_self2 RS succ_leI) 2);
lcp@515
   269
by (tc_tac []);
lcp@515
   270
val PROJ_case_lemma = result();
lcp@515
   271
val PROJ_case = PROJ_case_lemma RS bspec;
lcp@515
   272
lcp@515
   273
(** COMP case **)
lcp@515
   274
lcp@515
   275
goal Primrec.thy
lcp@515
   276
 "!!fs. fs : list({f: primrec .					\
lcp@515
   277
\              	   EX kf:nat. ALL l:list(nat). 			\
lcp@515
   278
\		    	      f`l < ack(kf, list_add(l))})	\
lcp@515
   279
\      ==> EX k:nat. ALL l: list(nat). 				\
lcp@515
   280
\                list_add(map(%f. f ` l, fs)) < ack(k, list_add(l))";
lcp@515
   281
by (etac list.induct 1);
lcp@515
   282
by (DO_GOAL [res_inst_tac [("x","0")] bexI,
lcp@515
   283
	     asm_simp_tac (ack2_ss addsimps [lt_ack1, nat_0_le]),
lcp@515
   284
	     resolve_tac nat_typechecks] 1);
lcp@515
   285
by (safe_tac ZF_cs);
lcp@515
   286
by (asm_simp_tac ack2_ss 1);
lcp@515
   287
by (rtac (ballI RS bexI) 1);
lcp@515
   288
by (rtac (add_lt_mono RS lt_trans) 1);
lcp@515
   289
by (REPEAT (FIRSTGOAL (etac bspec)));
lcp@515
   290
by (rtac ack_add_bound 5);
lcp@515
   291
by (tc_tac []);
lcp@515
   292
val COMP_map_lemma = result();
lcp@515
   293
lcp@515
   294
goalw Primrec.thy [COMP_def]
lcp@515
   295
 "!!g. [| g: primrec;  kg: nat;					\
lcp@515
   296
\         ALL l:list(nat). g`l < ack(kg, list_add(l));		\
lcp@515
   297
\         fs : list({f: primrec .				\
lcp@515
   298
\                    EX kf:nat. ALL l:list(nat). 		\
lcp@515
   299
\		    	f`l < ack(kf, list_add(l))}) 		\
lcp@515
   300
\      |] ==> EX k:nat. ALL l: list(nat). COMP(g,fs)`l < ack(k, list_add(l))";
lcp@515
   301
by (asm_simp_tac ZF_ss 1);
lcp@515
   302
by (forward_tac [list_CollectD] 1);
lcp@515
   303
by (etac (COMP_map_lemma RS bexE) 1);
lcp@515
   304
by (rtac (ballI RS bexI) 1);
lcp@515
   305
by (etac (bspec RS lt_trans) 1);
lcp@515
   306
by (rtac lt_trans 2);
lcp@515
   307
by (rtac ack_nest_bound 3);
lcp@515
   308
by (etac (bspec RS ack_lt_mono2) 2);
lcp@515
   309
by (tc_tac [map_type]);
lcp@515
   310
val COMP_case = result();
lcp@515
   311
lcp@515
   312
(** PREC case **)
lcp@515
   313
lcp@515
   314
goalw Primrec.thy [PREC_def]
lcp@515
   315
 "!!f g. [| ALL l:list(nat). f`l #+ list_add(l) < ack(kf, list_add(l));	\
lcp@515
   316
\           ALL l:list(nat). g`l #+ list_add(l) < ack(kg, list_add(l));	\
lcp@515
   317
\           f: primrec;  kf: nat;					\
lcp@515
   318
\           g: primrec;  kg: nat;					\
lcp@515
   319
\           l: list(nat)						\
lcp@515
   320
\        |] ==> PREC(f,g)`l #+ list_add(l) < ack(succ(kf#+kg), list_add(l))";
lcp@515
   321
by (etac list.elim 1);
lcp@515
   322
by (asm_simp_tac (ack2_ss addsimps [[nat_le_refl, lt_ack2] MRS lt_trans]) 1);
lcp@515
   323
by (asm_simp_tac ack2_ss 1);
lcp@515
   324
by (etac ssubst 1);  (*get rid of the needless assumption*)
lcp@515
   325
by (eres_inst_tac [("n","a")] nat_induct 1);
lcp@515
   326
(*base case*)
lcp@515
   327
by (DO_GOAL [asm_simp_tac ack2_ss, rtac lt_trans, etac bspec,
lcp@515
   328
	     assume_tac, rtac (add_le_self RS ack_lt_mono1),
lcp@515
   329
	     REPEAT o ares_tac (ack_typechecks)] 1);
lcp@515
   330
(*ind step*)
lcp@515
   331
by (asm_simp_tac (ack2_ss addsimps [add_succ_right]) 1);
lcp@515
   332
by (rtac (succ_leI RS lt_trans1) 1);
lcp@515
   333
by (res_inst_tac [("j", "g ` ?ll #+ ?mm")] lt_trans1 1);
lcp@515
   334
by (etac bspec 2);
lcp@515
   335
by (rtac (nat_le_refl RS add_le_mono) 1);
lcp@515
   336
by (tc_tac []);
lcp@515
   337
by (asm_simp_tac (ack2_ss addsimps [add_le_self2]) 1);
lcp@515
   338
(*final part of the simplification*)
lcp@515
   339
by (asm_simp_tac ack2_ss 1);
lcp@515
   340
by (rtac (add_le_self2 RS ack_le_mono1 RS lt_trans1) 1);
lcp@515
   341
by (etac ack_lt_mono2 5);
lcp@515
   342
by (tc_tac []);
lcp@515
   343
val PREC_case_lemma = result();
lcp@515
   344
lcp@515
   345
goal Primrec.thy
lcp@515
   346
 "!!f g. [| f: primrec;  kf: nat;				\
lcp@515
   347
\           g: primrec;  kg: nat;				\
lcp@515
   348
\           ALL l:list(nat). f`l < ack(kf, list_add(l));	\
lcp@515
   349
\           ALL l:list(nat). g`l < ack(kg, list_add(l)) 	\
lcp@515
   350
\        |] ==> EX k:nat. ALL l: list(nat). 			\
lcp@515
   351
\		    PREC(f,g)`l< ack(k, list_add(l))";
lcp@515
   352
by (rtac (ballI RS bexI) 1);
lcp@515
   353
by (rtac ([add_le_self, PREC_case_lemma] MRS lt_trans1) 1);
lcp@515
   354
by (REPEAT
lcp@515
   355
    (SOMEGOAL
lcp@515
   356
     (FIRST' [test_assume_tac,
lcp@515
   357
	      match_tac (ack_typechecks),
lcp@515
   358
	      rtac (ack_add_bound2 RS ballI) THEN' etac bspec])));
lcp@515
   359
val PREC_case = result();
lcp@515
   360
lcp@515
   361
goal Primrec.thy
lcp@515
   362
    "!!f. f:primrec ==> EX k:nat. ALL l:list(nat). f`l < ack(k, list_add(l))";
lcp@515
   363
by (etac primrec.induct 1);
lcp@515
   364
by (safe_tac ZF_cs);
lcp@515
   365
by (DEPTH_SOLVE
lcp@515
   366
    (ares_tac ([SC_case, CONST_case, PROJ_case, COMP_case, PREC_case,
lcp@515
   367
		       bexI, ballI] @ nat_typechecks) 1));
lcp@515
   368
val ack_bounds_primrec = result();
lcp@515
   369
lcp@515
   370
goal Primrec.thy
lcp@515
   371
    "~ (lam l:list(nat). list_case(0, %x xs. ack(x,x), l)) : primrec";
lcp@515
   372
by (rtac notI 1);
lcp@515
   373
by (etac (ack_bounds_primrec RS bexE) 1);
lcp@515
   374
by (rtac lt_irrefl 1);
lcp@515
   375
by (dres_inst_tac [("x", "[x]")] bspec 1);
lcp@515
   376
by (asm_simp_tac ack2_ss 1);
lcp@515
   377
by (asm_full_simp_tac (ack2_ss addsimps [add_0_right]) 1);
lcp@515
   378
val ack_not_primrec = result();
lcp@515
   379