author  paulson 
Tue, 18 Aug 1998 10:24:54 +0200  
changeset 5330  8c9fadda81f4 
parent 5318  72bf8039b53f 
child 5337  2f7d09a927c4 
permissions  rwrr 
1475  1 
(* Title: HOL/wf.ML 
923  2 
ID: $Id$ 
1475  3 
Author: Tobias Nipkow, with minor changes by Konrad Slind 
4 
Copyright 1992 University of Cambridge/1995 TU Munich 

923  5 

3198  6 
Wellfoundedness, induction, and recursion 
923  7 
*) 
8 

9 
open WF; 

10 

950  11 
val H_cong = read_instantiate [("f","H")] (standard(refl RS cong RS cong)); 
923  12 
val H_cong1 = refl RS H_cong; 
13 

14 
(*Restriction to domain A. If r is wellfounded over A then wf(r)*) 

5316  15 
val [prem1,prem2] = Goalw [wf_def] 
1642  16 
"[ r <= A Times A; \ 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
950
diff
changeset

17 
\ !!x P. [ ! x. (! y. (y,x) : r > P(y)) > P(x); x:A ] ==> P(x) ] \ 
923  18 
\ ==> wf(r)"; 
3708  19 
by (Clarify_tac 1); 
923  20 
by (rtac allE 1); 
21 
by (assume_tac 1); 

4089  22 
by (best_tac (claset() addSEs [prem1 RS subsetD RS SigmaE2] addIs [prem2]) 1); 
923  23 
qed "wfI"; 
24 

5316  25 
val major::prems = Goalw [wf_def] 
923  26 
"[ wf(r); \ 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
950
diff
changeset

27 
\ !!x.[ ! y. (y,x): r > P(y) ] ==> P(x) \ 
923  28 
\ ] ==> P(a)"; 
29 
by (rtac (major RS spec RS mp RS spec) 1); 

4089  30 
by (blast_tac (claset() addIs prems) 1); 
923  31 
qed "wf_induct"; 
32 

33 
(*Perform induction on i, then prove the wf(r) subgoal using prems. *) 

34 
fun wf_ind_tac a prems i = 

35 
EVERY [res_inst_tac [("a",a)] wf_induct i, 

1465  36 
rename_last_tac a ["1"] (i+1), 
37 
ares_tac prems i]; 

923  38 

5316  39 
Goal "[ wf(r); (a,x):r; (x,a):r ] ==> P"; 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
950
diff
changeset

40 
by (subgoal_tac "! x. (a,x):r > (x,a):r > P" 1); 
5316  41 
by (Blast_tac 1); 
42 
by (wf_ind_tac "a" [] 1); 

2935  43 
by (Blast_tac 1); 
923  44 
qed "wf_asym"; 
45 

5316  46 
Goal "[ wf(r); (a,a): r ] ==> P"; 
47 
by (blast_tac (claset() addEs [wf_asym]) 1); 

1618  48 
qed "wf_irrefl"; 
923  49 

1475  50 
(*transitive closure of a wf relation is wf! *) 
5316  51 
Goal "wf(r) ==> wf(r^+)"; 
52 
by (stac wf_def 1); 

3708  53 
by (Clarify_tac 1); 
923  54 
(*must retain the universal formula for later use!*) 
55 
by (rtac allE 1 THEN assume_tac 1); 

56 
by (etac mp 1); 

5316  57 
by (eres_inst_tac [("a","x")] wf_induct 1); 
923  58 
by (rtac (impI RS allI) 1); 
59 
by (etac tranclE 1); 

2935  60 
by (Blast_tac 1); 
61 
by (Blast_tac 1); 

923  62 
qed "wf_trancl"; 
63 

64 

4762  65 
val wf_converse_trancl = prove_goal thy 
66 
"!!X. wf (r^1) ==> wf ((r^+)^1)" (K [ 

67 
stac (trancl_converse RS sym) 1, 

68 
etac wf_trancl 1]); 

69 

3198  70 
(* 
71 
* Minimalelement characterization of wellfoundedness 

72 
**) 

