| author | paulson | 
| Thu, 11 Dec 1997 10:29:22 +0100 | |
| changeset 4386 | b3cff8adc213 | 
| parent 4153 | e534c4c32d54 | 
| child 4477 | b3e5857d8d99 | 
| permissions | -rw-r--r-- | 
| 1700 | 1 | (* Title: HOL/IMP/Transition.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: Tobias Nipkow & Robert Sandner, TUM | |
| 4 | Copyright 1996 TUM | |
| 5 | ||
| 6 | Equivalence of Natural and Transition semantics | |
| 7 | *) | |
| 8 | ||
| 9 | open Transition; | |
| 10 | ||
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 11 | section "Winskel's Proof"; | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 12 | |
| 1973 | 13 | AddSEs [rel_pow_0_E]; | 
| 1700 | 14 | |
| 1973 | 15 | val evalc1_SEs = map (evalc1.mk_cases com.simps) | 
| 16 | ["(SKIP,s) -1-> t", "(x:=a,s) -1-> t","(c1;c2, s) -1-> t", | |
| 17 | "(IF b THEN c1 ELSE c2, s) -1-> t"]; | |
| 18 | val evalc1_Es = map (evalc1.mk_cases com.simps) | |
| 19 | ["(WHILE b DO c,s) -1-> t"]; | |
| 1700 | 20 | |
| 1973 | 21 | AddSEs evalc1_SEs; | 
| 22 | ||
| 23 | AddIs evalc1.intrs; | |
| 1700 | 24 | |
| 1701 | 25 | goal Transition.thy "!!s. (SKIP,s) -m-> (SKIP,t) ==> s = t & m = 0"; | 
| 2031 | 26 | by (etac rel_pow_E2 1); | 
| 1700 | 27 | by (Asm_full_simp_tac 1); | 
| 2031 | 28 | by (Fast_tac 1); | 
| 1973 | 29 | val hlemma = result(); | 
| 1700 | 30 | |
| 31 | ||
| 32 | goal Transition.thy | |
| 1701 | 33 | "!s t u c d. (c,s) -n-> (SKIP,t) --> (d,t) -*-> (SKIP,u) --> \ | 
| 1700 | 34 | \ (c;d, s) -*-> (SKIP, u)"; | 
| 2031 | 35 | by (nat_ind_tac "n" 1); | 
| 1700 | 36 | (* case n = 0 *) | 
| 4089 | 37 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2])1); | 
| 1700 | 38 | (* induction step *) | 
| 4089 | 39 | by (safe_tac (claset() addSDs [rel_pow_Suc_D2])); | 
| 2031 | 40 | by (split_all_tac 1); | 
| 4089 | 41 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | 
| 1700 | 42 | qed_spec_mp "lemma1"; | 
| 43 | ||
| 44 | ||
| 1730 | 45 | goal Transition.thy "!!c s s1. <c,s> -c-> s1 ==> (c,s) -*-> (SKIP,s1)"; | 
| 2031 | 46 | by (etac evalc.induct 1); | 
| 1700 | 47 | |
| 48 | (* SKIP *) | |
| 2031 | 49 | by (rtac rtrancl_refl 1); | 
| 1700 | 50 | |
| 51 | (* ASSIGN *) | |
| 4089 | 52 | by (fast_tac (claset() addSIs [r_into_rtrancl]) 1); | 
| 1700 | 53 | |
| 54 | (* SEMI *) | |
| 4089 | 55 | by (fast_tac (claset() addDs [rtrancl_imp_UN_rel_pow] addIs [lemma1]) 1); | 
| 1700 | 56 | |
| 57 | (* IF *) | |
| 4089 | 58 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | 
| 59 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | |
| 1700 | 60 | |
| 61 | (* WHILE *) | |
| 4089 | 62 | by (fast_tac (claset() addSIs [r_into_rtrancl]) 1); | 
| 63 | by (fast_tac (claset() addDs [rtrancl_imp_UN_rel_pow] | |
| 1700 | 64 | addIs [rtrancl_into_rtrancl2,lemma1]) 1); | 
| 65 | ||
| 1730 | 66 | qed "evalc_impl_evalc1"; | 
| 1700 | 67 | |
| 68 | ||
| 69 | goal Transition.thy | |
| 1701 | 70 | "!c d s u. (c;d,s) -n-> (SKIP,u) --> \ | 
| 71 | \ (? t m. (c,s) -*-> (SKIP,t) & (d,t) -m-> (SKIP,u) & m <= n)"; | |
| 2031 | 72 | by (nat_ind_tac "n" 1); | 
| 1700 | 73 | (* case n = 0 *) | 
| 4089 | 74 | by (fast_tac (claset() addss simpset()) 1); | 
| 1700 | 75 | (* induction step *) | 
| 4089 | 76 | by (fast_tac (claset() addSIs [le_SucI,le_refl] | 
| 1700 | 77 | addSDs [rel_pow_Suc_D2] | 
| 1973 | 78 | addSEs [rel_pow_imp_rtrancl,rtrancl_into_rtrancl2]) 1); | 
| 1700 | 79 | qed_spec_mp "lemma2"; | 
| 80 | ||
| 81 | goal Transition.thy "!s t. (c,s) -*-> (SKIP,t) --> <c,s> -c-> t"; | |
| 82 | by (com.induct_tac "c" 1); | |
| 4089 | 83 | by (safe_tac (claset() addSDs [rtrancl_imp_UN_rel_pow])); | 
| 1700 | 84 | |
| 85 | (* SKIP *) | |
| 4089 | 86 | by (fast_tac (claset() addSEs [rel_pow_E2]) 1); | 
| 1700 | 87 | |
| 88 | (* ASSIGN *) | |
| 4089 | 89 | by (fast_tac (claset() addSDs [hlemma] addSEs [rel_pow_E2] | 
| 4153 | 90 | addss simpset()) 1); | 
| 1700 | 91 | |
| 92 | (* SEMI *) | |
| 4089 | 93 | by (fast_tac (claset() addSDs [lemma2,rel_pow_imp_rtrancl]) 1); | 
| 1700 | 94 | |
| 95 | (* IF *) | |
| 2031 | 96 | by (etac rel_pow_E2 1); | 
| 1700 | 97 | by (Asm_full_simp_tac 1); | 
| 4089 | 98 | by (fast_tac (claset() addSDs [rel_pow_imp_rtrancl]) 1); | 
| 1700 | 99 | |
| 100 | (* WHILE, induction on the length of the computation *) | |
| 4153 | 101 | by (eres_inst_tac [("P","?X -n-> ?Y")] rev_mp 1);
 | 
