src/HOL/WF_Rel.ML
author wenzelm
Thu Jun 22 23:04:34 2000 +0200 (2000-06-22)
changeset 9108 9fff97d29837
parent 9076 108ec332625d
child 9163 4d624e34e19a
permissions -rw-r--r--
bind_thm(s);
paulson@3193
     1
(*  Title: 	HOL/WF_Rel
paulson@3193
     2
    ID:         $Id$
paulson@3193
     3
    Author: 	Konrad Slind
paulson@3193
     4
    Copyright   1996  TU Munich
paulson@3193
     5
paulson@3296
     6
Derived WF relations: inverse image, lexicographic product, measure, ...
paulson@3193
     7
*)
paulson@3193
     8
paulson@3193
     9
paulson@3193
    10
(*----------------------------------------------------------------------------
paulson@3237
    11
 * "Less than" on the natural numbers
paulson@3237
    12
 *---------------------------------------------------------------------------*)
paulson@3237
    13
wenzelm@5069
    14
Goalw [less_than_def] "wf less_than"; 
paulson@3237
    15
by (rtac (wf_pred_nat RS wf_trancl) 1);
paulson@3237
    16
qed "wf_less_than";
paulson@3237
    17
AddIffs [wf_less_than];
paulson@3237
    18
wenzelm@5069
    19
Goalw [less_than_def] "trans less_than"; 
paulson@3237
    20
by (rtac trans_trancl 1);
paulson@3237
    21
qed "trans_less_than";
paulson@3237
    22
AddIffs [trans_less_than];
paulson@3237
    23
wenzelm@5069
    24
Goalw [less_than_def, less_def] "((x,y): less_than) = (x<y)"; 
paulson@3237
    25
by (Simp_tac 1);
paulson@3237
    26
qed "less_than_iff";
paulson@3237
    27
AddIffs [less_than_iff];
paulson@3237
    28
oheimb@8158
    29
Goal "(!!n. (!m. Suc m <= n --> P m) ==> P n) ==> P n";
paulson@8254
    30
by (rtac (wf_less_than RS wf_induct) 1);
oheimb@8158
    31
by (resolve_tac (premises()) 1);
oheimb@8158
    32
by Auto_tac;
oheimb@8158
    33
qed_spec_mp "full_nat_induct";
oheimb@8158
    34
paulson@3237
    35
(*----------------------------------------------------------------------------
paulson@3193
    36
 * The inverse image into a wellfounded relation is wellfounded.
paulson@3193
    37
 *---------------------------------------------------------------------------*)
paulson@3193
    38
paulson@5143
    39
Goal "wf(r) ==> wf(inv_image r (f::'a=>'b))"; 
wenzelm@4089
    40
by (full_simp_tac (simpset() addsimps [inv_image_def, wf_eq_minimal]) 1);
paulson@3718
    41
by (Clarify_tac 1);
paulson@3193
    42
by (subgoal_tac "? (w::'b). w : {w. ? (x::'a). x: Q & (f x = w)}" 1);
wenzelm@4089
    43
by (blast_tac (claset() delrules [allE]) 2);
paulson@3193
    44
by (etac allE 1);
paulson@3193
    45
by (mp_tac 1);
paulson@3193
    46
by (Blast_tac 1);
paulson@3193
    47
qed "wf_inv_image";
paulson@3193
    48
AddSIs [wf_inv_image];
paulson@3193
    49
wenzelm@5069
    50
Goalw [trans_def,inv_image_def]
paulson@3237
    51
    "!!r. trans r ==> trans (inv_image r f)";
paulson@3237
    52
by (Simp_tac 1);
paulson@3237
    53
by (Blast_tac 1);
paulson@3237
    54
qed "trans_inv_image";
paulson@3237
    55
paulson@3237
    56
paulson@3193
    57
(*----------------------------------------------------------------------------
paulson@3193
    58
 * All measures are wellfounded.
paulson@3193
    59
 *---------------------------------------------------------------------------*)
paulson@3193
    60
wenzelm@5069
    61
Goalw [measure_def] "wf (measure f)";
paulson@3237
    62
by (rtac (wf_less_than RS wf_inv_image) 1);
paulson@3193
    63
qed "wf_measure";
paulson@3193
    64
AddIffs [wf_measure];
paulson@3193
    65
nipkow@4643
    66
val measure_induct = standard
nipkow@4643
    67
    (asm_full_simplify (simpset() addsimps [measure_def,inv_image_def])
nipkow@4643
    68
      (wf_measure RS wf_induct));
wenzelm@9108
    69
bind_thm ("measure_induct", measure_induct);
nipkow@4643
    70
paulson@3193
    71
(*----------------------------------------------------------------------------
paulson@3193
    72
 * Wellfoundedness of lexicographic combinations
paulson@3193
    73
 *---------------------------------------------------------------------------*)
paulson@3193
    74
paulson@3193
    75
