src/HOL/Wellfounded_Recursion.ML
author nipkow
Thu Oct 12 18:44:35 2000 +0200 (2000-10-12)
changeset 10213 01c2744a3786
child 10832 e33b47e4246d
permissions -rw-r--r--
*** empty log message ***
nipkow@10213
     1
(*  Title:      HOL/Wellfounded_Recursion.ML
nipkow@10213
     2
    ID:         $Id$
nipkow@10213
     3
    Author:     Tobias Nipkow, with minor changes by Konrad Slind
nipkow@10213
     4
    Copyright   1992  University of Cambridge/1995 TU Munich
nipkow@10213
     5
nipkow@10213
     6
Wellfoundedness, induction, and  recursion
nipkow@10213
     7
*)
nipkow@10213
     8
nipkow@10213
     9
Goal "x = y ==> H x z = H y z";
nipkow@10213
    10
by (Asm_simp_tac 1);
nipkow@10213
    11
val H_cong2 = (*freeze H!*)
nipkow@10213
    12
	      read_instantiate [("H","H")] (result());
nipkow@10213
    13
nipkow@10213
    14
val [prem] = Goalw [wf_def]
nipkow@10213
    15
 "(!!P x. (ALL x. (ALL y. (y,x) : r --> P(y)) --> P(x)) ==> P(x)) ==> wf(r)";
nipkow@10213
    16
by (Clarify_tac 1);
nipkow@10213
    17
by (rtac prem 1);
nipkow@10213
    18
by (assume_tac 1);
nipkow@10213
    19
qed "wfUNIVI";
nipkow@10213
    20
nipkow@10213
    21
(*Restriction to domain A.  If r is well-founded over A then wf(r)*)
nipkow@10213
    22
val [prem1,prem2] = Goalw [wf_def]
nipkow@10213
    23
 "[| r <= A <*> A;  \
nipkow@10213
    24
\    !!x P. [| ALL x. (ALL y. (y,x) : r --> P y) --> P x;  x:A |] ==> P x |]  \
nipkow@10213
    25
\ ==>  wf r";
nipkow@10213
    26
by (cut_facts_tac [prem1] 1);
nipkow@10213
    27
by (blast_tac (claset() addIs [prem2]) 1);
nipkow@10213
    28
qed "wfI";
nipkow@10213
    29
nipkow@10213
    30
val major::prems = Goalw [wf_def]
nipkow@10213
    31
    "[| wf(r);          \
nipkow@10213
    32
\       !!x.[| ALL y. (y,x): r --> P(y) |] ==> P(x) \
nipkow@10213
    33
\    |]  ==>  P(a)";
nipkow@10213
    34
by (rtac (major RS spec RS mp RS spec) 1);
nipkow@10213
    35
by (blast_tac (claset() addIs prems) 1);
nipkow@10213
    36
qed "wf_induct";
nipkow@10213
    37
nipkow@10213
    38
(*Perform induction on i, then prove the wf(r) subgoal using prems. *)
nipkow@10213
    39
fun wf_ind_tac a prems i = 
nipkow@10213
    40
    EVERY [res_inst_tac [("a",a)] wf_induct i,
nipkow@10213
    41
           rename_last_tac a ["1"] (i+1),
nipkow@10213
    42
           ares_tac prems i];
nipkow@10213
    43
nipkow@10213
    44
Goal "wf(r) ==> ALL x. (a,x):r --> (x,a)~:r";
nipkow@10213
    45
by (wf_ind_tac "a" [] 1);
nipkow@10213
    46
by (Blast_tac 1);
nipkow@10213
    47
qed_spec_mp "wf_not_sym";
nipkow@10213
    48
nipkow@10213
    49
(* [| wf r;  ~Z ==> (a,x) : r;  (x,a) ~: r ==> Z |] ==> Z *)
nipkow@10213
    50
bind_thm ("wf_asym", cla_make_elim wf_not_sym);
nipkow@10213
    51
