| author | wenzelm | 
| Thu, 19 Jun 2008 20:48:03 +0200 | |
| changeset 27279 | 39ff18c0f07f | 
| parent 16733 | 236dfafbeb63 | 
| child 27651 | 16a26996c30e | 
| permissions | -rw-r--r-- | 
| 13020 | 1 | header {* \section{Examples} *}
 | 
| 2 | ||
| 16417 | 3 | theory RG_Examples imports RG_Syntax begin | 
| 13020 | 4 | |
| 5 | lemmas definitions [simp]= stable_def Pre_def Rely_def Guar_def Post_def Com_def | |
| 6 | ||
| 7 | subsection {* Set Elements of an Array to Zero *}
 | |
| 8 | ||
| 9 | lemma le_less_trans2: "\<lbrakk>(j::nat)<k; i\<le> j\<rbrakk> \<Longrightarrow> i<k" | |
| 10 | by simp | |
| 11 | ||
| 12 | lemma add_le_less_mono: "\<lbrakk> (a::nat) < c; b\<le>d \<rbrakk> \<Longrightarrow> a + b < c + d" | |
| 13 | by simp | |
| 14 | ||
| 15 | record Example1 = | |
| 16 | A :: "nat list" | |
| 17 | ||
| 18 | lemma Example1: | |
| 19 | "\<turnstile> COBEGIN | |
| 20 | SCHEME [0 \<le> i < n] | |
| 21 | (\<acute>A := \<acute>A [i := 0], | |
| 22 | \<lbrace> n < length \<acute>A \<rbrace>, | |
| 23 | \<lbrace> length \<ordmasculine>A = length \<ordfeminine>A \<and> \<ordmasculine>A ! i = \<ordfeminine>A ! i \<rbrace>, | |
| 24 | \<lbrace> length \<ordmasculine>A = length \<ordfeminine>A \<and> (\<forall>j<n. i \<noteq> j \<longrightarrow> \<ordmasculine>A ! j = \<ordfeminine>A ! j) \<rbrace>, | |
| 25 | \<lbrace> \<acute>A ! i = 0 \<rbrace>) | |
| 26 | COEND | |
| 27 | SAT [\<lbrace> n < length \<acute>A \<rbrace>, \<lbrace> \<ordmasculine>A = \<ordfeminine>A \<rbrace>, \<lbrace> True \<rbrace>, \<lbrace> \<forall>i < n. \<acute>A ! i = 0 \<rbrace>]" | |
| 28 | apply(rule Parallel) | |
| 15102 | 29 | apply (auto intro!: Basic) | 
| 13020 | 30 | done | 
| 31 | ||
| 32 | lemma Example1_parameterized: | |
| 33 | "k < t \<Longrightarrow> | |
| 34 | \<turnstile> COBEGIN | |
| 35 | SCHEME [k*n\<le>i<(Suc k)*n] (\<acute>A:=\<acute>A[i:=0], | |
| 36 | \<lbrace>t*n < length \<acute>A\<rbrace>, | |
| 37 | \<lbrace>t*n < length \<ordmasculine>A \<and> length \<ordmasculine>A=length \<ordfeminine>A \<and> \<ordmasculine>A!i = \<ordfeminine>A!i\<rbrace>, | |
| 38 | \<lbrace>t*n < length \<ordmasculine>A \<and> length \<ordmasculine>A=length \<ordfeminine>A \<and> (\<forall>j<length \<ordmasculine>A . i\<noteq>j \<longrightarrow> \<ordmasculine>A!j = \<ordfeminine>A!j)\<rbrace>, | |
| 39 | \<lbrace>\<acute>A!i=0\<rbrace>) | |
| 40 | COEND | |
| 41 | SAT [\<lbrace>t*n < length \<acute>A\<rbrace>, | |
| 42 | \<lbrace>t*n < length \<ordmasculine>A \<and> length \<ordmasculine>A=length \<ordfeminine>A \<and> (\<forall>i<n. \<ordmasculine>A!(k*n+i)=\<ordfeminine>A!(k*n+i))\<rbrace>, | |
| 43 | \<lbrace>t*n < length \<ordmasculine>A \<and> length \<ordmasculine>A=length \<ordfeminine>A \<and> | |
| 44 | (\<forall>i<length \<ordmasculine>A . (i<k*n \<longrightarrow> \<ordmasculine>A!i = \<ordfeminine>A!i) \<and> ((Suc k)*n \<le> i\<longrightarrow> \<ordmasculine>A!i = \<ordfeminine>A!i))\<rbrace>, | |
| 45 | \<lbrace>\<forall>i<n. \<acute>A!(k*n+i) = 0\<rbrace>]" | |
| 46 | apply(rule Parallel) | |
| 15102 | 47 | apply auto | 
| 48 | apply(erule_tac x="k*n +i" in allE) | |
| 49 | apply(subgoal_tac "k*n+i <length (A b)") | |
| 13020 | 50 | apply force | 
| 15102 | 51 | apply(erule le_less_trans2) | 
| 52 | apply(case_tac t,simp+) | |
| 53 | apply (simp add:add_commute) | |
| 54 | apply(simp add: add_le_mono) | |
| 13020 | 55 | apply(rule Basic) | 
| 56 | apply simp | |
| 57 | apply clarify | |
| 58 | apply (subgoal_tac "k*n+i< length (A x)") | |
| 59 | apply simp | |
| 60 | apply(erule le_less_trans2) | |
| 61 | apply(case_tac t,simp+) | |
| 62 | apply (simp add:add_commute) | |
| 15102 | 63 | apply(rule add_le_mono, auto) | 
| 13020 | 64 | done | 
| 65 | ||
| 15102 | 66 | |
| 13020 | 67 | subsection {* Increment a Variable in Parallel *}
 | 