val [wfa,wfb] = goalw thy [wf_def,lex_prod_def]
nipkow@8703
    76
 "[| wf(ra); wf(rb) |] ==> wf(ra <*lex*> rb)";
nipkow@3413
    77
by (EVERY1 [rtac allI,rtac impI]);
nipkow@3413
    78
by (simp_tac (HOL_basic_ss addsimps [split_paired_All]) 1);
paulson@3193
    79
by (rtac (wfa RS spec RS mp) 1);
paulson@3193
    80
by (EVERY1 [rtac allI,rtac impI]);
paulson@3193
    81
by (rtac (wfb RS spec RS mp) 1);
paulson@3193
    82
by (Blast_tac 1);
paulson@3193
    83
qed "wf_lex_prod";
paulson@3193
    84
AddSIs [wf_lex_prod];
paulson@3193
    85
paulson@3193
    86
(*---------------------------------------------------------------------------
paulson@3193
    87
 * Transitivity of WF combinators.
paulson@3193
    88
 *---------------------------------------------------------------------------*)
wenzelm@5069
    89
Goalw [trans_def, lex_prod_def]
nipkow@8703
    90
    "!!R1 R2. [| trans R1; trans R2 |] ==> trans (R1 <*lex*> R2)";
paulson@3193
    91
by (Simp_tac 1);
paulson@3193
    92
by (Blast_tac 1);
paulson@3193
    93
qed "trans_lex_prod";
paulson@3193
    94
AddSIs [trans_lex_prod];
paulson@3193
    95
paulson@3193
    96
paulson@3193
    97
(*---------------------------------------------------------------------------
paulson@3193
    98
 * Wellfoundedness of proper subset on finite sets.
paulson@3193
    99
 *---------------------------------------------------------------------------*)
wenzelm@5069
   100
Goalw [finite_psubset_def] "wf(finite_psubset)";
paulson@3193
   101
by (rtac (wf_measure RS wf_subset) 1);
wenzelm@4089
   102
by (simp_tac (simpset() addsimps [measure_def, inv_image_def, less_than_def,
paulson@3237
   103
				 symmetric less_def])1);
paulson@9076
   104
by (fast_tac (claset() addSEs [psubset_card_mono]) 1);
paulson@3193
   105
qed "wf_finite_psubset";
paulson@3193
   106
wenzelm@5069
   107
Goalw [finite_psubset_def, trans_def] "trans finite_psubset";
wenzelm@4089
   108
by (simp_tac (simpset() addsimps [psubset_def]) 1);
paulson@3237
   109
by (Blast_tac 1);
paulson@3237
   110
qed "trans_finite_psubset";
paulson@3193
   111
nipkow@3413
   112
(*---------------------------------------------------------------------------
nipkow@3413
   113
 * Wellfoundedness of finite acyclic relations
nipkow@5144
   114
 * Cannot go into WF because it needs Finite.
nipkow@3413
   115
 *---------------------------------------------------------------------------*)
nipkow@3413
   116
paulson@5143
   117
Goal "finite r ==> acyclic r --> wf r";
paulson@3457
   118
by (etac finite_induct 1);
paulson@3457
   119
 by (Blast_tac 1);
paulson@3457
   120
by (split_all_tac 1);
paulson@3457
   121
by (Asm_full_simp_tac 1);
nipkow@3413
   122
qed_spec_mp "finite_acyclic_wf";
nipkow@3413
   123
paulson@7031
   124
Goal "[|finite r; acyclic r|] ==> wf (r^-1)";
paulson@7031
   125
by (etac (finite_converse RS iffD2 RS finite_acyclic_wf) 1);
paulson@7031
   126
by (etac (acyclic_converse RS iffD2) 1);
paulson@7031
   127
qed "finite_acyclic_wf_converse";
oheimb@4749
   128
paulson@5143
   129
Goal "finite r ==> wf r = acyclic r";
wenzelm@4089
   130
by (blast_tac (claset() addIs [finite_acyclic_wf,wf_acyclic]) 1);
nipkow@3413
   131
qed "wf_iff_acyclic_if_finite";
nipkow@3413
   132
nipkow@3413
   133
nipkow@3413
   134
(*---------------------------------------------------------------------------
nipkow@3413
   135
 * A relation is wellfounded iff it has no infinite descending chain
nipkow@5144
   136
 * Cannot go into WF because it needs type nat.
nipkow@3413
   137
 *---------------------------------------------------------------------------*)
nipkow@3413
   138
wenzelm@5069
   139
Goalw [wf_eq_minimal RS eq_reflection]
nipkow@3413
   140
  "wf r = (~(? f. !i. (f(Suc i),f i) : r))";
paulson@3457
   141
by (rtac iffI 1);
paulson@3457
   142
 by (rtac notI 1);
paulson@3457
   143
 by (etac exE 1);
paulson@3457
   144
 by (eres_inst_tac [("x","{w. ? i. w=f i}")] allE 1);
paulson@3457
   145
 by (Blast_tac 1);