nipkow@10213
    52
Goal "wf(r) ==> (a,a) ~: r";
nipkow@10213
    53
by (blast_tac (claset() addEs [wf_asym]) 1);
nipkow@10213
    54
qed "wf_not_refl";
nipkow@10213
    55
nipkow@10213
    56
(* [| wf r;  (a,a) ~: r ==> PROP W |] ==> PROP W *)
nipkow@10213
    57
bind_thm ("wf_irrefl", make_elim wf_not_refl);
nipkow@10213
    58
nipkow@10213
    59
(*transitive closure of a wf relation is wf! *)
nipkow@10213
    60
Goal "wf(r) ==> wf(r^+)";
nipkow@10213
    61
by (stac wf_def 1);
nipkow@10213
    62
by (Clarify_tac 1);
nipkow@10213
    63
(*must retain the universal formula for later use!*)
nipkow@10213
    64
by (rtac allE 1 THEN assume_tac 1);
nipkow@10213
    65
by (etac mp 1);
nipkow@10213
    66
by (eres_inst_tac [("a","x")] wf_induct 1);
nipkow@10213
    67
by (blast_tac (claset() addEs [tranclE]) 1);
nipkow@10213
    68
qed "wf_trancl";
nipkow@10213
    69
nipkow@10213
    70
Goal "wf (r^-1) ==> wf ((r^+)^-1)";
nipkow@10213
    71
by (stac (trancl_converse RS sym) 1);
nipkow@10213
    72
by (etac wf_trancl 1);
nipkow@10213
    73
qed "wf_converse_trancl";
nipkow@10213
    74
nipkow@10213
    75
nipkow@10213
    76
(*----------------------------------------------------------------------------
nipkow@10213
    77
 * Minimal-element characterization of well-foundedness
nipkow@10213
    78
 *---------------------------------------------------------------------------*)
nipkow@10213
    79
nipkow@10213
    80
Goalw [wf_def] "wf r ==> x:Q --> (EX z:Q. ALL y. (y,z):r --> y~:Q)";
nipkow@10213
    81
by (dtac spec 1);
nipkow@10213
    82
by (etac (mp RS spec) 1);
nipkow@10213
    83
by (Blast_tac 1);
nipkow@10213
    84
val lemma1 = result();
nipkow@10213
    85
nipkow@10213
    86
Goalw [wf_def] "(ALL Q x. x:Q --> (EX z:Q. ALL y. (y,z):r --> y~:Q)) ==> wf r";
nipkow@10213
    87
by (Clarify_tac 1);
nipkow@10213
    88
by (dres_inst_tac [("x", "{x. ~ P x}")] spec 1);
nipkow@10213
    89
by (Blast_tac 1);
nipkow@10213
    90
val lemma2 = result();
nipkow@10213
    91
nipkow@10213
    92
Goal "wf r = (ALL Q x. x:Q --> (EX z:Q. ALL y. (y,z):r --> y~:Q))";
nipkow@10213
    93
by (blast_tac (claset() addSIs [lemma1, lemma2]) 1);
nipkow@10213
    94
qed "wf_eq_minimal";
nipkow@10213
    95
nipkow@10213
    96
(*---------------------------------------------------------------------------
nipkow@10213
    97
 * Wellfoundedness of subsets
nipkow@10213
    98
 *---------------------------------------------------------------------------*)
nipkow@10213
    99
nipkow@10213
   100
Goal "[| wf(r);  p<=r |] ==> wf(p)";
nipkow@10213
   101
by (full_simp_tac (simpset() addsimps [wf_eq_minimal]) 1);
nipkow@10213
   102
by (Fast_tac 1);
nipkow@10213
   103
qed "wf_subset";
nipkow@10213
   104
nipkow@10213
   105
(*---------------------------------------------------------------------------
nipkow@10213
   106
 * Wellfoundedness of the empty relation.
nipkow@10213
   107
 *---------------------------------------------------------------------------*)