| 68 | ||
| 69 | subsubsection {* Two components *}
 | |
| 70 | ||
| 71 | record Example2 = | |
| 72 | x :: nat | |
| 73 | c_0 :: nat | |
| 74 | c_1 :: nat | |
| 75 | ||
| 76 | lemma Example2: | |
| 77 | "\<turnstile> COBEGIN | |
| 78 | (\<langle> \<acute>x:=\<acute>x+1;; \<acute>c_0:=\<acute>c_0 + 1 \<rangle>, | |
| 79 | \<lbrace>\<acute>x=\<acute>c_0 + \<acute>c_1 \<and> \<acute>c_0=0\<rbrace>, | |
| 80 | \<lbrace>\<ordmasculine>c_0 = \<ordfeminine>c_0 \<and> | |
| 81 | (\<ordmasculine>x=\<ordmasculine>c_0 + \<ordmasculine>c_1 | |
| 82 | \<longrightarrow> \<ordfeminine>x = \<ordfeminine>c_0 + \<ordfeminine>c_1)\<rbrace>, | |
| 83 | \<lbrace>\<ordmasculine>c_1 = \<ordfeminine>c_1 \<and> | |
| 84 | (\<ordmasculine>x=\<ordmasculine>c_0 + \<ordmasculine>c_1 | |
| 85 | \<longrightarrow> \<ordfeminine>x =\<ordfeminine>c_0 + \<ordfeminine>c_1)\<rbrace>, | |
| 86 | \<lbrace>\<acute>x=\<acute>c_0 + \<acute>c_1 \<and> \<acute>c_0=1 \<rbrace>) | |
| 87 | \<parallel> | |
| 88 | (\<langle> \<acute>x:=\<acute>x+1;; \<acute>c_1:=\<acute>c_1+1 \<rangle>, | |
| 89 | \<lbrace>\<acute>x=\<acute>c_0 + \<acute>c_1 \<and> \<acute>c_1=0 \<rbrace>, | |
| 90 | \<lbrace>\<ordmasculine>c_1 = \<ordfeminine>c_1 \<and> | |
| 91 | (\<ordmasculine>x=\<ordmasculine>c_0 + \<ordmasculine>c_1 | |
| 92 | \<longrightarrow> \<ordfeminine>x = \<ordfeminine>c_0 + \<ordfeminine>c_1)\<rbrace>, | |
| 93 | \<lbrace>\<ordmasculine>c_0 = \<ordfeminine>c_0 \<and> | |
| 94 | (\<ordmasculine>x=\<ordmasculine>c_0 + \<ordmasculine>c_1 | |
| 95 | \<longrightarrow> \<ordfeminine>x =\<ordfeminine>c_0 + \<ordfeminine>c_1)\<rbrace>, | |
| 96 | \<lbrace>\<acute>x=\<acute>c_0 + \<acute>c_1 \<and> \<acute>c_1=1\<rbrace>) | |
| 97 | COEND | |
| 98 | SAT [\<lbrace>\<acute>x=0 \<and> \<acute>c_0=0 \<and> \<acute>c_1=0\<rbrace>, | |
| 99 | \<lbrace>\<ordmasculine>x=\<ordfeminine>x \<and> \<ordmasculine>c_0= \<ordfeminine>c_0 \<and> \<ordmasculine>c_1=\<ordfeminine>c_1\<rbrace>, | |
| 100 | \<lbrace>True\<rbrace>, | |
| 101 | \<lbrace>\<acute>x=2\<rbrace>]" | |
| 102 | apply(rule Parallel) | |
| 103 | apply simp_all | |
| 104 | apply clarify | |
| 105 | apply(case_tac i) | |
| 106 | apply simp | |
| 15102 | 107 | apply(rule conjI) | 
| 13020 | 108 | apply clarify | 
| 109 | apply simp | |
| 110 | apply clarify | |
| 111 | apply simp | |
| 112 | apply(case_tac j,simp) | |
| 113 | apply simp | |
| 114 | apply simp | |
| 15102 | 115 | apply(rule conjI) | 
| 13020 | 116 | apply clarify | 
| 117 | apply simp | |
| 118 | apply clarify | |
| 119 | apply simp | |
| 13187 | 120 | apply(subgoal_tac "j=0") | 
| 121 | apply (rotate_tac -1) | |
| 13601 | 122 | apply (simp (asm_lr)) | 
| 13187 | 123 | apply arith | 
| 13020 | 124 | apply clarify | 
| 125 | apply(case_tac i,simp,simp) | |
| 126 | apply clarify | |
| 127 | apply simp | |
| 128 | apply(erule_tac x=0 in all_dupE) | |
| 129 | apply(erule_tac x=1 in allE,simp) | |
| 130 | apply clarify | |
| 131 | apply(case_tac i,simp) | |
| 132 | apply(rule Await) | |
| 133 | apply simp_all | |
| 134 | apply(clarify) | |
| 135 | apply(rule Seq) | |
| 136 | prefer 2 | |
| 137 | apply(rule Basic) | |
| 138 | apply simp_all | |
| 139 | apply(rule subset_refl) | |
| 140 | apply(rule Basic) | |
| 141 | apply simp_all | |
| 142 | apply clarify | |
| 143 | apply simp | |
| 144 | apply(rule Await) | |
| 145 | apply simp_all | |
| 146 | apply(clarify) | |
| 147 | apply(rule Seq) | |
| 148 | prefer 2 | |
| 149 | apply(rule Basic) | |
| 150 | apply simp_all | |
| 151 | apply(rule subset_refl) | |
| 15102 | 152 | apply(auto intro!: Basic) | 
| 13020 | 153 | done | 
| 154 | ||
| 155 | subsubsection {* Parameterized *}
 | |