paulson@3457
   146
by (etac swap 1);
paulson@3446
   147
by (Asm_full_simp_tac 1);
paulson@3718
   148
by (Clarify_tac 1);
paulson@3457
   149
by (subgoal_tac "!n. nat_rec x (%i y. @z. z:Q & (z,y):r) n : Q" 1);
nipkow@3436
   150
 by (res_inst_tac[("x","nat_rec x (%i y. @z. z:Q & (z,y):r)")]exI 1);
paulson@3457
   151
 by (rtac allI 1);
paulson@3457
   152
 by (Simp_tac 1);
paulson@3457
   153
 by (rtac selectI2EX 1);
paulson@3457
   154
  by (Blast_tac 1);
paulson@3457
   155
 by (Blast_tac 1);
paulson@3457
   156
by (rtac allI 1);
paulson@3457
   157
by (induct_tac "n" 1);
paulson@3457
   158
 by (Asm_simp_tac 1);
paulson@3457
   159
by (Simp_tac 1);
paulson@3457
   160
by (rtac selectI2EX 1);
paulson@3457
   161
 by (Blast_tac 1);
paulson@3457
   162
by (Blast_tac 1);
nipkow@3413
   163
qed "wf_iff_no_infinite_down_chain";
nipkow@6803
   164
nipkow@6803
   165
(*----------------------------------------------------------------------------
nipkow@6803
   166
 * Weakly decreasing sequences (w.r.t. some well-founded order) stabilize.
nipkow@6803
   167
 *---------------------------------------------------------------------------*)
nipkow@6803
   168
nipkow@6803
   169
Goal "[| ! i. (f (Suc i), f i) : r^* |] ==> (f (i+k), f i) : r^*";
nipkow@6803
   170
by (induct_tac "k" 1);
nipkow@6803
   171
 by (ALLGOALS Simp_tac);
nipkow@6803
   172
by (blast_tac (claset() addIs [rtrancl_trans]) 1);
nipkow@6803
   173
val lemma = result();
nipkow@6803
   174
nipkow@6803
   175
Goal "[| ! i. (f (Suc i), f i) : r^*; wf (r^+) |] \
nipkow@6803
   176
\     ==> ! m. f m = x --> (? i. ! k. f (m+i+k) = f (m+i))";
nipkow@6803
   177
by (etac wf_induct 1);
nipkow@6803
   178
by (Clarify_tac 1);
nipkow@6803
   179
by (case_tac "? j. (f (m+j), f m) : r^+" 1);
nipkow@6803
   180
 by (Clarify_tac 1);
nipkow@6803
   181
 by (subgoal_tac "? i. ! k. f ((m+j)+i+k) = f ((m+j)+i)" 1);
nipkow@6803
   182
  by (Clarify_tac 1);
nipkow@6803
   183
  by (res_inst_tac [("x","j+i")] exI 1);
nipkow@6803
   184
  by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
nipkow@6803
   185
 by (Blast_tac 1);
nipkow@6803
   186
by (res_inst_tac [("x","0")] exI 1);
nipkow@6803
   187
by (Clarsimp_tac 1);
nipkow@6803
   188
by (dres_inst_tac [("i","m"), ("k","k")] lemma 1);
nipkow@6803
   189
by (fast_tac (claset() addDs [rtranclE,rtrancl_into_trancl1]) 1);
nipkow@6803
   190
val lemma = result();
nipkow@6803
   191
nipkow@6803
   192
Goal "[| ! i. (f (Suc i), f i) : r^*; wf (r^+) |] \
nipkow@6803
   193
\     ==> ? i. ! k. f (i+k) = f i";
nipkow@6803
   194
by (dres_inst_tac [("x","0")] (lemma RS spec) 1);
nipkow@6803
   195
by Auto_tac;
nipkow@6803
   196
qed "wf_weak_decr_stable";
nipkow@6803
   197
nipkow@6803
   198
(* special case: <= *)
nipkow@6803
   199
nipkow@6803
   200
Goal "(m, n) : pred_nat^* = (m <= n)";
nipkow@6803
   201
by (simp_tac (simpset() addsimps [less_eq, reflcl_trancl RS sym] 
nipkow@6803
   202
                        delsimps [reflcl_trancl]) 1);
nipkow@6803
   203
by (arith_tac 1);
nipkow@6803
   204
qed "le_eq";
nipkow@6803
   205
nipkow@6803
   206
Goal "[| ! i. f (Suc i) <= ((f i)::nat) |] ==> ? i. ! k. f (i+k) = f i";
nipkow@6803
   207
by (res_inst_tac [("r","pred_nat")] wf_weak_decr_stable 1);
nipkow@6803
   208
by (asm_simp_tac (simpset() addsimps [le_eq]) 1);
nipkow@6803
   209
by (REPEAT (resolve_tac [wf_trancl,wf_pred_nat] 1));
nipkow@6803
   210
qed "weak_decr_stable";