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