| 156 | ||
| 15561 | 157 | lemma Example2_lemma2_aux: "j<n \<Longrightarrow> | 
| 158 | (\<Sum>i=0..<n. (b i::nat)) = | |
| 159 | (\<Sum>i=0..<j. b i) + b j + (\<Sum>i=0..<n-(Suc j) . b (Suc j + i))" | |
| 13020 | 160 | apply(induct n) | 
| 161 | apply simp_all | |
| 162 | apply(simp add:less_Suc_eq) | |
| 163 | apply(auto) | |
| 164 | apply(subgoal_tac "n - j = Suc(n- Suc j)") | |
| 165 | apply simp | |
| 166 | apply arith | |
| 15561 | 167 | done | 
| 13020 | 168 | |
| 15561 | 169 | lemma Example2_lemma2_aux2: | 
| 170 | "j\<le> s \<Longrightarrow> (\<Sum>i::nat=0..<j. (b (s:=t)) i) = (\<Sum>i=0..<j. b i)" | |
| 13020 | 171 | apply(induct j) | 
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 172 | apply (simp_all cong:setsum_cong) | 
| 13020 | 173 | done | 
| 174 | ||
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 175 | lemma Example2_lemma2: | 
| 15561 | 176 | "\<lbrakk>j<n; b j=0\<rbrakk> \<Longrightarrow> Suc (\<Sum>i::nat=0..<n. b i)=(\<Sum>i=0..<n. (b (j := Suc 0)) i)" | 
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 177 | apply(frule_tac b="(b (j:=(Suc 0)))" in Example2_lemma2_aux) | 
| 15561 | 178 | apply(erule_tac  t="setsum (b(j := (Suc 0))) {0..<n}" in ssubst)
 | 