nipkow@10213
   108
nipkow@10213
   109
Goal "wf({})";
nipkow@10213
   110
by (simp_tac (simpset() addsimps [wf_def]) 1);
nipkow@10213
   111
qed "wf_empty";
nipkow@10213
   112
AddIffs [wf_empty];
nipkow@10213
   113
nipkow@10213
   114
(*---------------------------------------------------------------------------
nipkow@10213
   115
 * Wellfoundedness of `insert'
nipkow@10213
   116
 *---------------------------------------------------------------------------*)
nipkow@10213
   117
nipkow@10213
   118
Goal "wf(insert (y,x) r) = (wf(r) & (x,y) ~: r^*)";
nipkow@10213
   119
by (rtac iffI 1);
nipkow@10213
   120
 by (blast_tac (claset() addEs [wf_trancl RS wf_irrefl] 
nipkow@10213
   121
	addIs [rtrancl_into_trancl1,wf_subset,impOfSubs rtrancl_mono]) 1);
nipkow@10213
   122
by (asm_full_simp_tac (simpset() addsimps [wf_eq_minimal]) 1);
nipkow@10213
   123
by Safe_tac;
nipkow@10213
   124
by (EVERY1[rtac allE, assume_tac, etac impE, Blast_tac]);
nipkow@10213
   125
by (etac bexE 1);
nipkow@10213
   126
by (rename_tac "a" 1);
nipkow@10213
   127
by (case_tac "a = x" 1);
nipkow@10213
   128
 by (res_inst_tac [("x","a")]bexI 2);
nipkow@10213
   129
  by (assume_tac 3);
nipkow@10213
   130
 by (Blast_tac 2);
nipkow@10213
   131
by (case_tac "y:Q" 1);
nipkow@10213
   132
 by (Blast_tac 2);
nipkow@10213
   133
by (res_inst_tac [("x","{z. z:Q & (z,y) : r^*}")] allE 1);
nipkow@10213
   134
 by (assume_tac 1);
nipkow@10213
   135
by (thin_tac "ALL Q. (EX x. x : Q) --> ?P Q" 1);	(*essential for speed*)
nipkow@10213
   136
(*Blast_tac with new substOccur fails*)
nipkow@10213
   137
by (best_tac (claset() addIs [rtrancl_into_rtrancl2]) 1);
nipkow@10213
   138
qed "wf_insert";
nipkow@10213
   139
AddIffs [wf_insert];
nipkow@10213
   140
nipkow@10213
   141
(*---------------------------------------------------------------------------
nipkow@10213
   142
 * Wellfoundedness of `disjoint union'
nipkow@10213
   143
 *---------------------------------------------------------------------------*)
nipkow@10213
   144
nipkow@10213
   145
(*Intuition behind this proof for the case of binary union:
nipkow@10213
   146
nipkow@10213
   147
  Goal: find an (R u S)-min element of a nonempty subset A.
nipkow@10213
   148
  by case distinction:
nipkow@10213
   149
  1. There is a step a -R-> b with a,b : A.
nipkow@10213
   150
     Pick an R-min element z of the (nonempty) set {a:A | EX b:A. a -R-> b}.
nipkow@10213
   151
     By definition, there is z':A s.t. z -R-> z'. Because z is R-min in the
nipkow@10213
   152
     subset, z' must be R-min in A. Because z' has an R-predecessor, it cannot
nipkow@10213
   153
     have an S-successor and is thus S-min in A as well.
nipkow@10213
   154
  2. There is no such step.
nipkow@10213
   155
     Pick an S-min element of A. In this case it must be an R-min
nipkow@10213
   156
     element of A as well.
nipkow@10213
   157
nipkow@10213
   158
*)
nipkow@10213
   159
nipkow@10213
   160
Goal "[| ALL i:I. wf(r i); \
nipkow@10213
   161
