src/ZF/wf.ML
author paulson
Fri, 11 Aug 2000 13:26:40 +0200
changeset 9577 9e66e8ed8237
parent 6 8ce8c4d13d4d
permissions -rw-r--r--
ZF arith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	ZF/wf.ML
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Tobias Nipkow and Lawrence C Paulson
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1992  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
For wf.thy.  Well-founded Recursion
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
Derived first for transitive relations, and finally for arbitrary WF relations
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
via wf_trancl and trans_trancl.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
It is difficult to derive this general case directly, using r^+ instead of
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
r.  In is_recfun, the two occurrences of the relation must have the same
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
form.  Inserting r^+ in the_recfun or wftrec yields a recursion rule with
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
r^+ -`` {a} instead of r-``{a}.  This recursion rule is stronger in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
principle, but harder to use, especially to prove wfrec_eclose_eq in
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
epsilon.ML.  Expanding out the definition of wftrec in wfrec would yield
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
a mess.
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
open WF;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
(*** Well-founded relations ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
(*Are these two theorems at all useful??*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
(*If every subset of field(r) possesses an r-minimal element then wf(r).
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
  Seems impossible to prove this for domain(r) or range(r) instead...
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
  Consider in particular finite wf relations!*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
val [prem1,prem2] = goalw WF.thy [wf_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
    "[| field(r)<=A;  \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
\       !!Z u. [| Z<=A;  u:Z;  ALL x:Z. EX y:Z. <y,x>:r |] ==> False |] \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
\    ==>  wf(r)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
by (rtac (equals0I RS disjCI RS allI) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
by (rtac prem2 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
by (res_inst_tac [ ("B1", "Z") ] (prem1 RS (Int_lower1 RS subset_trans)) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
by (fast_tac ZF_cs 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
by (fast_tac ZF_cs 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
val wfI = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
(*If r allows well-founded induction then wf(r)*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
val [prem1,prem2] = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
    "[| field(r)<=A;  \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
\       !!B. ALL x:A. (ALL y. <y,x>: r --> y:B) --> x:B ==> A<=B |]  \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
\    ==>  wf(r)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
by (rtac (prem1 RS wfI) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
by (res_inst_tac [ ("B", "A-Z") ] (prem2 RS subsetCE) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
by (fast_tac ZF_cs 3);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
by (fast_tac ZF_cs 2);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
by (fast_tac ZF_cs 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
val wfI2 = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
(** Well-founded Induction **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    56
(*Consider the least z in domain(r) Un {a} such that P(z) does not hold...*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
val major::prems = goalw WF.thy [wf_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
    "[| wf(r);          \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    59
\       !!x.[| ALL y. <y,x>: r --> P(y) |] ==> P(x) \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
\    |]  ==>  P(a)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
by (res_inst_tac [ ("x", "{z:domain(r) Un {a}. ~P(z)}") ]  (major RS allE) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
by (etac disjE 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
by (rtac classical 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
by (etac equals0D 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
by (etac (singletonI RS UnI2 RS CollectI) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
by (etac bexE 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
by (etac CollectE 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
by (etac swap 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
by (resolve_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    70
by (fast_tac ZF_cs 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
val wf_induct = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    72
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    73
(*Perform induction on i, then prove the wf(r) subgoal using prems. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
fun wf_ind_tac a prems i = 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
    EVERY [res_inst_tac [("a",a)] wf_induct i,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
	   rename_last_tac a ["1"] (i+1),
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
	   ares_tac prems i];
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    78
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    79
(*The form of this rule is designed to match wfI2*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
val wfr::amem::prems = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
    "[| wf(r);  a:A;  field(r)<=A;  \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
\       !!x.[| x: A;  ALL y. <y,x>: r --> P(y) |] ==> P(x) \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
\    |]  ==>  P(a)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    84
by (rtac (amem RS rev_mp) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    85
by (wf_ind_tac "a" [wfr] 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    86
by (rtac impI 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
by (eresolve_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
by (fast_tac (ZF_cs addIs (prems RL [subsetD])) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
val wf_induct2 = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
val prems = goal WF.thy "[| wf(r);  <a,x>:r;  <x,a>:r |] ==> False";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
by (subgoal_tac "ALL x. <a,x>:r --> <x,a>:r --> False" 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
by (wf_ind_tac "a" prems 2);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
by (fast_tac ZF_cs 2);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
by (fast_tac (FOL_cs addIs prems) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    96
val wf_anti_sym = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
(*transitive closure of a WF relation is WF!*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    99
val [prem] = goal WF.thy "wf(r) ==> wf(r^+)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
by (rtac (trancl_type RS field_rel_subset RS wfI2) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   101
by (rtac subsetI 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
(*must retain the universal formula for later use!*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
by (rtac (bspec RS mp) 1 THEN assume_tac 1 THEN assume_tac 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
by (eres_inst_tac [("a","x")] (prem RS wf_induct2) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   105
by (rtac subset_refl 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   106
by (rtac (impI RS allI) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   107
by (etac tranclE 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
by (etac (bspec RS mp) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
by (etac fieldI1 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   110
by (fast_tac ZF_cs 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
by (fast_tac ZF_cs 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
val wf_trancl = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   114
(** r-``{a} is the set of everything under a in r **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   115
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
val underI = standard (vimage_singleton_iff RS iffD2);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
val underD = standard (vimage_singleton_iff RS iffD1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   119
(** is_recfun **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
val [major] = goalw WF.thy [is_recfun_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
    "is_recfun(r,a,H,f) ==> f: r-``{a} -> range(f)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   123
by (rtac (major RS ssubst) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
by (rtac (lamI RS rangeI RS lam_type) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
by (assume_tac 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
val is_recfun_type = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
val [isrec,rel] = goalw WF.thy [is_recfun_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
    "[| is_recfun(r,a,H,f); <x,a>:r |] ==> f`x = H(x, restrict(f,r-``{x}))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   130
by (res_inst_tac [("P", "%x.?t(x) = ?u::i")] (isrec RS ssubst) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
by (rtac (rel RS underI RS beta) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   132
val apply_recfun = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   133
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   134
(*eresolve_tac transD solves <a,b>:r using transitivity AT MOST ONCE
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   135
  spec RS mp  instantiates induction hypotheses*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   136
fun indhyp_tac hyps =
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   137
    resolve_tac (TrueI::refl::hyps) ORELSE' 
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   138
    (cut_facts_tac hyps THEN'
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   139
       DEPTH_SOLVE_1 o (ares_tac [TrueI, ballI] ORELSE'
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   140
		        eresolve_tac [underD, transD, spec RS mp]));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   141
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   142
(*** NOTE! some simplifications need a different solver!! ***)
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   143
val wf_super_ss = ZF_ss setsolver indhyp_tac;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   144
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   145
val prems = goalw WF.thy [is_recfun_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   146
    "[| wf(r);  trans(r);  is_recfun(r,a,H,f);  is_recfun(r,b,H,g) |] ==> \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   147
\    <x,a>:r --> <x,b>:r --> f`x=g`x";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   148
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   149
by (wf_ind_tac "x" prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   150
by (REPEAT (rtac impI 1 ORELSE etac ssubst 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   151
by (rewtac restrict_def);
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   152
by (asm_simp_tac (wf_super_ss addsimps [vimage_singleton_iff]) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   153
val is_recfun_equal_lemma = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   154
val is_recfun_equal = standard (is_recfun_equal_lemma RS mp RS mp);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   155
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   156
val prems as [wfr,transr,recf,recg,_] = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   157
    "[| wf(r);  trans(r);       \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   158
\       is_recfun(r,a,H,f);  is_recfun(r,b,H,g);  <b,a>:r |] ==> \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   159
\    restrict(f, r-``{b}) = g";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   160
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   161
by (rtac (consI1 RS restrict_type RS fun_extension) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   162
by (etac is_recfun_type 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   163
by (ALLGOALS
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   164
    (asm_simp_tac (wf_super_ss addsimps
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
		   [ [wfr,transr,recf,recg] MRS is_recfun_equal ])));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
val is_recfun_cut = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   167
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   168
(*** Main Existence Lemma ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   169
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   170
val prems = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   171
    "[| wf(r); trans(r); is_recfun(r,a,H,f); is_recfun(r,a,H,g) |]  ==>  f=g";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   172
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   173
by (rtac fun_extension 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   174
by (REPEAT (ares_tac [is_recfun_equal] 1
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   175
     ORELSE eresolve_tac [is_recfun_type,underD] 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   176
val is_recfun_functional = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   177
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   178
(*If some f satisfies is_recfun(r,a,H,-) then so does the_recfun(r,a,H) *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   179
val prems = goalw WF.thy [the_recfun_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   180
    "[| is_recfun(r,a,H,f);  wf(r);  trans(r) |]  \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   181
\    ==> is_recfun(r, a, H, the_recfun(r,a,H))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   182
by (rtac (ex1I RS theI) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
by (REPEAT (ares_tac (prems@[is_recfun_functional]) 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   184
val is_the_recfun = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   185
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   186
val prems = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   187
    "[| wf(r);  trans(r) |] ==> is_recfun(r, a, H, the_recfun(r,a,H))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   188
by (cut_facts_tac prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   189
by (wf_ind_tac "a" prems 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   190
by (res_inst_tac [("f", "lam y: r-``{a1}. wftrec(r,y,H)")] is_the_recfun 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   191
by (REPEAT (assume_tac 2));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   192
by (rewrite_goals_tac [is_recfun_def, wftrec_def]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   193
(*Applying the substitution: must keep the quantified assumption!!*)
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   194
by (REPEAT (dtac underD 1 ORELSE resolve_tac [refl, lam_cong] 1));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   195
by (fold_tac [is_recfun_def]);
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   196
by (rtac (consI1 RS restrict_type RSN (2,fun_extension) RS subst_context) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   197
by (rtac is_recfun_type 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   198
by (ALLGOALS
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   199
    (asm_simp_tac
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   200
     (wf_super_ss addsimps [underI RS beta, apply_recfun, is_recfun_cut])));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
val unfold_the_recfun = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   202
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   203
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   204
(*** Unfolding wftrec ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   205
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   206
val prems = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   207
    "[| wf(r);  trans(r);  <b,a>:r |] ==> \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   208
\    restrict(the_recfun(r,a,H), r-``{b}) = the_recfun(r,b,H)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   209
by (REPEAT (ares_tac (prems @ [is_recfun_cut, unfold_the_recfun]) 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
val the_recfun_cut = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   211
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
(*NOT SUITABLE FOR REWRITING since it is recursive!*)
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   213
goalw WF.thy [wftrec_def]
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   214
    "!!r. [| wf(r);  trans(r) |] ==> \
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   215
\         wftrec(r,a,H) = H(a, lam x: r-``{a}. wftrec(r,x,H))";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   216
by (rtac (rewrite_rule [is_recfun_def] unfold_the_recfun RS ssubst) 1);
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   217
by (ALLGOALS (asm_simp_tac
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   218
	(ZF_ss addsimps [vimage_singleton_iff RS iff_sym, the_recfun_cut])));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   219
val wftrec = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   220
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
(** Removal of the premise trans(r) **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   222
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   223
(*NOT SUITABLE FOR REWRITING since it is recursive!*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   224
val [wfr] = goalw WF.thy [wfrec_def]
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   225
    "wf(r) ==> wfrec(r,a,H) = H(a, lam x:r-``{a}. wfrec(r,x,H))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   226
by (rtac (wfr RS wf_trancl RS wftrec RS ssubst) 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   227
by (rtac trans_trancl 1);
6
8ce8c4d13d4d Installation of new simplifier for ZF. Deleted all congruence rules not
lcp
parents: 0
diff changeset
   228
by (rtac (vimage_pair_mono RS restrict_lam_eq RS subst_context) 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   229
by (etac r_into_trancl 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   230
by (rtac subset_refl 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   231
val wfrec = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   232
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   233
(*This form avoids giant explosions in proofs.  NOTE USE OF == *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   234
val rew::prems = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   235
    "[| !!x. h(x)==wfrec(r,x,H);  wf(r) |] ==> \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   236
\    h(a) = H(a, lam x: r-``{a}. h(x))";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   237
by (rewtac rew);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   238
by (REPEAT (resolve_tac (prems@[wfrec]) 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   239
val def_wfrec = result();
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   240
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   241
val prems = goal WF.thy
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   242
    "[| wf(r);  a:A;  field(r)<=A;  \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   243
\       !!x u. [| x: A;  u: Pi(r-``{x}, B) |] ==> H(x,u) : B(x)   \
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   244
\    |] ==> wfrec(r,a,H) : B(a)";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   245
by (res_inst_tac [("a","a")] wf_induct2 1);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   246
by (rtac (wfrec RS ssubst) 4);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   247
by (REPEAT (ares_tac (prems@[lam_type]) 1
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   248
     ORELSE eresolve_tac [spec RS mp, underD] 1));
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   249
val wfrec_type = result();