73 

5316  74 
Goalw [wf_def] "wf r ==> x:Q > (? z:Q. ! y. (y,z):r > y~:Q)"; 
5318  75 
by (dtac spec 1); 
5316  76 
by (etac (mp RS spec) 1); 
3198  77 
by (Blast_tac 1); 
78 
val lemma1 = result(); 

79 

5316  80 
Goalw [wf_def] "(! Q x. x:Q > (? z:Q. ! y. (y,z):r > y~:Q)) ==> wf r"; 
3708  81 
by (Clarify_tac 1); 
3198  82 
by (dres_inst_tac [("x", "{x. ~ P x}")] spec 1); 
83 
by (Blast_tac 1); 

84 
val lemma2 = result(); 

85 

5069  86 
Goal "wf r = (! Q x. x:Q > (? z:Q. ! y. (y,z):r > y~:Q))"; 
4089  87 
by (blast_tac (claset() addSIs [lemma1, lemma2]) 1); 
3198  88 
qed "wf_eq_minimal"; 
89 

3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

90 
(* 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

91 
* Wellfoundedness of subsets 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

92 
**) 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

93 

5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset

94 
Goal "[ wf(r); p<=r ] ==> wf(p)"; 
4089  95 
by (full_simp_tac (simpset() addsimps [wf_eq_minimal]) 1); 
3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

96 
by (Fast_tac 1); 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

97 
qed "wf_subset"; 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

98 

c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

99 
(* 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

100 
* Wellfoundedness of the empty relation. 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

101 
**) 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

102 

5069  103 
Goal "wf({})"; 
4089  104 
by (simp_tac (simpset() addsimps [wf_def]) 1); 
3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

105 
qed "wf_empty"; 
5281  106 
AddIffs [wf_empty]; 
3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

107 

c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

108 
(* 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

109 
* Wellfoundedness of `insert' 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

110 
**) 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

111 

5069  112 
Goal "wf(insert (y,x) r) = (wf(r) & (x,y) ~: r^*)"; 
3457  113 
by (rtac iffI 1); 
4350
1983e4054fd8
updated for latest Blast_tac, which treats equality differently
paulson
parents:
4153
diff
changeset

114 
by (blast_tac (claset() addEs [wf_trancl RS wf_irrefl] 
1983e4054fd8
updated for latest Blast_tac, which treats equality differently
paulson
parents:
4153
diff
changeset

115 
addIs [rtrancl_into_trancl1,wf_subset,impOfSubs rtrancl_mono]) 1); 
4089  116 
by (asm_full_simp_tac (simpset() addsimps [wf_eq_minimal]) 1); 
4153  117 
by Safe_tac; 
3457  118 
by (EVERY1[rtac allE, atac, etac impE, Blast_tac]); 
119 
by (etac bexE 1); 

120 
by (rename_tac "a" 1); 

121 
by (case_tac "a = x" 1); 

122 
by (res_inst_tac [("x","a")]bexI 2); 

123 
by (assume_tac 3); 

124 
by (Blast_tac 2); 

125 
by (case_tac "y:Q" 1); 

126 
by (Blast_tac 2); 

4059  127 
by (res_inst_tac [("x","{z. z:Q & (z,y) : r^*}")] allE 1); 
3457  128 
by (assume_tac 1); 
4059  129 
by (thin_tac "! Q. (? x. x : Q) > ?P Q" 1); (*essential for speed*) 
4350
1983e4054fd8
updated for latest Blast_tac, which treats equality differently
paulson
parents:
4153
diff
changeset

130 
(*Blast_tac with new substOccur fails*) 
1983e4054fd8
updated for latest Blast_tac, which treats equality differently
paulson
parents:
4153
diff
changeset

131 
by (best_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); 
3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

132 
qed "wf_insert"; 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

133 
AddIffs [wf_insert]; 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

134 

5281  135 
(* 
136 
* Wellfoundedness of `disjoint union' 

137 
**) 

138 

