src/HOL/Wellfounded_Relations.ML
author nipkow
Wed Aug 18 11:09:40 2004 +0200 (2004-08-18)
changeset 15140 322485b816ac
parent 13867 1fdecd15437f
permissions -rw-r--r--
import -> imports
nipkow@10213
     1
(*  Title: 	HOL/Wellfounded_Relations
nipkow@10213
     2
    ID:         $Id$
nipkow@10213
     3
    Author: 	Konrad Slind
nipkow@10213
     4
    Copyright   1996  TU Munich
nipkow@10213
     5
nipkow@10213
     6
Derived WF relations: inverse image, lexicographic product, measure, ...
nipkow@10213
     7
*)
nipkow@10213
     8
nipkow@10213
     9
oheimb@11142
    10
section "`Less than' on the natural numbers";
nipkow@10213
    11
nipkow@10213
    12
Goalw [less_than_def] "wf less_than"; 
nipkow@10213
    13
by (rtac (wf_pred_nat RS wf_trancl) 1);
nipkow@10213
    14
qed "wf_less_than";
nipkow@10213
    15
AddIffs [wf_less_than];
nipkow@10213
    16
nipkow@10213
    17
Goalw [less_than_def] "trans less_than"; 
nipkow@10213
    18
by (rtac trans_trancl 1);
nipkow@10213
    19
qed "trans_less_than";
nipkow@10213
    20
AddIffs [trans_less_than];
nipkow@10213
    21
nipkow@10213
    22
Goalw [less_than_def, less_def] "((x,y): less_than) = (x<y)"; 
nipkow@10213
    23
by (Simp_tac 1);
nipkow@10213
    24
qed "less_than_iff";
nipkow@10213
    25
AddIffs [less_than_iff];
nipkow@10213
    26
nipkow@10213
    27
Goal "(!!n. (ALL m. Suc m <= n --> P m) ==> P n) ==> P n";
nipkow@10213
    28
by (rtac (wf_less_than RS wf_induct) 1);
nipkow@10213
    29
by (resolve_tac (premises()) 1);
nipkow@10213
    30
by Auto_tac;
nipkow@10213
    31
qed_spec_mp "full_nat_induct";
nipkow@10213
    32
nipkow@10213
    33
(*----------------------------------------------------------------------------
nipkow@10213
    34
 * The inverse image into a wellfounded relation is wellfounded.
nipkow@10213
    35
 *---------------------------------------------------------------------------*)
nipkow@10213
    36
nipkow@10213
    37
Goal "wf(r) ==> wf(inv_image r (f::'a=>'b))"; 
nipkow@10213
    38
by (full_simp_tac (simpset() addsimps [inv_image_def, wf_eq_minimal]) 1);
nipkow@10213
    39
by (Clarify_tac 1);
nipkow@10213
    40
by (subgoal_tac "EX (w::'b). w : {w. EX (x::'a). x: Q & (f x = w)}" 1);
nipkow@10213
    41
by (blast_tac (claset() delrules [allE]) 2);
nipkow@10213
    42
by (etac allE 1);
nipkow@10213
    43
by (mp_tac 1);
nipkow@10213
    44
by (Blast_tac 1);
nipkow@10213
    45
qed "wf_inv_image";
nipkow@13867
    46
Addsimps [wf_inv_image];
nipkow@10213
    47
AddSIs [wf_inv_image];
nipkow@10213
    48
nipkow@10213
    49
nipkow@10213
    50
(*----------------------------------------------------------------------------
nipkow@10213
    51
 * All measures are wellfounded.
nipkow@10213
    52
 *---------------------------------------------------------------------------*)
nipkow@10213
    53
nipkow@10213
    54
Goalw [measure_def] "wf (measure f)";
nipkow@10213
    55
by (rtac (wf_less_than RS wf_inv_image) 1);
nipkow@10213
    56
qed "wf_measure";
nipkow@10213
    57
AddIffs [wf_measure];
nipkow@10213
    58
nipkow@10213
    59
val measure_induct = standard
nipkow@10213
    60
    (asm_full_simplify (simpset() addsimps [measure_def,inv_image_def])
nipkow@10213
    61
      (wf_measure RS wf_induct));
nipkow@10213
    62
bind_thm ("measure_induct", measure_induct);
nipkow@10213
    63
nipkow@10213
    64
(*----------------------------------------------------------------------------
nipkow@10213
    65
 * Wellfoundedness of lexicographic combinations
nipkow@10213
    66
 *---------------------------------------------------------------------------*)
