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