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