5330  139 
(*Intuition behind this proof for the case of binary union: 
140 

141 
Goal: find an (R u S)min element of a nonempty subset A. 

142 
by case distinction: 

143 
1. There is a step a R> b with a,b : A. 

144 
Pick an Rmin element z of the (nonempty) set {a:A  EX b:A. a R> b}. 

145 
By definition, there is z':A s.t. z R> z'. Because z is Rmin in the 

146 
subset, z' must be Rmin in A. Because z' has an Rpredecessor, it cannot 

147 
have an Ssuccessor and is thus Smin in A as well. 

148 
2. There is no such step. 

149 
Pick an Smin element of A. In this case it must be an Rmin 

150 
element of A as well. 

151 

152 
*) 

153 

5316  154 
Goal "[ !i:I. wf(r i); \ 
155 
\ !i:I.!j:I. r i ~= r j > Domain(r i) Int Range(r j) = {} & \ 

156 
\ Domain(r j) Int Range(r i) = {} \ 

157 
\ ] ==> wf(UN i:I. r i)"; 

5318  158 
by (asm_full_simp_tac (HOL_basic_ss addsimps [wf_eq_minimal]) 1); 
159 
by (Clarify_tac 1); 

160 
by (rename_tac "A a" 1); 

161 
by (case_tac "? i:I. ? a:A. ? b:A. (b,a) : r i" 1); 

162 
by (Clarify_tac 1); 

163 
by (EVERY1[dtac bspec, atac, 

5281  164 
eres_inst_tac[("x","{a. a:A & (? b:A. (b,a) : r i)}")]allE]); 
5318  165 
by (EVERY1[etac allE,etac impE]); 
166 
by (Blast_tac 1); 

167 
by (Clarify_tac 1); 

168 
by (rename_tac "z'" 1); 

169 
by (res_inst_tac [("x","z'")] bexI 1); 

170 
by (assume_tac 2); 

171 
by (Clarify_tac 1); 

172 
by (rename_tac "j" 1); 

173 
by (case_tac "r j = r i" 1); 

174 
by (EVERY1[etac allE,etac impE,atac]); 

175 
by (Asm_full_simp_tac 1); 

176 
by (Blast_tac 1); 

177 
by (blast_tac (claset() addEs [equalityE]) 1); 

178 
by (Asm_full_simp_tac 1); 

179 
by (case_tac "? i. i:I" 1); 

180 
by (Clarify_tac 1); 

181 
by (EVERY1[dtac bspec, atac, eres_inst_tac[("x","A")]allE]); 

182 
by (Blast_tac 1); 

183 
by (Blast_tac 1); 

5281  184 
qed "wf_UN"; 
185 

186 
Goalw [Union_def] 

187 
"[ !r:R. wf r; \ 

188 
\ !r:R.!s:R. r ~= s > Domain r Int Range s = {} & \ 

189 
\ Domain s Int Range r = {} \ 

190 
\ ] ==> wf(Union R)"; 

5318  191 
by (rtac wf_UN 1); 
192 
by (Blast_tac 1); 

193 
by (Blast_tac 1); 

5281  194 
qed "wf_Union"; 
195 

5316  196 
Goal "[ wf r; wf s; Domain r Int Range s = {}; Domain s Int Range r = {} \ 
197 
\ ] ==> wf(r Un s)"; 

5318  198 
by (rtac (simplify (simpset()) (read_instantiate[("R","{r,s}")]wf_Union)) 1); 
199 
by (Blast_tac 1); 

200 
by (Blast_tac 1); 

5281  201 
qed "wf_Un"; 
202 

