| author | paulson | 
| Thu, 17 Jun 1999 10:35:01 +0200 | |
| changeset 6833 | 15d6c121d75f | 
| parent 6676 | 62d1e642da30 | 
| child 7403 | c318acb88251 | 
| permissions | -rw-r--r-- | 
| 4776 | 1 | (* Title: HOL/UNITY/Reach.thy | 
| 2 | ID: $Id$ | |
| 3 | Author: Lawrence C Paulson, Cambridge University Computer Laboratory | |
| 4 | Copyright 1998 University of Cambridge | |
| 5 | ||
| 6 | Reachability in Directed Graphs. From Chandy and Misra, section 6.4. | |
| 4896 
4727272f3db6
New syntax for function update; moved to main HOL directory
 paulson parents: 
4776diff
changeset | 7 | [ this example took only four days!] | 
| 4776 | 8 | *) | 
| 9 | ||
| 10 | (*TO SIMPDATA.ML?? FOR CLASET?? *) | |
| 11 | val major::prems = goal thy | |
| 12 | "[| if P then Q else R; \ | |
| 13 | \ [| P; Q |] ==> S; \ | |
| 14 | \ [| ~ P; R |] ==> S |] ==> S"; | |
| 15 | by (cut_facts_tac [major] 1); | |
| 16 | by (blast_tac (claset() addSDs [if_bool_eq_disj RS iffD1] addIs prems) 1); | |
| 17 | qed "ifE"; | |
| 18 | ||
| 19 | AddSEs [ifE]; | |
| 20 | ||
| 21 | ||
| 5648 | 22 | Addsimps [Rprg_def RS def_prg_Init]; | 
| 23 | program_defs_ref := [Rprg_def]; | |
| 4776 | 24 | |
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 25 | Addsimps [simp_of_act asgt_def]; | 
| 4776 | 26 | |
| 27 | (*All vertex sets are finite*) | |
| 28 | AddIffs [[subset_UNIV, finite_graph] MRS finite_subset]; | |
| 29 | ||
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 30 | Addsimps [simp_of_set reach_invariant_def]; | 
| 4776 | 31 | |
| 6570 | 32 | Goal "Rprg : Always reach_invariant"; | 
| 33 | by (rtac AlwaysI 1); | |
| 5240 
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
 paulson parents: 
5232diff
changeset | 34 | by Auto_tac; (*for the initial state; proof of stability remains*) | 
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 35 | by (constrains_tac 1); | 
| 4776 | 36 | by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 1); | 
| 5240 
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
 paulson parents: 
5232diff
changeset | 37 | qed "reach_invariant"; | 
| 4776 | 38 | |
| 39 | ||
| 40 | (*** Fixedpoint ***) | |
| 41 | ||
| 42 | (*If it reaches a fixedpoint, it has found a solution*) | |
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 43 | Goalw [fixedpoint_def] | 
| 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 44 |      "fixedpoint Int reach_invariant = { %v. (init, v) : edges^* }";
 | 
| 4776 | 45 | by (rtac equalityI 1); | 
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 46 | by (auto_tac (claset() addSIs [ext], simpset())); | 
| 4776 | 47 | by (blast_tac (claset() addIs [r_into_rtrancl,rtrancl_trans]) 2); | 
| 48 | by (etac rtrancl_induct 1); | |
| 49 | by Auto_tac; | |
| 50 | qed "fixedpoint_invariant_correct"; | |
| 51 | ||
| 5648 | 52 | Goalw [FP_def, fixedpoint_def, stable_def, constrains_def, Rprg_def] | 
| 53 | "FP Rprg <= fixedpoint"; | |
| 4776 | 54 | by Auto_tac; | 
| 5758 
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
 oheimb parents: 
5648diff
changeset | 55 | by (dtac bspec 1 THEN atac 1); | 
| 4776 | 56 | by (asm_full_simp_tac (simpset() addsimps [Image_singleton, image_iff]) 1); | 
| 57 | by (dtac fun_cong 1); | |
| 58 | by Auto_tac; | |
| 59 | val lemma1 = result(); | |
| 60 | ||
| 5648 | 61 | Goalw [FP_def, fixedpoint_def, stable_def, constrains_def, Rprg_def] | 
| 62 | "fixedpoint <= FP Rprg"; | |
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 63 | by (auto_tac (claset() addSIs [ext], simpset())); | 
| 4776 | 64 | val lemma2 = result(); | 
| 65 | ||
| 5648 | 66 | Goal "FP Rprg = fixedpoint"; | 
| 4776 | 67 | by (rtac ([lemma1,lemma2] MRS equalityI) 1); | 
| 68 | qed "FP_fixedpoint"; | |
| 69 | ||
| 70 | ||
| 71 | (*If we haven't reached a fixedpoint then there is some edge for which u but | |
| 72 | not v holds. Progress will be proved via an ENSURES assertion that the | |
| 73 | metric will decrease for each suitable edge. A union over all edges proves | |
| 74 | a LEADSTO assertion that the metric decreases if we are not at a fixedpoint. | |
| 75 | *) | |
| 76 | ||
| 5490 | 77 | Goal "- fixedpoint = (UN (u,v): edges. {s. s u & ~ s v})";
 | 
| 4776 | 78 | by (simp_tac (simpset() addsimps | 
| 5648 | 79 | ([Compl_FP, UN_UN_flatten, FP_fixedpoint RS sym, Rprg_def])) 1); | 
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 80 | by Auto_tac; | 
| 5758 
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
 oheimb parents: 