| 13020 | 179 | apply(frule_tac b=b in Example2_lemma2_aux) | 
| 15561 | 180 | apply(erule_tac  t="setsum b {0..<n}" in ssubst)
 | 
| 181 | apply(subgoal_tac "Suc (setsum b {0..<j} + b j + (\<Sum>i=0..<n - Suc j. b (Suc j + i)))=(setsum b {0..<j} + Suc (b j) + (\<Sum>i=0..<n - Suc j. b (Suc j + i)))")
 | |
| 15041 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 182 | apply(rotate_tac -1) | 
| 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 183 | apply(erule ssubst) | 
| 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 184 | apply(subgoal_tac "j\<le>j") | 
| 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 185 | apply(drule_tac b="b" and t="(Suc 0)" in Example2_lemma2_aux2) | 
| 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 186 | apply(rotate_tac -1) | 
| 
a6b1f0cef7b3
Got rid of Summation and made it a translation into setsum instead.
 nipkow parents: 
14174diff
changeset | 187 | apply(erule ssubst) | 
| 13020 | 188 | apply simp_all | 
| 189 | done | |
| 190 | ||
| 15561 | 191 | lemma Example2_lemma2_Suc0: "\<lbrakk>j<n; b j=0\<rbrakk> \<Longrightarrow> | 
| 192 | Suc (\<Sum>i::nat=0..< n. b i)=(\<Sum>i=0..< n. (b (j:=Suc 0)) i)" | |
| 13020 | 193 | by(simp add:Example2_lemma2) | 
| 194 | ||
| 195 | record Example2_parameterized = | |
| 196 | C :: "nat \<Rightarrow> nat" | |
| 197 | y :: nat | |
| 198 | ||
| 199 | lemma Example2_parameterized: "0<n \<Longrightarrow> | |
| 200 | \<turnstile> COBEGIN SCHEME [0\<le>i<n] | |
| 201 | (\<langle> \<acute>y:=\<acute>y+1;; \<acute>C:=\<acute>C (i:=1) \<rangle>, | |
| 15561 | 202 | \<lbrace>\<acute>y=(\<Sum>i=0..<n. \<acute>C i) \<and> \<acute>C i=0\<rbrace>, | 
| 13020 | 203 | \<lbrace>\<ordmasculine>C i = \<ordfeminine>C i \<and> | 
| 15561 | 204 | (\<ordmasculine>y=(\<Sum>i=0..<n. \<ordmasculine>C i) \<longrightarrow> \<ordfeminine>y =(\<Sum>i=0..<n. \<ordfeminine>C i))\<rbrace>, | 
| 13020 | 205 | \<lbrace>(\<forall>j<n. i\<noteq>j \<longrightarrow> \<ordmasculine>C j = \<ordfeminine>C j) \<and> | 
| 15561 | 206 | (\<ordmasculine>y=(\<Sum>i=0..<n. \<ordmasculine>C i) \<longrightarrow> \<ordfeminine>y =(\<Sum>i=0..<n. \<ordfeminine>C i))\<rbrace>, | 
| 207 | \<lbrace>\<acute>y=(\<Sum>i=0..<n. \<acute>C i) \<and> \<acute>C i=1\<rbrace>) | |
| 13020 | 208 | COEND | 
| 15561 | 209 | SAT [\<lbrace>\<acute>y=0 \<and> (\<Sum>i=0..<n. \<acute>C i)=0 \<rbrace>, \<lbrace>\<ordmasculine>C=\<ordfeminine>C \<and> \<ordmasculine>y=\<ordfeminine>y\<rbrace>, \<lbrace>True\<rbrace>, \<lbrace>\<acute>y=n\<rbrace>]" | 
| 13020 | 210 | apply(rule Parallel) | 
| 211 | apply force | |
| 212 | apply force | |
| 15561 | 213 | apply(force) | 
| 13020 | 214 | apply clarify | 
| 215 | apply simp | |
| 15561 | 216 | apply(simp cong:setsum_ivl_cong) | 
| 13020 | 217 | apply clarify | 
| 218 | apply simp | |
| 219 | apply(rule Await) | |
| 220 | apply simp_all | |
| 221 | apply clarify | |
| 222 | apply(rule Seq) | |
| 223 | prefer 2 | |
| 224 | apply(rule Basic) | |
| 225 | apply(rule subset_refl) | |
| 226 | apply simp+ | |
| 227 | apply(rule Basic) | |
| 228 | apply simp | |
| 229 | apply clarify | |
| 230 | apply simp | |
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16417diff
changeset | 231 | apply(simp add:Example2_lemma2_Suc0 cong:if_cong) | 
| 13020 | 232 | apply simp+ | 
| 233 | done | |
| 234 | ||
| 235 | subsection {* Find Least Element *}
 | |
