author | oheimb |
Thu, 15 Feb 2001 16:01:47 +0100 | |
changeset 11142 | 42181d7cd7b2 |
parent 10996 | 74e970389def |
child 11167 | 2c90a6167b0b |
permissions | -rw-r--r-- |
10213 | 1 |
(* Title: HOL/Wellfounded_Relations |
2 |
ID: $Id$ |
|
3 |
Author: Konrad Slind |
|
4 |
Copyright 1996 TU Munich |
|
5 |
||
6 |
Derived WF relations: inverse image, lexicographic product, measure, ... |
|
7 |
*) |
|
8 |
||
9 |
||
11142 | 10 |
section "`Less than' on the natural numbers"; |
10213 | 11 |
|
12 |
Goalw [less_than_def] "wf less_than"; |
|
13 |
by (rtac (wf_pred_nat RS wf_trancl) 1); |
|
14 |
qed "wf_less_than"; |
|
15 |
AddIffs [wf_less_than]; |
|
16 |
||
17 |
Goalw [less_than_def] "trans less_than"; |
|
18 |
by (rtac trans_trancl 1); |
|
19 |
qed "trans_less_than"; |
|
20 |
AddIffs [trans_less_than]; |
|
21 |
||
22 |
Goalw [less_than_def, less_def] "((x,y): less_than) = (x<y)"; |
|
23 |
by (Simp_tac 1); |
|
24 |
qed "less_than_iff"; |
|
25 |
AddIffs [less_than_iff]; |
|
26 |
||
27 |
Goal "(!!n. (ALL m. Suc m <= n --> P m) ==> P n) ==> P n"; |
|
28 |
by (rtac (wf_less_than RS wf_induct) 1); |
|
29 |
by (resolve_tac (premises()) 1); |
|
30 |
by Auto_tac; |
|
31 |
qed_spec_mp "full_nat_induct"; |
|
32 |
||
33 |
(*---------------------------------------------------------------------------- |
|
34 |
* The inverse image into a wellfounded relation is wellfounded. |
|
35 |
*---------------------------------------------------------------------------*) |
|
36 |
||
37 |
Goal "wf(r) ==> wf(inv_image r (f::'a=>'b))"; |
|
38 |
by (full_simp_tac (simpset() addsimps [inv_image_def, wf_eq_minimal]) 1); |
|
39 |
by (Clarify_tac 1); |
|
40 |
by (subgoal_tac "EX (w::'b). w : {w. EX (x::'a). x: Q & (f x = w)}" 1); |
|
41 |
by (blast_tac (claset() delrules [allE]) 2); |
|
42 |
by (etac allE 1); |
|
43 |
by (mp_tac 1); |
|
44 |
by (Blast_tac 1); |
|
45 |
qed "wf_inv_image"; |
|
46 |
AddSIs [wf_inv_image]; |
|
47 |
||
48 |
||
49 |
(*---------------------------------------------------------------------------- |
|
50 |
* All measures are wellfounded. |
|
51 |
*---------------------------------------------------------------------------*) |
|
52 |
||
53 |
Goalw [measure_def] "wf (measure f)"; |
|
54 |
by (rtac (wf_less_than RS wf_inv_image) 1); |
|
55 |
qed "wf_measure"; |
|
56 |
AddIffs [wf_measure]; |
|
57 |
||
58 |
val measure_induct = standard |
|
59 |
(asm_full_simplify (simpset() addsimps [measure_def,inv_image_def]) |
|
60 |
(wf_measure RS wf_induct)); |
|
61 |
bind_thm ("measure_induct", measure_induct); |
|
62 |
||
63 |
(*---------------------------------------------------------------------------- |
|
64 |
* Wellfoundedness of lexicographic combinations |
|
65 |
*---------------------------------------------------------------------------*) |
|
66 |
||
67 |
val [wfa,wfb] = goalw (the_context ()) [wf_def,lex_prod_def] |
|
68 |
"[| wf(ra); wf(rb) |] ==> wf(ra <*lex*> rb)"; |
|
69 |
by (EVERY1 [rtac allI,rtac impI]); |
|
70 |
by (simp_tac (HOL_basic_ss addsimps [split_paired_All]) 1); |
|
71 |
by (rtac (wfa RS spec RS mp) 1); |
|
72 |
by (EVERY1 [rtac allI,rtac impI]); |
|
73 |
by (rtac (wfb RS spec RS mp) 1); |
|
74 |
by (Blast_tac 1); |
|
75 |
qed "wf_lex_prod"; |
|
76 |
AddSIs [wf_lex_prod]; |
|
77 |
||
78 |
(*--------------------------------------------------------------------------- |
|
79 |
* Transitivity of WF combinators. |
|
80 |
*---------------------------------------------------------------------------*) |
|
81 |
Goalw [trans_def, lex_prod_def] |
|
82 |
"!!R1 R2. [| trans R1; trans R2 |] ==> trans (R1 <*lex*> R2)"; |
|
83 |
by (Simp_tac 1); |
|
84 |
by (Blast_tac 1); |
|
85 |
qed "trans_lex_prod"; |
|
86 |
AddSIs [trans_lex_prod]; |
|
87 |
||
88 |
||
89 |
(*--------------------------------------------------------------------------- |
|
90 |
* Wellfoundedness of proper subset on finite sets. |
|
91 |
*---------------------------------------------------------------------------*) |
|
92 |
Goalw [finite_psubset_def] "wf(finite_psubset)"; |
|
93 |
by (rtac (wf_measure RS wf_subset) 1); |
|
94 |
by (simp_tac (simpset() addsimps [measure_def, inv_image_def, less_than_def, |
|
95 |
symmetric less_def])1); |
|
96 |
by (fast_tac (claset() addSEs [psubset_card_mono]) 1); |
|
97 |
qed "wf_finite_psubset"; |
|
98 |
||
99 |
Goalw [finite_psubset_def, trans_def] "trans finite_psubset"; |
|
100 |
by (simp_tac (simpset() addsimps [psubset_def]) 1); |
|
101 |
by (Blast_tac 1); |
|
102 |
qed "trans_finite_psubset"; |
|
103 |
||
104 |
(*--------------------------------------------------------------------------- |
|
105 |
* Wellfoundedness of finite acyclic relations |
|
106 |
* Cannot go into WF because it needs Finite. |
|
107 |
*---------------------------------------------------------------------------*) |
|
108 |
||
109 |
Goal "finite r ==> acyclic r --> wf r"; |
|
110 |
by (etac finite_induct 1); |
|
111 |
by (Blast_tac 1); |
|
112 |
by (split_all_tac 1); |
|
113 |
by (Asm_full_simp_tac 1); |
|
114 |
qed_spec_mp "finite_acyclic_wf"; |
|
115 |
||
116 |
Goal "[|finite r; acyclic r|] ==> wf (r^-1)"; |
|
117 |
by (etac (finite_converse RS iffD2 RS finite_acyclic_wf) 1); |
|
118 |
by (etac (acyclic_converse RS iffD2) 1); |
|
119 |
qed "finite_acyclic_wf_converse"; |
|
120 |
||
121 |
Goal "finite r ==> wf r = acyclic r"; |
|
122 |
by (blast_tac (claset() addIs [finite_acyclic_wf,wf_acyclic]) 1); |
|
123 |
qed "wf_iff_acyclic_if_finite"; |
|
124 |
||
125 |
||
126 |
(*--------------------------------------------------------------------------- |
|
127 |
* A relation is wellfounded iff it has no infinite descending chain |
|
128 |
* Cannot go into WF because it needs type nat. |
|
129 |
*---------------------------------------------------------------------------*) |
|
130 |
||
131 |
Goalw [wf_eq_minimal RS eq_reflection] |
|
132 |
"wf r = (~(EX f. ALL i. (f(Suc i),f i) : r))"; |
|
133 |
by (rtac iffI 1); |
|
134 |
by (rtac notI 1); |
|
135 |
by (etac exE 1); |
|
136 |
by (eres_inst_tac [("x","{w. EX i. w=f i}")] allE 1); |
|
137 |
by (Blast_tac 1); |
|
10231 | 138 |
by (etac contrapos_np 1); |
10213 | 139 |
by (Asm_full_simp_tac 1); |
140 |
by (Clarify_tac 1); |
|
141 |
by (subgoal_tac "ALL n. nat_rec x (%i y. @z. z:Q & (z,y):r) n : Q" 1); |
|
142 |
by (res_inst_tac[("x","nat_rec x (%i y. @z. z:Q & (z,y):r)")]exI 1); |
|
143 |
by (rtac allI 1); |
|
144 |
by (Simp_tac 1); |
|
145 |
by (rtac someI2_ex 1); |
|
146 |
by (Blast_tac 1); |
|
147 |
by (Blast_tac 1); |
|
148 |
by (rtac allI 1); |
|
149 |
by (induct_tac "n" 1); |
|
150 |
by (Asm_simp_tac 1); |
|
151 |
by (Simp_tac 1); |
|
152 |
by (rtac someI2_ex 1); |
|
153 |
by (Blast_tac 1); |
|
154 |
by (Blast_tac 1); |
|
155 |
qed "wf_iff_no_infinite_down_chain"; |
|
156 |
||
157 |
(*---------------------------------------------------------------------------- |
|
158 |
* Weakly decreasing sequences (w.r.t. some well-founded order) stabilize. |
|
159 |
*---------------------------------------------------------------------------*) |
|
160 |
||
161 |
Goal "[| ALL i. (f (Suc i), f i) : r^* |] ==> (f (i+k), f i) : r^*"; |
|
162 |
by (induct_tac "k" 1); |
|
163 |
by (ALLGOALS Simp_tac); |
|
164 |
by (blast_tac (claset() addIs [rtrancl_trans]) 1); |
|
165 |
val lemma = result(); |
|
166 |
||
167 |
Goal "[| ALL i. (f (Suc i), f i) : r^*; wf (r^+) |] \ |
|
168 |
\ ==> ALL m. f m = x --> (EX i. ALL k. f (m+i+k) = f (m+i))"; |
|
169 |
by (etac wf_induct 1); |
|
170 |
by (Clarify_tac 1); |
|
171 |
by (case_tac "EX j. (f (m+j), f m) : r^+" 1); |
|
172 |
by (Clarify_tac 1); |
|
173 |
by (subgoal_tac "EX i. ALL k. f ((m+j)+i+k) = f ((m+j)+i)" 1); |
|
174 |
by (Clarify_tac 1); |
|
175 |
by (res_inst_tac [("x","j+i")] exI 1); |
|
176 |
by (asm_full_simp_tac (simpset() addsimps add_ac) 1); |
|
177 |
by (Blast_tac 1); |
|
178 |
by (res_inst_tac [("x","0")] exI 1); |
|
179 |
by (Clarsimp_tac 1); |
|
180 |
by (dres_inst_tac [("i","m"), ("k","k")] lemma 1); |
|
181 |
by (blast_tac (claset() addEs [rtranclE] addDs [rtrancl_into_trancl1]) 1); |
|
182 |
val lemma = result(); |
|
183 |
||
184 |
Goal "[| ALL i. (f (Suc i), f i) : r^*; wf (r^+) |] \ |
|
185 |
\ ==> EX i. ALL k. f (i+k) = f i"; |
|
186 |
by (dres_inst_tac [("x","0")] (lemma RS spec) 1); |
|
187 |
by Auto_tac; |
|
188 |
qed "wf_weak_decr_stable"; |
|
189 |
||
190 |
(* special case: <= *) |
|
191 |
||
192 |
Goal "(m, n) : pred_nat^* = (m <= n)"; |
|
10996
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
nipkow
parents:
10653
diff
changeset
|
193 |
by (simp_tac (simpset() addsimps [less_eq, thm"reflcl_trancl" RS sym] |
74e970389def
Moved some thms from Transitive_ClosureTr.ML to Transitive_Closure.thy
nipkow
parents:
10653
diff
changeset
|
194 |
delsimps [thm"reflcl_trancl"]) 1); |
10213 | 195 |
by (arith_tac 1); |
196 |
qed "le_eq"; |
|
197 |
||
198 |
Goal "ALL i. f (Suc i) <= ((f i)::nat) ==> EX i. ALL k. f (i+k) = f i"; |
|
199 |
by (res_inst_tac [("r","pred_nat")] wf_weak_decr_stable 1); |
|
200 |
by (asm_simp_tac (simpset() addsimps [le_eq]) 1); |
|
201 |
by (REPEAT (resolve_tac [wf_trancl,wf_pred_nat] 1)); |
|
202 |
qed "weak_decr_stable"; |
|
203 |
||
204 |
(*---------------------------------------------------------------------------- |
|
205 |
* Wellfoundedness of same_fst |
|
206 |
*---------------------------------------------------------------------------*) |
|
207 |
||
208 |
val prems = goalw thy [same_fst_def] |
|
209 |
"(!!x. P x ==> wf(R x)) ==> wf(same_fst P R)"; |
|
210 |
by(full_simp_tac (simpset() delcongs [imp_cong] addsimps [wf_def]) 1); |
|
211 |
by(strip_tac 1); |
|
212 |
by(rename_tac "a b" 1); |
|
213 |
by(case_tac "wf(R a)" 1); |
|
214 |
by (eres_inst_tac [("a","b")] wf_induct 1); |
|
215 |
by (EVERY1[etac allE, etac allE, etac mp, rtac allI, rtac allI]); |
|
216 |
by(Blast_tac 1); |
|
217 |
by(blast_tac (claset() addIs prems) 1); |
|
10653 | 218 |
qed "wf_same_fst"; |
11142 | 219 |
|
220 |
||
221 |
||
222 |
(* ### see also LEAST and wellorderings in Wellfounded_Recursion.ML *) |
|
223 |
||
224 |
Goal "wf r ==> !x y. ((x,y):r^+) = ((y,x)~:r^*) ==> \ |
|
225 |
\ P k ==> ? x. P x & (!y. P y --> (m x,m y):r^*)"; |
|
226 |
by (dtac (wf_trancl RS (wf_eq_minimal RS iffD1)) 1); |
|
227 |
by (dres_inst_tac [("x","m`Collect P")] spec 1); |
|
228 |
by (Force_tac 1); |
|
229 |
qed "wf_linord_ex_has_least"; |
|
230 |
||
231 |
(* successor of obsolete nonempty_has_least *) |
|
232 |
Goal "P k ==> ? x. P x & (!y. P y --> m x <= (m y::nat))"; |
|
233 |
by (simp_tac (HOL_basic_ss addsimps [le_eq RS sym]) 1); |
|
234 |
by (rtac (wf_pred_nat RS wf_linord_ex_has_least) 1); |
|
235 |
by (simp_tac (simpset() addsimps [less_eq,not_le_iff_less,le_eq]) 1); |
|
236 |
by (atac 1); |
|
237 |
qed "ex_has_least_nat"; |
|
238 |
||
239 |
Goalw [thm "LeastM_def"] |
|
240 |
"P k ==> P (LeastM m P) & (!y. P y --> m (LeastM m P) <= (m y::nat))"; |
|
241 |
by (rtac someI_ex 1); |
|
242 |
by (etac ex_has_least_nat 1); |
|
243 |
qed "LeastM_nat_lemma"; |
|
244 |
||
245 |
bind_thm ("LeastM_natI", LeastM_nat_lemma RS conjunct1); |
|
246 |
||
247 |
Goal "P x ==> m (LeastM m P) <= (m x::nat)"; |
|
248 |
by (rtac (LeastM_nat_lemma RS conjunct2 RS spec RS mp) 1); |
|
249 |
by (atac 1); |
|
250 |
by (atac 1); |
|
251 |
qed "LeastM_nat_le"; |
|
252 |