nipkow@10213
    67
nipkow@10213
    68
val [wfa,wfb] = goalw (the_context ()) [wf_def,lex_prod_def]
nipkow@10213
    69
 "[| wf(ra); wf(rb) |] ==> wf(ra <*lex*> rb)";
nipkow@10213
    70
by (EVERY1 [rtac allI,rtac impI]);
nipkow@10213
    71
by (simp_tac (HOL_basic_ss addsimps [split_paired_All]) 1);
nipkow@10213
    72
by (rtac (wfa RS spec RS mp) 1);
nipkow@10213
    73
by (EVERY1 [rtac allI,rtac impI]);
nipkow@10213
    74
by (rtac (wfb RS spec RS mp) 1);
nipkow@10213
    75
by (Blast_tac 1);
nipkow@10213
    76
qed "wf_lex_prod";
nipkow@10213
    77
AddSIs [wf_lex_prod];
nipkow@10213
    78
nipkow@10213
    79
(*---------------------------------------------------------------------------
nipkow@10213
    80
 * Transitivity of WF combinators.
nipkow@10213
    81
 *---------------------------------------------------------------------------*)
nipkow@10213
    82
Goalw [trans_def, lex_prod_def]
nipkow@10213
    83
    "!!R1 R2. [| trans R1; trans R2 |] ==> trans (R1 <*lex*> R2)";
nipkow@10213
    84
by (Simp_tac 1);
nipkow@10213
    85
by (Blast_tac 1);
nipkow@10213
    86
qed "trans_lex_prod";
nipkow@10213
    87
AddSIs [trans_lex_prod];
nipkow@10213
    88
nipkow@10213
    89
nipkow@10213
    90
(*---------------------------------------------------------------------------
nipkow@10213
    91
 * Wellfoundedness of proper subset on finite sets.
nipkow@10213
    92
 *---------------------------------------------------------------------------*)
nipkow@10213
    93
Goalw [finite_psubset_def] "wf(finite_psubset)";
nipkow@10213
    94
by (rtac (wf_measure RS wf_subset) 1);
nipkow@10213
    95
by (simp_tac (simpset() addsimps [measure_def, inv_image_def, less_than_def,
nipkow@10213
    96
				 symmetric less_def])1);
nipkow@10213
    97
by (fast_tac (claset() addSEs [psubset_card_mono]) 1);
nipkow@10213
    98
qed "wf_finite_psubset";
nipkow@10213
    99
nipkow@10213
   100
Goalw [finite_psubset_def, trans_def] "trans finite_psubset";
nipkow@10213
   101
by (simp_tac (simpset() addsimps [psubset_def]) 1);
nipkow@10213
   102
by (Blast_tac 1);
nipkow@10213
   103
qed "trans_finite_psubset";
nipkow@10213
   104
nipkow@10213
   105
(*---------------------------------------------------------------------------
nipkow@10213
   106
 * Wellfoundedness of finite acyclic relations
nipkow@10213
   107
 * Cannot go into WF because it needs Finite.
nipkow@10213
   108
 *---------------------------------------------------------------------------*)
nipkow@10213
   109
nipkow@10213
   110
Goal "finite r ==> acyclic r --> wf r";
nipkow@10213
   111
by (etac finite_induct 1);
nipkow@10213
   112
 by (Blast_tac 1);
nipkow@10213
   113
by (split_all_tac 1);
nipkow@10213
   114
by (Asm_full_simp_tac 1);
nipkow@10213
   115
qed_spec_mp "finite_acyclic_wf";
nipkow@10213
   116
nipkow@10213
   117
Goal "[|finite r; acyclic r|] ==> wf (r^-1)";
nipkow@10213
   118
by (etac (finite_converse RS iffD2 RS finite_acyclic_wf) 1);
nipkow@10213
   119
by (etac (acyclic_converse RS iffD2) 1);
nipkow@10213
   120
qed "finite_acyclic_wf_converse";
nipkow@10213
   121
nipkow@10213
   122
Goal "finite r ==> wf r = acyclic r";
nipkow@10213
   123
by (blast_tac (claset() addIs [finite_acyclic_wf,wf_acyclic]) 1);
nipkow@10213
   124
qed "wf_iff_acyclic_if_finite";
nipkow@10213
   125
nipkow@10213
   126
nipkow@10213
   127
(*----------------------------------------------------------------------------
nipkow@10213
   128
 * Weakly decreasing sequences (w.r.t. some well-founded order) stabilize.
nipkow@10213
   129
 *---------------------------------------------------------------------------*)