\        ALL i:I. ALL j:I. r i ~= r j --> Domain(r i) Int Range(r j) = {} & \
nipkow@10213
   162
\                                         Domain(r j) Int Range(r i) = {} \
nipkow@10213
   163
\     |] ==> wf(UN i:I. r i)";
nipkow@10213
   164
by (asm_full_simp_tac (HOL_basic_ss addsimps [wf_eq_minimal]) 1);
nipkow@10213
   165
by (Clarify_tac 1);
nipkow@10213
   166
by (rename_tac "A a" 1);
nipkow@10213
   167
by (case_tac "EX i:I. EX a:A. EX b:A. (b,a) : r i" 1);
nipkow@10213
   168
 by (Asm_full_simp_tac 2);
nipkow@10213
   169
 by (Best_tac 2);  (*much faster than Blast_tac*)
nipkow@10213
   170
by (Clarify_tac 1);
nipkow@10213
   171
by (EVERY1[dtac bspec, assume_tac,
nipkow@10213
   172
	   eres_inst_tac [("x","{a. a:A & (EX b:A. (b,a) : r i)}")] allE]);
nipkow@10213
   173
by (EVERY1[etac allE, etac impE]);
nipkow@10213
   174
 by (ALLGOALS Blast_tac);
nipkow@10213
   175
qed "wf_UN";
nipkow@10213
   176
nipkow@10213
   177
Goalw [Union_def]
nipkow@10213
   178
 "[| ALL r:R. wf r; \
nipkow@10213
   179
\    ALL r:R. ALL s:R. r ~= s --> Domain r Int Range s = {} & \
nipkow@10213
   180
\                                 Domain s Int Range r = {} \
nipkow@10213
   181
\ |] ==> wf(Union R)";
nipkow@10213
   182
by (blast_tac (claset() addIs [wf_UN]) 1);
nipkow@10213
   183
qed "wf_Union";
nipkow@10213
   184
nipkow@10213
   185
Goal "[| wf r; wf s; Domain r Int Range s = {}; Domain s Int Range r = {} \
nipkow@10213
   186
\     |] ==> wf(r Un s)";
nipkow@10213
   187
by (rtac (simplify (simpset()) (read_instantiate[("R","{r,s}")]wf_Union)) 1);
nipkow@10213
   188
by (Blast_tac 1);
nipkow@10213
   189
by (Blast_tac 1);
nipkow@10213
   190
qed "wf_Un";
nipkow@10213
   191
nipkow@10213
   192
