9448
|
1 |
(* Title: HOL/While
|
|
2 |
ID: $Id$
|
|
3 |
Author: Tobias Nipkow
|
|
4 |
Copyright 2000 TU Muenchen
|
|
5 |
*)
|
|
6 |
|
|
7 |
goalw_cterm [] (cterm_of (sign_of thy)
|
|
8 |
(HOLogic.mk_Trueprop (hd while_aux.tcs)));
|
|
9 |
br wf_same_fstI 1;
|
|
10 |
br wf_same_fstI 1;
|
|
11 |
by (asm_full_simp_tac (simpset() addsimps [wf_iff_no_infinite_down_chain]) 1);
|
|
12 |
by(Blast_tac 1);
|
|
13 |
val while_aux_tc = result();
|
|
14 |
|
|
15 |
Goal
|
|
16 |
"while_aux(b,c,s) = (if ? f. f 0 = s & (!i. b(f i) & c(f i) = f(i+1)) \
|
|
17 |
\ then arbitrary \
|
|
18 |
\ else (if b s then while_aux(b,c,c s) else s))";
|
|
19 |
by(rtac (while_aux_tc RS (hd while_aux.simps) RS trans) 1);
|
|
20 |
by(simp_tac (simpset() addsimps [same_fst_def]) 1);
|
|
21 |
br refl 1;
|
|
22 |
qed "while_aux_unfold";
|
|
23 |
|
|
24 |
(*** The recursion equation for while: directly executable! ***)
|
|
25 |
|
|
26 |
Goalw [while_def] "while b c s = (if b s then while b c (c s) else s)";
|
|
27 |
by(rtac (while_aux_unfold RS trans) 1);
|
|
28 |
by (Auto_tac);
|
|
29 |
by(stac while_aux_unfold 1);
|
|
30 |
by(Asm_full_simp_tac 1);
|
|
31 |
by(Clarify_tac 1);
|
|
32 |
by(eres_inst_tac [("x","%i. f(Suc i)")] allE 1);
|
|
33 |
by(Blast_tac 1);
|
|
34 |
qed "while_unfold";
|
|
35 |
|
|
36 |
(*** The proof rule for while; P is the invariant ***)
|
|
37 |
|
|
38 |
val [prem1,prem2,prem3] = Goal
|
|
39 |
"[| !!s. [| P s; b s |] ==> P(c s); \
|
|
40 |
\ !!s. [| P s; ~b s |] ==> Q s; \
|
|
41 |
\ wf{(t,s). P s & b s & t = c s} |] \
|
|
42 |
\ ==> P s --> Q(while b c s)";
|
9747
|
43 |
by(induct_thm_tac (prem3 RS wf_induct) "s" 1);
|
9448
|
44 |
by(Asm_full_simp_tac 1);
|
|
45 |
by(Clarify_tac 1);
|
|
46 |
by(stac while_unfold 1);
|
|
47 |
by(asm_full_simp_tac (simpset() addsimps [prem1,prem2]) 1);
|
|
48 |
qed_spec_mp "while_rule";
|
|
49 |
|
|
50 |
(*** An application: computation of the lfp on finite sets via iteration ***)
|
|
51 |
|
|
52 |
Goal
|
|
53 |
"[| mono f; finite U; f U = U |] \
|
|
54 |
\ ==> lfp f = fst(while (%(A,fA). A~=fA) (%(A,fA). (fA, f fA)) ({},f{}))";
|
|
55 |
by(res_inst_tac [("P","%(A,B).(A <= U & B = f A & A <= B & B <= lfp f)")]
|
|
56 |
while_rule 1);
|
10186
|
57 |
by(stac lfp_unfold 1);
|
9448
|
58 |
ba 1;
|
|
59 |
by(Clarsimp_tac 1);
|
|
60 |
by(blast_tac (claset() addDs [monoD]) 1);
|
|
61 |
by(fast_tac (claset() addSIs [lfp_lowerbound] addss simpset()) 1);
|
|
62 |
by(res_inst_tac [("r","((Pow U <*> UNIV) <*> (Pow U <*> UNIV)) Int \
|
|
63 |
\ inv_image finite_psubset (op - U o fst)")]
|
|
64 |
wf_subset 1);
|
|
65 |
by(blast_tac (claset() addIs
|
|
66 |
[wf_finite_psubset,Int_lower2 RSN (2,wf_subset)]) 1);
|
|
67 |
by(clarsimp_tac (claset(),simpset() addsimps
|
|
68 |
[inv_image_def,finite_psubset_def,order_less_le]) 1);
|
|
69 |
by(blast_tac (claset() addSIs [finite_Diff] addDs [monoD]) 1);
|
10186
|
70 |
by(stac lfp_unfold 1);
|
9448
|
71 |
ba 1;
|
|
72 |
by(asm_simp_tac (simpset() addsimps [monoD]) 1);
|
|
73 |
qed "lfp_conv_while";
|
|
74 |
|
|
75 |
(*** An example; requires integers
|
|
76 |
|
|
77 |
Goal "{f n|n. A n | B n} = {f n|n. A n} Un {f n|n. B n}";
|
|
78 |
by(Blast_tac 1);
|
|
79 |
qed "lemma";
|
|
80 |
|
|
81 |
Goal "P(lfp (%N::int set. {#0} Un {(n + #2) mod #6 |n. n:N})) = P{#0,#4,#2}";
|
|
82 |
by(stac (read_instantiate [("U","{#0,#1,#2,#3,#4,#5}")] lfp_conv_while) 1);
|
|
83 |
br monoI 1;
|
|
84 |
by(Blast_tac 1);
|
|
85 |
by(Simp_tac 1);
|
|
86 |
by(simp_tac (simpset() addsimps [lemma,set_eq_subset]) 1);
|
|
87 |
(* The fixpoint computation is performed purely by rewriting: *)
|
|
88 |
by(simp_tac (simpset() addsimps [while_unfold,lemma,set_eq_subset]
|
|
89 |
delsimps [subset_empty]) 1);
|
|
90 |
result();
|
|
91 |
|
|
92 |
***)
|