nipkow@10213
   130
nipkow@10213
   131
Goal "[| ALL i. (f (Suc i), f i) : r^* |] ==> (f (i+k), f i) : r^*";
nipkow@10213
   132
by (induct_tac "k" 1);
nipkow@10213
   133
 by (ALLGOALS Simp_tac);
nipkow@10213
   134
by (blast_tac (claset() addIs [rtrancl_trans]) 1);
nipkow@10213
   135
val lemma = result();
nipkow@10213
   136
nipkow@10213
   137
Goal "[| ALL i. (f (Suc i), f i) : r^*; wf (r^+) |] \
nipkow@10213
   138
\     ==> ALL m. f m = x --> (EX i. ALL k. f (m+i+k) = f (m+i))";
nipkow@10213
   139
by (etac wf_induct 1);
nipkow@10213
   140
by (Clarify_tac 1);
nipkow@10213
   141
by (case_tac "EX j. (f (m+j), f m) : r^+" 1);
nipkow@10213
   142
 by (Clarify_tac 1);
nipkow@10213
   143
 by (subgoal_tac "EX i. ALL k. f ((m+j)+i+k) = f ((m+j)+i)" 1);
nipkow@10213
   144
  by (Clarify_tac 1);
nipkow@10213
   145
  by (res_inst_tac [("x","j+i")] exI 1);
nipkow@10213
   146
  by (asm_full_simp_tac (simpset() addsimps add_ac) 1);
nipkow@10213
   147
 by (Blast_tac 1);
nipkow@10213
   148
by (res_inst_tac [("x","0")] exI 1);
nipkow@10213
   149
by (Clarsimp_tac 1);
nipkow@10213
   150
by (dres_inst_tac [("i","m"), ("k","k")] lemma 1);
nipkow@10213
   151
by (blast_tac (claset() addEs [rtranclE] addDs [rtrancl_into_trancl1]) 1);
nipkow@10213
   152
val lemma = result();
nipkow@10213
   153
nipkow@10213
   154
Goal "[| ALL i. (f (Suc i), f i) : r^*; wf (r^+) |] \
nipkow@10213
   155
\     ==> EX i. ALL k. f (i+k) = f i";
nipkow@10213
   156
by (dres_inst_tac [("x","0")] (lemma RS spec) 1);
nipkow@10213
   157
by Auto_tac;
nipkow@10213
   158
qed "wf_weak_decr_stable";
nipkow@10213
   159
paulson@11454
   160
(* special case of the theorem above: <= *)
nipkow@10213
   161
Goal "ALL i. f (Suc i) <= ((f i)::nat) ==> EX i. ALL k. f (i+k) = f i";
nipkow@10213
   162
by (res_inst_tac [("r","pred_nat")] wf_weak_decr_stable 1);
paulson@11454
   163
by (asm_simp_tac (simpset() addsimps [thm "pred_nat_trancl_eq_le"]) 1);
nipkow@10213
   164
by (REPEAT (resolve_tac [wf_trancl,wf_pred_nat] 1));
nipkow@10213
   165
qed "weak_decr_stable";
nipkow@10213
   166
nipkow@10213
   167
(*----------------------------------------------------------------------------
nipkow@10213
   168
 * Wellfoundedness of same_fst
nipkow@10213
   169
 *---------------------------------------------------------------------------*)
nipkow@10213
   170
oheimb@11167
   171
Goalw[same_fst_def] "[| P x; (y',y) : R x |] ==> ((x,y'),(x,y)) : same_fst P R";
oheimb@11167
   172
by (Asm_simp_tac 1);
oheimb@11167
   173
qed "same_fstI";
oheimb@11340
   174
AddSIs[same_fstI];
oheimb@11167
   175
nipkow@10213
   176
val prems = goalw thy [same_fst_def]
nipkow@10213
   177
  "(!!x. P x ==> wf(R x)) ==> wf(same_fst P R)";
wenzelm@12486
   178
by (full_simp_tac (simpset() delcongs [imp_cong] addsimps [wf_def]) 1);
wenzelm@12486
   179
by (strip_tac 1);
wenzelm@12486
   180
by (rename_tac "a b" 1);
wenzelm@12486
   181
by (case_tac "wf(R a)" 1);
nipkow@10213
   182
 by (eres_inst_tac [("a","b")] wf_induct 1);
wenzelm@12486
   183
 by (Blast_tac 1);
wenzelm@12486
   184
by (blast_tac (claset() addIs prems) 1);
nipkow@10653
   185
qed "wf_same_fst";