(*---------------------------------------------------------------------------
nipkow@10213
   193
 * Wellfoundedness of `image'
nipkow@10213
   194
 *---------------------------------------------------------------------------*)
nipkow@10213
   195
nipkow@10213
   196
Goal "[| wf r; inj f |] ==> wf(prod_fun f f `` r)";
nipkow@10213
   197
by (asm_full_simp_tac (HOL_basic_ss addsimps [wf_eq_minimal]) 1);
nipkow@10213
   198
by (Clarify_tac 1);
nipkow@10213
   199
by (case_tac "EX p. f p : Q" 1);
nipkow@10213
   200
by (eres_inst_tac [("x","{p. f p : Q}")]allE 1);
nipkow@10213
   201
by (fast_tac (claset() addDs [injD]) 1);
nipkow@10213
   202
by (Blast_tac 1);
nipkow@10213
   203
qed "wf_prod_fun_image";
nipkow@10213
   204
nipkow@10213
   205
(*** acyclic ***)
nipkow@10213
   206
nipkow@10213
   207
Goalw [acyclic_def] "ALL x. (x, x) ~: r^+ ==> acyclic r";
nipkow@10213
   208
by (assume_tac 1);
nipkow@10213
   209
qed "acyclicI";
nipkow@10213
   210
nipkow@10213
   211
Goalw [acyclic_def] "wf r ==> acyclic r";
nipkow@10213
   212
by (blast_tac (claset() addEs [wf_trancl RS wf_irrefl]) 1);
nipkow@10213
   213
qed "wf_acyclic";
nipkow@10213
   214
nipkow@10213
   215
Goalw [acyclic_def] "acyclic(insert (y,x) r) = (acyclic r & (x,y) ~: r^*)";
nipkow@10213
   216
by (simp_tac (simpset() addsimps [trancl_insert]) 1);
nipkow@10213
   217
by (blast_tac (claset() addIs [rtrancl_trans]) 1);
nipkow@10213
   218
qed "acyclic_insert";
nipkow@10213
   219
AddIffs [acyclic_insert];
nipkow@10213
   220
nipkow@10213
   221
Goalw [acyclic_def] "acyclic(r^-1) = acyclic r";
nipkow@10213
   222
by (simp_tac (simpset() addsimps [trancl_converse]) 1);
nipkow@10213
   223
qed "acyclic_converse";
nipkow@10213
   224
AddIffs [acyclic_converse];
nipkow@10213
   225
nipkow@10213
   226
Goalw [acyclic_def,antisym_def] "acyclic r ==> antisym(r^*)";
nipkow@10213
   227
by(blast_tac (claset() addEs [rtranclE]
nipkow@10213
   228
     addIs [rtrancl_into_trancl1,rtrancl_trancl_trancl]) 1);
nipkow@10213
   229
qed "acyclic_impl_antisym_rtrancl";
nipkow@10213
   230
nipkow@10213
   231
(* Other direction:
nipkow@10213
   232
acyclic = no loops
nipkow@10213
   233
antisym = only self loops
nipkow@10213
   234
Goalw [acyclic_def,antisym_def] "antisym(r^* ) ==> acyclic(r - Id)";
nipkow@10213
   235
==> "antisym(r^* ) = acyclic(r - Id)";
nipkow@10213
   236
*)
nipkow@10213
   237
nipkow@10213
   238
Goalw [acyclic_def] "[| acyclic s; r <= s |] ==> acyclic r";
nipkow@10213
   239
by (blast_tac (claset() addIs [trancl_mono]) 1);
nipkow@10213
   240
qed "acyclic_subset";
nipkow@10213
   241
nipkow@10213
   242
(** cut **)
nipkow@10213
   243
nipkow@10213
   244
(*This rewrite rule works upon formulae; thus it requires explicit use of
nipkow@10213
   245
  H_cong to expose the equality*)
nipkow@10213
   246
Goalw [cut_def] "(cut f r x = cut g r x) = (ALL y. (y,x):r --> f(y)=g(y))";
nipkow@10213
   247
by (simp_tac (HOL_ss addsimps [expand_fun_eq]) 1);
nipkow@10213
   248
qed "cuts_eq";
nipkow@10213
   249
nipkow@10213
   250
Goalw [cut_def] "(x,a):r ==> (cut f r a)(x) = f(x)";
nipkow@10213
   251
by (asm_simp_tac HOL_ss 1);
nipkow@10213
   252
qed "cut_apply";
nipkow@10213
   253
nipkow@10213
   254
(*** is_recfun ***)
nipkow@10213
   255
nipkow@10213
   256
Goalw [is_recfun_def,cut_def]
nipkow@10213
   257
    "[| is_recfun r H a f;  ~(b,a):r |] ==> f(b) = arbitrary";
nipkow@10213
   258
by (etac ssubst 1);
nipkow@10213
   259
by (asm_simp_tac HOL_ss 1);
nipkow@10213
   260
qed "is_recfun_undef";
nipkow@10213
   261
nipkow@10213
   262
(*** NOTE! some simplifications need a different Solver!! ***)
nipkow@10213
   263
fun indhyp_tac hyps =
nipkow@10213
   264
    (cut_facts_tac hyps THEN'
nipkow@10213
   265
       DEPTH_SOLVE_1 o (ares_tac [TrueI] ORELSE'
nipkow@10213
   266
                        eresolve_tac [transD, mp, allE]));
nipkow@10213
   267
val wf_super_ss = HOL_ss addSolver (mk_solver "WF" indhyp_tac);
nipkow@10213
   268
nipkow@10213
   269
Goalw [is_recfun_def,cut_def]
nipkow@10213
   270
    "[| wf(r);  trans(r);  is_recfun r H a f;  is_recfun r H b g |] ==> \
nipkow@10213
   271
    \ (x,a):r --> (x,b):r --> f(x)=g(x)";
nipkow@10213
   272
by (etac wf_induct 1);
nipkow@10213
   273
by (REPEAT (rtac impI 1 ORELSE etac ssubst 1));
nipkow@10213
   274
by (asm_simp_tac (wf_super_ss addcongs [if_cong]) 1);
nipkow@10213
   275
qed_spec_mp "is_recfun_equal";
nipkow@10213
   276
nipkow@10213
   277
nipkow@10213
   278
val prems as [wfr,transr,recfa,recgb,_] = goalw (the_context ()) [cut_def]
nipkow@10213
   279
    "[| wf(r);  trans(r); \
nipkow@10213
   280
\       is_recfun r H a f;  is_recfun r H b g;  (b,a):r |] ==> \
nipkow@10213
   281
\    cut f r b = g";
nipkow@10213
   282
val gundef = recgb RS is_recfun_undef
nipkow@10213
   283
and fisg   = recgb RS (recfa RS (transr RS (wfr RS is_recfun_equal)));
nipkow@10213
   284
by (cut_facts_tac prems 1);
nipkow@10213
   285
by (rtac ext 1);
nipkow@10213
   286
by (asm_simp_tac (wf_super_ss addsimps [gundef,fisg]) 1);
nipkow@10213
   287
qed "is_recfun_cut";
nipkow@10213
   288
nipkow@10213
   289
(*** Main Existence Lemma -- Basic Properties of the_recfun ***)
nipkow@10213
   290
nipkow@10213
   291
Goalw [the_recfun_def]
nipkow@10213
   292
    "is_recfun r H a f ==> is_recfun r H a (the_recfun r H a)";
nipkow@10213
   293
by (eres_inst_tac [("P", "is_recfun r H a")] someI 1);
nipkow@10213
   294
qed "is_the_recfun";
nipkow@10213
   295
nipkow@10213
   296
Goal "[| wf(r);  trans(r) |] ==> is_recfun r H a (the_recfun r H a)";
nipkow@10213
   297
by (wf_ind_tac "a" [] 1);
nipkow@10213
   298
by (res_inst_tac [("f","cut (%y. H (the_recfun r H y) y) r a1")]
nipkow@10213
   299
                 is_the_recfun 1);
nipkow@10213
   300
by (rewtac is_recfun_def);
nipkow@10213
   301
by (stac cuts_eq 1);
nipkow@10213
   302
by (Clarify_tac 1);
nipkow@10213
   303
by (rtac H_cong2 1);
nipkow@10213
   304
by (subgoal_tac
nipkow@10213
   305
         "the_recfun r H y = cut(%x. H(cut(the_recfun r H y) r x) x) r y" 1);
nipkow@10213
   306
 by (Blast_tac 2);
nipkow@10213
   307
by (etac ssubst 1);
nipkow@10213
   308
by (simp_tac (HOL_ss addsimps [cuts_eq]) 1);
nipkow@10213
   309
by (Clarify_tac 1);
nipkow@10213
   310
by (stac cut_apply 1);
nipkow@10213
   311
 by (fast_tac (claset() addDs [transD]) 1);
nipkow@10213
   312
by (fold_tac [is_recfun_def]);
nipkow@10213
   313
by (asm_simp_tac (wf_super_ss addsimps[is_recfun_cut]) 1);
nipkow@10213
   314
qed "unfold_the_recfun";
nipkow@10213
   315
nipkow@10213
   316
Goal "[| wf r; trans r; (x,a) : r; (x,b) : r |] \
nipkow@10213
   317
\     ==> the_recfun r H a x = the_recfun r H b x";
nipkow@10213
   318
by (best_tac (claset() addIs [is_recfun_equal, unfold_the_recfun]) 1);
nipkow@10213
   319
qed "the_recfun_equal";
nipkow@10213
   320
nipkow@10213
   321
(** Removal of the premise trans(r) **)
nipkow@10213
   322
val th = rewrite_rule[is_recfun_def]
nipkow@10213
   323
                     (trans_trancl RSN (2,(wf_trancl RS unfold_the_recfun)));
nipkow@10213
   324
nipkow@10213
   325
Goalw [wfrec_def]
nipkow@10213
   326
    "wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a";
nipkow@10213
   327
by (rtac H_cong2 1);
nipkow@10213
   328
by (simp_tac (HOL_ss addsimps [cuts_eq]) 1);
nipkow@10213
   329
by (rtac allI 1);
nipkow@10213
   330
by (rtac impI 1);
nipkow@10213
   331
by (res_inst_tac [("a1","a")] (th RS ssubst) 1);
nipkow@10213
   332
by (assume_tac 1);
nipkow@10213
   333
by (ftac wf_trancl 1);
nipkow@10213
   334
by (ftac r_into_trancl 1);
nipkow@10213
   335
by (asm_simp_tac (HOL_ss addsimps [cut_apply]) 1);
nipkow@10213
   336
by (rtac H_cong2 1);    (*expose the equality of cuts*)
nipkow@10213
   337
by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1);
nipkow@10213
   338
by (blast_tac (claset() addIs [the_recfun_equal, transD, trans_trancl, 
nipkow@10213
   339
			       r_into_trancl]) 1);
nipkow@10213
   340
qed "wfrec";
nipkow@10213
   341
nipkow@10213
   342
(*---------------------------------------------------------------------------
nipkow@10213
   343
 * This form avoids giant explosions in proofs.  NOTE USE OF == 
nipkow@10213
   344
 *---------------------------------------------------------------------------*)
nipkow@10213
   345
Goal "[| f==wfrec r H;  wf(r) |] ==> f(a) = H (cut f r a) a";
nipkow@10213
   346
by Auto_tac;
nipkow@10213
   347
by (blast_tac (claset() addIs [wfrec]) 1);   
nipkow@10213
   348
qed "def_wfrec";
nipkow@10213
   349
nipkow@10213
   350
nipkow@10213
   351
(**** TFL variants ****)
nipkow@10213
   352
nipkow@10213
   353
Goal "ALL R. wf R --> \
nipkow@10213
   354
\      (ALL P. (ALL x. (ALL y. (y,x):R --> P y) --> P x) --> (ALL x. P x))";
nipkow@10213
   355
by (Clarify_tac 1);
nipkow@10213
   356
by (res_inst_tac [("r","R"),("P","P"), ("a","x")] wf_induct 1);
nipkow@10213
   357
by (assume_tac 1);
nipkow@10213
   358
by (Blast_tac 1);
nipkow@10213
   359
qed"tfl_wf_induct";
nipkow@10213
   360
nipkow@10213
   361
Goal "ALL f R. (x,a):R --> (cut f R a)(x) = f(x)";
nipkow@10213
   362
by (Clarify_tac 1);
nipkow@10213
   363
by (rtac cut_apply 1);
nipkow@10213
   364
by (assume_tac 1);
nipkow@10213
   365
qed"tfl_cut_apply";
nipkow@10213
   366
nipkow@10213
   367
Goal "ALL M R f. (f=wfrec R M) --> wf R --> (ALL x. f x = M (cut f R x) x)";
nipkow@10213
   368
by (Clarify_tac 1);
nipkow@10213
   369
by (etac wfrec 1);
nipkow@10213
   370
qed "tfl_wfrec";