5648diff
changeset | 81 | by (ALLGOALS (dtac bspec THEN' atac)); | 
| 
27a2b36efd95
corrected auto_tac (applications of unsafe wrappers)
 oheimb parents: 
5648diff
changeset | 82 | by (rtac fun_upd_idem 1); | 
| 5521 | 83 | by (auto_tac (claset(),simpset() addsimps [fun_upd_idem_iff])); | 
| 4776 | 84 | qed "Compl_fixedpoint"; | 
| 85 | ||
| 5069 | 86 | Goal "A - fixedpoint = (UN (u,v): edges. A Int {s. s u & ~ s v})";
 | 
| 4776 | 87 | by (simp_tac (simpset() addsimps [Diff_eq, Compl_fixedpoint]) 1); | 
| 88 | by (Blast_tac 1); | |
| 89 | qed "Diff_fixedpoint"; | |
| 90 | ||
| 91 | ||
| 92 | (*** Progress ***) | |
| 93 | ||
| 5111 | 94 | Goalw [metric_def] "~ s x ==> Suc (metric (s(x:=True))) = metric s"; | 
| 5071 
548f398d770b
Consequences of the change from [ := ] to ( := ) in theory Update.
 nipkow parents: 
5069diff
changeset | 95 | by (subgoal_tac "{v. ~ (s(x:=True)) v} = {v. ~ s v} - {x}" 1);
 | 
| 4776 | 96 | by Auto_tac; | 
| 5629 | 97 | by (asm_simp_tac (simpset() addsimps [card_Suc_Diff1]) 1); | 
| 4776 | 98 | qed "Suc_metric"; | 
| 99 | ||
| 5111 | 100 | Goal "~ s x ==> metric (s(x:=True)) < metric s"; | 
| 4776 | 101 | by (etac (Suc_metric RS subst) 1); | 
| 102 | by (Blast_tac 1); | |
| 103 | qed "metric_less"; | |
| 104 | AddSIs [metric_less]; | |
| 105 | ||
| 5071 
548f398d770b
Consequences of the change from [ := ] to ( := ) in theory Update.
 nipkow parents: 
5069diff
changeset | 106 | Goal "metric (s(y:=s x | s y)) <= metric s"; | 
| 4776 | 107 | by (case_tac "s x --> s y" 1); | 
| 108 | by (auto_tac (claset() addIs [less_imp_le], | |
| 5196 | 109 | simpset() addsimps [fun_upd_idem])); | 
| 4776 | 110 | qed "metric_le"; | 
| 111 | ||
| 6536 | 112 | Goal "Rprg : ((metric-``{m}) - fixedpoint) LeadsTo (metric-``(lessThan m))";
 | 
| 4776 | 113 | by (simp_tac (simpset() addsimps [Diff_fixedpoint]) 1); | 
| 5313 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 114 | by (rtac LeadsTo_UN 1); | 
| 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 115 | by Auto_tac; | 
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 116 | by (ensures_tac "asgt a b" 1); | 
| 5424 
771a68a468cc
modified proofs for new constrains_tac and ensures_tac
 paulson parents: 
5313diff
changeset | 117 | by (Blast_tac 2); | 
| 
771a68a468cc
modified proofs for new constrains_tac and ensures_tac
 paulson parents: 
5313diff
changeset | 118 | by (full_simp_tac (simpset() addsimps [not_less_iff_le]) 1); | 
| 6676 | 119 | by (dtac (metric_le RS order_antisym) 1); | 
| 5424 
771a68a468cc
modified proofs for new constrains_tac and ensures_tac
 paulson parents: 
5313diff
changeset | 120 | by (auto_tac (claset() addEs [less_not_refl3 RSN (2, rev_notE)], | 
| 
771a68a468cc
modified proofs for new constrains_tac and ensures_tac
 paulson parents: 
5313diff
changeset | 121 | simpset())); | 
| 5313 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 122 | qed "LeadsTo_Diff_fixedpoint"; | 
| 4776 | 123 | |
| 6536 | 124 | Goal "Rprg : (metric-``{m}) LeadsTo (metric-``(lessThan m) Un fixedpoint)";
 | 
| 5426 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 125 | by (rtac ([LeadsTo_Diff_fixedpoint RS LeadsTo_weaken_R, | 
| 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 126 | subset_imp_LeadsTo] MRS LeadsTo_Diff) 1); | 
| 
566f47250bd0
A new approach, using simp_of_act and simp_of_set to activate definitions when
 paulson parents: 
5424diff
changeset | 127 | by Auto_tac; | 
| 5313 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 128 | qed "LeadsTo_Un_fixedpoint"; | 
| 4776 | 129 | |
| 130 | ||
| 131 | (*Execution in any state leads to a fixedpoint (i.e. can terminate)*) | |
| 6536 | 132 | Goal "Rprg : UNIV LeadsTo fixedpoint"; | 
| 5313 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 133 | by (rtac LessThan_induct 1); | 
| 4776 | 134 | by Auto_tac; | 
| 5313 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 135 | by (rtac LeadsTo_Un_fixedpoint 1); | 
| 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 136 | qed "LeadsTo_fixedpoint"; | 
| 4776 | 137 | |
| 6536 | 138 | Goal "Rprg : UNIV LeadsTo { %v. (init, v) : edges^* }";
 | 
| 4776 | 139 | by (stac (fixedpoint_invariant_correct RS sym) 1); | 
| 5313 
1861a564d7e2
Constrains, Stable, Invariant...more of the substitution axiom, but Union
 paulson parents: 
5253diff
changeset | 140 | by (rtac ([reach_invariant, LeadsTo_fixedpoint] | 
| 6570 | 141 | MRS Always_LeadsTo_weaken) 1); | 
| 5240 
bbcd79ef7cf2
Constant "invariant" and new constrains_tac, ensures_tac
 paulson parents: 
5232diff
changeset | 142 | by Auto_tac; | 
| 4776 | 143 | qed "LeadsTo_correct"; |