| 236 | ||
| 237 | text {* A previous lemma: *}
 | |
| 238 | ||
| 239 | lemma mod_aux :"\<lbrakk>i < (n::nat); a mod n = i; j < a + n; j mod n = i; a < j\<rbrakk> \<Longrightarrow> False" | |
| 240 | apply(subgoal_tac "a=a div n*n + a mod n" ) | |
| 13517 | 241 | prefer 2 apply (simp (no_asm_use)) | 
| 13020 | 242 | apply(subgoal_tac "j=j div n*n + j mod n") | 
| 13517 | 243 | prefer 2 apply (simp (no_asm_use)) | 
| 13020 | 244 | apply simp | 
| 245 | apply(subgoal_tac "a div n*n < j div n*n") | |
| 246 | prefer 2 apply arith | |
| 247 | apply(subgoal_tac "j div n*n < (a div n + 1)*n") | |
| 13517 | 248 | prefer 2 apply simp | 
| 13020 | 249 | apply (simp only:mult_less_cancel2) | 
| 250 | apply arith | |
| 251 | done | |
| 252 | ||
| 253 | record Example3 = | |
| 254 | X :: "nat \<Rightarrow> nat" | |
| 255 | Y :: "nat \<Rightarrow> nat" | |
| 256 | ||
| 257 | lemma Example3: "m mod n=0 \<Longrightarrow> | |
| 258 | \<turnstile> COBEGIN | |
| 259 | SCHEME [0\<le>i<n] | |
| 260 | (WHILE (\<forall>j<n. \<acute>X i < \<acute>Y j) DO | |
| 261 | IF P(B!(\<acute>X i)) THEN \<acute>Y:=\<acute>Y (i:=\<acute>X i) | |
| 262 | ELSE \<acute>X:= \<acute>X (i:=(\<acute>X i)+ n) FI | |
| 263 | OD, | |
| 264 | \<lbrace>(\<acute>X i) mod n=i \<and> (\<forall>j<\<acute>X i. j mod n=i \<longrightarrow> \<not>P(B!j)) \<and> (\<acute>Y i<m \<longrightarrow> P(B!(\<acute>Y i)) \<and> \<acute>Y i\<le> m+i)\<rbrace>, | |
| 265 | \<lbrace>(\<forall>j<n. i\<noteq>j \<longrightarrow> \<ordfeminine>Y j \<le> \<ordmasculine>Y j) \<and> \<ordmasculine>X i = \<ordfeminine>X i \<and> | |
| 266 | \<ordmasculine>Y i = \<ordfeminine>Y i\<rbrace>, | |
| 267 | \<lbrace>(\<forall>j<n. i\<noteq>j \<longrightarrow> \<ordmasculine>X j = \<ordfeminine>X j \<and> \<ordmasculine>Y j = \<ordfeminine>Y j) \<and> | |
| 268 | \<ordfeminine>Y i \<le> \<ordmasculine>Y i\<rbrace>, | |
| 269 | \<lbrace>(\<acute>X i) mod n=i \<and> (\<forall>j<\<acute>X i. j mod n=i \<longrightarrow> \<not>P(B!j)) \<and> (\<acute>Y i<m \<longrightarrow> P(B!(\<acute>Y i)) \<and> \<acute>Y i\<le> m+i) \<and> (\<exists>j<n. \<acute>Y j \<le> \<acute>X i) \<rbrace>) | |
| 270 | COEND | |
| 271 | SAT [\<lbrace> \<forall>i<n. \<acute>X i=i \<and> \<acute>Y i=m+i \<rbrace>,\<lbrace>\<ordmasculine>X=\<ordfeminine>X \<and> \<ordmasculine>Y=\<ordfeminine>Y\<rbrace>,\<lbrace>True\<rbrace>, | |
| 272 | \<lbrace>\<forall>i<n. (\<acute>X i) mod n=i \<and> (\<forall>j<\<acute>X i. j mod n=i \<longrightarrow> \<not>P(B!j)) \<and> | |
| 273 | (\<acute>Y i<m \<longrightarrow> P(B!(\<acute>Y i)) \<and> \<acute>Y i\<le> m+i) \<and> (\<exists>j<n. \<acute>Y j \<le> \<acute>X i)\<rbrace>]" | |
| 274 | apply(rule Parallel) | |
| 13099 | 275 | --{*5 subgoals left *}
 | 
