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