203 
(* 

204 
* Wellfoundedness of `image' 

205 
**) 

206 

207 
Goal "[ wf r; inj f ] ==> wf(prod_fun f f `` r)"; 

5318  208 
by (asm_full_simp_tac (HOL_basic_ss addsimps [wf_eq_minimal]) 1); 
209 
by (Clarify_tac 1); 

210 
by (case_tac "? p. f p : Q" 1); 

211 
by (eres_inst_tac [("x","{p. f p : Q}")]allE 1); 

212 
by (fast_tac (claset() addDs [injD]) 1); 

213 
by (Blast_tac 1); 

5281  214 
qed "wf_prod_fun_image"; 
215 

3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

216 
(*** acyclic ***) 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

217 

4750  218 
val acyclicI = prove_goalw WF.thy [acyclic_def] 
219 
"!!r. !x. (x, x) ~: r^+ ==> acyclic r" (K [atac 1]); 

220 

5069  221 
Goalw [acyclic_def] 
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset

222 
"wf r ==> acyclic r"; 
4089  223 
by (blast_tac (claset() addEs [wf_trancl RS wf_irrefl]) 1); 
3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

224 
qed "wf_acyclic"; 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

225 

5069  226 
Goalw [acyclic_def] 
3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

227 
"acyclic(insert (y,x) r) = (acyclic r & (x,y) ~: r^*)"; 
4089  228 
by (simp_tac (simpset() addsimps [trancl_insert]) 1); 
229 
by (blast_tac (claset() addEs [make_elim rtrancl_trans]) 1); 

3413
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

230 
qed "acyclic_insert"; 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

231 
AddIffs [acyclic_insert]; 
c1f63cc3a768
Finite.ML Finite.thy: Replaced `finite subset of' by mere `finite'.
nipkow
parents:
3320
diff
changeset

232 

5069  233 
Goalw [acyclic_def] "acyclic(r^1) = acyclic r"; 
4746  234 
by (simp_tac (simpset() addsimps [trancl_converse]) 1); 
235 
qed "acyclic_converse"; 

3198  236 

923  237 
(** cut **) 
238 

239 
(*This rewrite rule works upon formulae; thus it requires explicit use of 

240 
H_cong to expose the equality*) 

5069  241 
Goalw [cut_def] 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
950
diff
changeset

242 
"(cut f r x = cut g r x) = (!y. (y,x):r > f(y)=g(y))"; 
4686  243 
by (simp_tac (HOL_ss addsimps [expand_fun_eq]) 1); 
1475  244 
qed "cuts_eq"; 
923  245 

5143
b94cd208f073
Removal of leading "\!\!..." from most Goal commands
paulson
parents:
5132
diff
changeset

246 
Goalw [cut_def] "(x,a):r ==> (cut f r a)(x) = f(x)"; 
1552  247 
by (asm_simp_tac HOL_ss 1); 
923  248 
qed "cut_apply"; 
249 

250 
(*** is_recfun ***) 

251 

5069  252 
Goalw [is_recfun_def,cut_def] 
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset

253 
"[ is_recfun r H a f; ~(b,a):r ] ==> f(b) = arbitrary"; 
923  254 
by (etac ssubst 1); 
1552  255 
by (asm_simp_tac HOL_ss 1); 
923  256 
qed "is_recfun_undef"; 
257 

258 
(*** NOTE! some simplifications need a different finish_tac!! ***) 

259 
fun indhyp_tac hyps = 

260 
(cut_facts_tac hyps THEN' 

261 
DEPTH_SOLVE_1 o (ares_tac [TrueI] ORELSE' 

1465  262 
eresolve_tac [transD, mp, allE])); 
2637
e9b203f854ae
reflecting my recent changes of the simplifier and classical reasoner
oheimb
parents:
2031
diff
changeset

263 
val wf_super_ss = HOL_ss addSolver indhyp_tac; 
923  264 

5316  265 
Goalw [is_recfun_def,cut_def] 
1475  266 
"[ wf(r); trans(r); is_recfun r H a f; is_recfun r H b g ] ==> \ 
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
950
diff
changeset

267 
\ (x,a):r > (x,b):r > f(x)=g(x)"; 
923  268 
by (etac wf_induct 1); 
269 
by (REPEAT (rtac impI 1 ORELSE etac ssubst 1)); 

270 
by (asm_simp_tac (wf_super_ss addcongs [if_cong]) 1); 

1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset

271 
qed_spec_mp "is_recfun_equal"; 
923  272 

273 

274 
val prems as [wfr,transr,recfa,recgb,_] = goalw WF.thy [cut_def] 

275 
"[ wf(r); trans(r); \ 

1475  276 
\ is_recfun r H a f; is_recfun r H b g; (b,a):r ] ==> \ 
923  277 
\ cut f r b = g"; 
278 
val gundef = recgb RS is_recfun_undef 