| 1700 | 102 | by (res_inst_tac [("x","s")] spec 1);
 | 
| 2031 | 103 | by (res_inst_tac [("n","n")] less_induct 1);
 | 
| 1700 | 104 | by (strip_tac 1); | 
| 2031 | 105 | by (etac rel_pow_E2 1); | 
| 1700 | 106 | by (Asm_full_simp_tac 1); | 
| 1973 | 107 | by (eresolve_tac evalc1_Es 1); | 
| 1700 | 108 | |
| 109 | (* WhileFalse *) | |
| 4089 | 110 | by (fast_tac (claset() addSDs [hlemma]) 1); | 
| 1700 | 111 | |
| 112 | (* WhileTrue *) | |
| 4089 | 113 | by (fast_tac(claset() addSDs[lemma2,le_imp_less_or_eq,less_Suc_eq RS iffD2])1); | 
| 1700 | 114 | |
| 115 | qed_spec_mp "evalc1_impl_evalc"; | |
| 116 | ||
| 117 | ||
| 118 | (**** proof of the equivalence of evalc and evalc1 ****) | |
| 119 | ||
| 120 | goal Transition.thy "((c, s) -*-> (SKIP, t)) = (<c,s> -c-> t)"; | |
| 121 | by (fast_tac (HOL_cs addSEs [evalc1_impl_evalc,evalc_impl_evalc1]) 1); | |
| 122 | qed "evalc1_eq_evalc"; | |
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 123 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 124 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 125 | section "A Proof Without -n->"; | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 126 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 127 | goal Transition.thy | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 128 | "!!c1. (c1,s1) -*-> (SKIP,s2) ==> \ | 
| 1939 | 129 | \ (c2,s2) -*-> cs3 --> (c1;c2,s1) -*-> cs3"; | 
| 3439 | 130 | by (etac inverse_rtrancl_induct2 1); | 
| 4089 | 131 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | 
| 132 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | |
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 133 | qed_spec_mp "my_lemma1"; | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 134 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 135 | |
| 1730 | 136 | goal Transition.thy "!!c s s1. <c,s> -c-> s1 ==> (c,s) -*-> (SKIP,s1)"; | 
| 2031 | 137 | by (etac evalc.induct 1); | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 138 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 139 | (* SKIP *) | 
| 2031 | 140 | by (rtac rtrancl_refl 1); | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 141 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 142 | (* ASSIGN *) | 
| 4089 | 143 | by (fast_tac (claset() addSIs [r_into_rtrancl]) 1); | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 144 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 145 | (* SEMI *) | 
| 4089 | 146 | by (fast_tac (claset() addIs [my_lemma1]) 1); | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 147 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 148 | (* IF *) | 
| 4089 | 149 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | 
| 150 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2]) 1); | |
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 151 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 152 | (* WHILE *) | 
| 4089 | 153 | by (fast_tac (claset() addSIs [r_into_rtrancl]) 1); | 
| 154 | by (fast_tac (claset() addIs [rtrancl_into_rtrancl2,my_lemma1]) 1); | |
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 155 | |
| 1730 | 156 | qed "evalc_impl_evalc1"; | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 157 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 158 | (* The opposite direction is based on a Coq proof done by Ranan Fraer and | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 159 | Yves Bertot. The following sketch is from an email by Ranan Fraer. | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 160 | *) | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 161 | (* | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 162 | First we've broke it into 2 lemmas: | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 163 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 164 | Lemma 1 | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 165 | ((c,s) --> (SKIP,t)) => (<c,s> -c-> t) | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 166 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 167 | This is a quick one, dealing with the cases skip, assignment | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 168 | and while_false. | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 169 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 170 | Lemma 2 | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 171 | ((c,s) -*-> (c',s')) /\ <c',s'> -c'-> t | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 172 | => | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 173 | <c,s> -c-> t | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 174 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 175 | This is proved by rule induction on the -*-> relation | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 176 | and the induction step makes use of a third lemma: | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 177 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 178 | Lemma 3 | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 179 | ((c,s) --> (c',s')) /\ <c',s'> -c'-> t | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 180 | => | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 181 | <c,s> -c-> t | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 182 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 183 | This captures the essence of the proof, as it shows that <c',s'> | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 184 | behaves as the continuation of <c,s> with respect to the natural | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 185 | semantics. | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 186 | The proof of Lemma 3 goes by rule induction on the --> relation, | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 187 | dealing with the cases sequence1, sequence2, if_true, if_false and | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 188 | while_true. In particular in the case (sequence1) we make use again | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 189 | of Lemma 1. | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 190 | *) | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 191 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 192 | |
| 1730 | 193 | goal Transition.thy | 
| 194 | "!!c s. ((c,s) -1-> (c',s')) ==> (!t. <c',s'> -c-> t --> <c,s> -c-> t)"; | |
| 2031 | 195 | by (etac evalc1.induct 1); | 
| 3023 | 196 | by (Auto_tac()); | 
| 1730 | 197 | qed_spec_mp "FB_lemma3"; | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 198 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 199 | val [major] = goal Transition.thy | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 200 | "(c,s) -*-> (c',s') ==> <c',s'> -c-> t --> <c,s> -c-> t"; | 
| 2031 | 201 | by (rtac (major RS rtrancl_induct2) 1); | 
| 202 | by (Fast_tac 1); | |
| 4089 | 203 | by (fast_tac (claset() addIs [FB_lemma3] addbefore split_all_tac) 1); | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 204 | qed_spec_mp "FB_lemma2"; | 
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 205 | |
| 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 206 | goal Transition.thy "!!c. (c,s) -*-> (SKIP,t) ==> <c,s> -c-> t"; | 
| 4089 | 207 | by (fast_tac (claset() addEs [FB_lemma2]) 1); | 
| 1707 
e1a64a6c454d
Added an equivalence proof which avoids the use of -n->
 nipkow parents: 
1701diff
changeset | 208 | qed "evalc1_impl_evalc"; |