| 13020 | 276 | apply force+ | 
| 277 | apply clarify | |
| 278 | apply simp | |
| 279 | apply(rule While) | |
| 280 | apply force | |
| 281 | apply force | |
| 282 | apply force | |
| 14174 
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
 ballarin parents: 
13601diff
changeset | 283 | apply(rule_tac pre'="\<lbrace> \<acute>X i mod n = i \<and> (\<forall>j. j<\<acute>X i \<longrightarrow> j mod n = i \<longrightarrow> \<not>P(B!j)) \<and> (\<acute>Y i < n * q \<longrightarrow> P (B!(\<acute>Y i))) \<and> \<acute>X i<\<acute>Y i\<rbrace>" in Conseq) | 
| 13020 | 284 | apply force | 
| 285 | apply(rule subset_refl)+ | |
| 286 | apply(rule Cond) | |
| 287 | apply force | |
| 288 | apply(rule Basic) | |
| 289 | apply force | |
| 13187 | 290 | apply fastsimp | 
| 13020 | 291 | apply force | 
| 292 | apply force | |
| 293 | apply(rule Basic) | |
| 294 | apply simp | |
| 295 | apply clarify | |
| 296 | apply simp | |
| 297 | apply(case_tac "X x (j mod n)\<le> j") | |
| 298 | apply(drule le_imp_less_or_eq) | |
| 299 | apply(erule disjE) | |
| 300 | apply(drule_tac j=j and n=n and i="j mod n" and a="X x (j mod n)" in mod_aux) | |
| 301 | apply assumption+ | |
| 302 | apply simp+ | |
| 13103 
66659a4b16f6
Added insert_disjoint and disjoint_insert [simp], and simplified proofs
 nipkow parents: 
13099diff
changeset | 303 | apply clarsimp | 
| 13187 | 304 | apply fastsimp | 
| 13020 | 305 | apply force+ | 
| 306 | done | |
| 307 | ||
| 308 | text {* Same but with a list as auxiliary variable: *}
 | |
| 309 | ||
| 310 | record Example3_list = | |
| 311 | X :: "nat list" | |
| 312 | Y :: "nat list" | |
| 313 | ||
| 314 | lemma Example3_list: "m mod n=0 \<Longrightarrow> \<turnstile> (COBEGIN SCHEME [0\<le>i<n] | |
| 315 | (WHILE (\<forall>j<n. \<acute>X!i < \<acute>Y!j) DO | |
| 316 | IF P(B!(\<acute>X!i)) THEN \<acute>Y:=\<acute>Y[i:=\<acute>X!i] ELSE \<acute>X:= \<acute>X[i:=(\<acute>X!i)+ n] FI | |
| 317 | OD, | |
| 318 | \<lbrace>n<length \<acute>X \<and> n<length \<acute>Y \<and> (\<acute>X!i) mod n=i \<and> (\<forall>j<\<acute>X!i. j mod n=i \<longrightarrow> \<not>P(B!j)) \<and> (\<acute>Y!i<m \<longrightarrow> P(B!(\<acute>Y!i)) \<and> \<acute>Y!i\<le> m+i)\<rbrace>, | |
| 319 | \<lbrace>(\<forall>j<n. i\<noteq>j \<longrightarrow> \<ordfeminine>Y!j \<le> \<ordmasculine>Y!j) \<and> \<ordmasculine>X!i = \<ordfeminine>X!i \<and> | |
| 320 | \<ordmasculine>Y!i = \<ordfeminine>Y!i \<and> length \<ordmasculine>X = length \<ordfeminine>X \<and> length \<ordmasculine>Y = length \<ordfeminine>Y\<rbrace>, | |
| 321 | \<lbrace>(\<forall>j<n. i\<noteq>j \<longrightarrow> \<ordmasculine>X!j = \<ordfeminine>X!j \<and> \<ordmasculine>Y!j = \<ordfeminine>Y!j) \<and> | |
| 322 | \<ordfeminine>Y!i \<le> \<ordmasculine>Y!i \<and> length \<ordmasculine>X = length \<ordfeminine>X \<and> length \<ordmasculine>Y = length \<ordfeminine>Y\<rbrace>, | |
| 323 | \<lbrace>(\<acute>X!i) mod n=i \<and> (\<forall>j<\<acute>X!i. j mod n=i \<longrightarrow> \<not>P(B!j)) \<and> (\<acute>Y!i<m \<longrightarrow> P(B!(\<acute>Y!i)) \<and> \<acute>Y!i\<le> m+i) \<and> (\<exists>j<n. \<acute>Y!j \<le> \<acute>X!i) \<rbrace>) COEND) | |
| 324 | SAT [\<lbrace>n<length \<acute>X \<and> n<length \<acute>Y \<and> (\<forall>i<n. \<acute>X!i=i \<and> \<acute>Y!i=m+i) \<rbrace>, | |
| 325 | \<lbrace>\<ordmasculine>X=\<ordfeminine>X \<and> \<ordmasculine>Y=\<ordfeminine>Y\<rbrace>, | |
| 326 | \<lbrace>True\<rbrace>, | |
| 327 | \<lbrace>\<forall>i<n. (\<acute>X!i) mod n=i \<and> (\<forall>j<\<acute>X!i. j mod n=i \<longrightarrow> \<not>P(B!j)) \<and> | |
| 328 | (\<acute>Y!i<m \<longrightarrow> P(B!(\<acute>Y!i)) \<and> \<acute>Y!i\<le> m+i) \<and> (\<exists>j<n. \<acute>Y!j \<le> \<acute>X!i)\<rbrace>]" | |
| 329 | apply(rule Parallel) | |
| 13099 | 330 | --{* 5 subgoals left *}
 | 