279 
and fisg = recgb RS (recfa RS (transr RS (wfr RS is_recfun_equal))); 

280 
by (cut_facts_tac prems 1); 

281 
by (rtac ext 1); 

4686  282 
by (asm_simp_tac (wf_super_ss addsimps [gundef,fisg]) 1); 
923  283 
qed "is_recfun_cut"; 
284 

285 
(*** Main Existence Lemma  Basic Properties of the_recfun ***) 

286 

5316  287 
Goalw [the_recfun_def] 
1475  288 
"is_recfun r H a f ==> is_recfun r H a (the_recfun r H a)"; 
5316  289 
by (eres_inst_tac [("P", "is_recfun r H a")] selectI 1); 
923  290 
qed "is_the_recfun"; 
291 

5316  292 
Goal "[ wf(r); trans(r) ] ==> is_recfun r H a (the_recfun r H a)"; 
293 
by (wf_ind_tac "a" [] 1); 

4821  294 
by (res_inst_tac [("f","cut (%y. H (the_recfun r H y) y) r a1")] 
295 
is_the_recfun 1); 

296 
by (rewtac is_recfun_def); 

297 
by (stac cuts_eq 1); 

298 
by (Clarify_tac 1); 

299 
by (rtac (refl RSN (2,H_cong)) 1); 

300 
by (subgoal_tac 

1475  301 
"the_recfun r H y = cut(%x. H(cut(the_recfun r H y) r x) x) r y" 1); 
4821  302 
by (etac allE 2); 
303 
by (dtac impE 2); 

304 
by (atac 2); 

1475  305 
by (atac 3); 
4821  306 
by (atac 2); 
307 
by (etac ssubst 1); 

308 
by (simp_tac (HOL_ss addsimps [cuts_eq]) 1); 

309 
by (Clarify_tac 1); 

310 
by (stac cut_apply 1); 

5132  311 
by (fast_tac (claset() addDs [transD]) 1); 
4821  312 
by (rtac (refl RSN (2,H_cong)) 1); 
313 
by (fold_tac [is_recfun_def]); 

314 
by (asm_simp_tac (wf_super_ss addsimps[is_recfun_cut]) 1); 

923  315 
qed "unfold_the_recfun"; 
316 

1475  317 
val unwind1_the_recfun = rewrite_rule[is_recfun_def] unfold_the_recfun; 
923  318 

1475  319 
(*Old proof 
5316  320 
val prems = Goal 
1475  321 
"[ wf(r); trans(r) ] ==> is_recfun r H a (the_recfun r H a)"; 
322 
by (cut_facts_tac prems 1); 

323 
by (wf_ind_tac "a" prems 1); 

324 
by (res_inst_tac [("f", "cut (%y. wftrec r H y) r a1")] is_the_recfun 1); 

325 
by (rewrite_goals_tac [is_recfun_def, wftrec_def]); 

2031  326 
by (stac cuts_eq 1); 
1475  327 
(*Applying the substitution: must keep the quantified assumption!!*) 
3708  328 
by (EVERY1 [Clarify_tac, rtac H_cong1, rtac allE, atac, 
1475  329 
etac (mp RS ssubst), atac]); 
330 
by (fold_tac [is_recfun_def]); 

331 
by (asm_simp_tac (wf_super_ss addsimps[cut_apply,is_recfun_cut,cuts_eq]) 1); 

332 
qed "unfold_the_recfun"; 

333 
*) 

923  334 

335 
(** Removal of the premise trans(r) **) 

1475  336 
val th = rewrite_rule[is_recfun_def] 
337 
(trans_trancl RSN (2,(wf_trancl RS unfold_the_recfun))); 

923  338 

5069  339 
Goalw [wfrec_def] 
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset

340 
"wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a"; 
1475  341 
by (rtac H_cong 1); 
342 
by (rtac refl 2); 

343 
by (simp_tac (HOL_ss addsimps [cuts_eq]) 1); 

344 
by (rtac allI 1); 

345 
by (rtac impI 1); 

346 
by (simp_tac(HOL_ss addsimps [wfrec_def]) 1); 

347 
by (res_inst_tac [("a1","a")] (th RS ssubst) 1); 

348 
by (atac 1); 

349 
by (forward_tac[wf_trancl] 1); 

350 
by (forward_tac[r_into_trancl] 1); 

351 
by (asm_simp_tac (HOL_ss addsimps [cut_apply]) 1); 

352 
by (rtac H_cong 1); (*expose the equality of cuts*) 

353 
by (rtac refl 2); 

354 
by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1); 

3708  355 
by (Clarify_tac 1); 
1485
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
nipkow
parents:
1475
diff
changeset

356 
by (res_inst_tac [("r","r^+")] is_recfun_equal 1); 
1475  357 
by (atac 1); 
358 
by (rtac trans_trancl 1); 

359 
by (rtac unfold_the_recfun 1); 

360 
by (atac 1); 

361 
by (rtac trans_trancl 1); 

362 
by (rtac unfold_the_recfun 1); 

363 
by (atac 1); 

364 
by (rtac trans_trancl 1); 

365 
by (rtac transD 1); 

366 
by (rtac trans_trancl 1); 

4762  367 
by (forw_inst_tac [("p","(ya,y)")] r_into_trancl 1); 
1475  368 
by (atac 1); 
369 
by (atac 1); 

4762  370 
by (forw_inst_tac [("p","(ya,y)")] r_into_trancl 1); 
1475  371 
by (atac 1); 
372 
qed "wfrec"; 

373 

374 
(*Old proof 

5069  375 
Goalw [wfrec_def] 
5148
74919e8f221c
More tidying and removal of "\!\!... from Goal commands
paulson
parents:
5143
diff
changeset

376 
"wf(r) ==> wfrec r H a = H (cut (wfrec r H) r a) a"; 
923  377 
by (etac (wf_trancl RS wftrec RS ssubst) 1); 
378 
by (rtac trans_trancl 1); 

379 
by (rtac (refl RS H_cong) 1); (*expose the equality of cuts*) 

1475  380 
by (simp_tac (HOL_ss addsimps [cuts_eq, cut_apply, r_into_trancl]) 1); 
923  381 
qed "wfrec"; 
1475  382 
*) 
923  383 

1475  384 
(* 
385 
* This form avoids giant explosions in proofs. NOTE USE OF == 

386 
**) 

5316  387 
val rew::prems = goal thy 
1475  388 
"[ f==wfrec r H; wf(r) ] ==> f(a) = H (cut f r a) a"; 
923  389 
by (rewtac rew); 
390 
by (REPEAT (resolve_tac (prems@[wfrec]) 1)); 

391 
qed "def_wfrec"; 

1475  392 

3198  393 

394 
(**** TFL variants ****) 

395 

5278  396 
Goal "!R. wf R > (!P. (!x. (!y. (y,x):R > P y) > P x) > (!x. P x))"; 
3708  397 
by (Clarify_tac 1); 
3198  398 
by (res_inst_tac [("r","R"),("P","P"), ("a","x")] wf_induct 1); 
399 
by (assume_tac 1); 

400 
by (Blast_tac 1); 

401 
qed"tfl_wf_induct"; 

402 

5069  403 
Goal "!f R. (x,a):R > (cut f R a)(x) = f(x)"; 
3708  404 
by (Clarify_tac 1); 
3198  405 
by (rtac cut_apply 1); 
406 
by (assume_tac 1); 

407 
qed"tfl_cut_apply"; 

408 

5069  409 
Goal "!M R f. (f=wfrec R M) > wf R > (!x. f x = M (cut f R x) x)"; 
3708  410 
by (Clarify_tac 1); 
4153  411 
by (etac wfrec 1); 
3198  412 
qed "tfl_wfrec"; 