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