| 13020 | 331 | apply force+ | 
| 332 | apply clarify | |
| 333 | apply simp | |
| 334 | apply(rule While) | |
| 335 | apply force | |
| 336 | apply force | |
| 337 | apply force | |
| 14174 
f3cafd2929d5
Methods rule_tac etc support static (Isar) contexts.
 ballarin parents: 
13601diff
changeset | 338 | apply(rule_tac pre'="\<lbrace>n<length \<acute>X \<and> n<length \<acute>Y \<and> \<acute>X ! i mod n = i \<and> (\<forall>j. j < \<acute>X ! i \<longrightarrow> j mod n = i \<longrightarrow> \<not> P (B ! j)) \<and> (\<acute>Y ! i < n * q \<longrightarrow> P (B ! (\<acute>Y ! i))) \<and> \<acute>X!i<\<acute>Y!i\<rbrace>" in Conseq) | 
| 13020 | 339 | apply force | 
| 340 | apply(rule subset_refl)+ | |
| 341 | apply(rule Cond) | |
| 342 | apply force | |
| 343 | apply(rule Basic) | |
| 344 | apply force | |
| 345 | apply force | |
| 346 | apply force | |
| 347 | apply force | |
| 348 | apply(rule Basic) | |
| 349 | apply simp | |
| 350 | apply clarify | |
| 351 | apply simp | |
| 352 | apply(rule allI) | |
| 353 | apply(rule impI)+ | |
| 354 | apply(case_tac "X x ! i\<le> j") | |
| 355 | apply(drule le_imp_less_or_eq) | |
| 356 | apply(erule disjE) | |
| 357 | apply(drule_tac j=j and n=n and i=i and a="X x ! i" in mod_aux) | |
| 358 | apply assumption+ | |
| 359 | apply simp | |
| 360 | apply force+ | |
| 361 | done | |
| 362 | ||
| 13187 | 363 | end |