theory Corres_C

lemma ccorres_mapM_x_while_genQ:
  fixes xf :: "globals myvars \<Rightarrow> ('c :: len) word"
  assumes rl: "\<forall>n. n < length xs \<longrightarrow> ccorres dc xfdc (F (n * j)) ({s. xf s = of_nat n * of_nat j} \<inter> Q) hs (f (xs ! n)) body"
  and  guard: "\<And>n. P n = (n < of_nat (length xs * j))"
  and  bodyi: "\<forall>s. xf s < of_nat (length xs * j)
    \<longrightarrow> \<Gamma>\<turnstile>\<^bsub>/UNIV\<^esub> ({s} \<inter> Q) body {t. xf t = xf s \<and> xf_update (\<lambda>x. xf t + of_nat j) t \<in> Q}"
  and  hi: "\<And>n. Suc n < length xs \<Longrightarrow> \<lbrace>F (n * j)\<rbrace> f (xs ! n) \<lbrace>\<lambda>_. F (Suc n * j)\<rbrace>"
  and  wb: "length xs * j < 2 ^ len_of TYPE('c)"
  and  xf: "\<forall>s f. xf (xf_update f s) = f (xf s) \<and> globals (xf_update f s) = globals s"
  and   j: "0 < j"
  shows  "ccorres (\<lambda>rv rv'. rv' = of_nat (length xs) * of_nat j) xf (\<lambda>s. P 0 \<longrightarrow> F (0 :: nat) s)
                  {s. xf_update (\<lambda>_. 0) s \<in> Q} hs
                  (mapM_x f xs)
                  (Basic (\<lambda>s. xf_update (\<lambda>_. 0) s);;
          (While {s. P (xf s)}
              (body ;; Basic (\<lambda>s. xf_update (\<lambda>_. xf s + of_nat j) s))))" unfolding mapM_x_def apply (rule ccorres_rel_imp) apply (rule ccorres_sequence_x_while_genQ[where xf_update=xf_update]) apply (simp add: assms hi[simplified])+ done

(* Proof state trace *)
proof (prove)
goal (1 subgoal):
 1. ccorres (\<lambda>rv rv'. rv' = word_of_nat (length xs) * word_of_nat j) xf (\<lambda>s. P 0 \<longrightarrow> F 0 s) {s. xf_update (\<lambda>_. 0) s \<in> Q} hs (mapM_x f xs) (Basic (xf_update (\<lambda>_. 0));;
While {s. P (xf s)} (body;;
Basic (\<lambda>s. xf_update (\<lambda>_. xf s + word_of_nat j) s))) proof (prove)
goal (1 subgoal):
 1. ccorres (\<lambda>rv rv'. rv' = word_of_nat (length xs) * word_of_nat j) xf (\<lambda>s. P 0 \<longrightarrow> F 0 s) {s. xf_update (\<lambda>_. 0) s \<in> Q} hs (sequence_x (map f xs)) (Basic (xf_update (\<lambda>_. 0));;
While {s. P (xf s)} (body;;
Basic (\<lambda>s. xf_update (\<lambda>_. xf s + word_of_nat j) s))) proof (prove)
goal (2 subgoals):
 1. ccorres ?r' ?xf' (\<lambda>s. P 0 \<longrightarrow> F 0 s) {s. xf_update (\<lambda>_. 0) s \<in> Q} hs (sequence_x (map f xs)) (Basic (xf_update (\<lambda>_. 0));;
While {s. P (xf s)} (body;;
Basic (\<lambda>s. xf_update (\<lambda>_. xf s + word_of_nat j) s)))
 2. \<And>x y. ?r' x (?xf' y) \<Longrightarrow> xf y = word_of_nat (length xs) * word_of_nat j proof (prove)
goal (8 subgoals):
 1. \<forall>n<length (map f xs). ccorres dc xfdc (F (n * j)) ({s. xf s = word_of_nat n * word_of_nat j} \<inter> Q) hs (map f xs ! n) body
 2. \<And>n. P n = (n < word_of_nat (length (map f xs) * j))
 3. \<forall>s. xf s < word_of_nat (length (map f xs) * j) \<longrightarrow> \<Gamma>\<turnstile>\<^bsub>/UNIV\<^esub> ({s} \<inter> Q) body {t. xf t = xf s \<and> xf_update (\<lambda>x. xf t + word_of_nat j) t \<in> Q}
 4. \<And>n. Suc n < length (map f xs) \<Longrightarrow> \<lbrace>F (n * j)\<rbrace> map f xs ! n \<lbrace>\<lambda>_. F (Suc n * j)\<rbrace>
 5. length (map f xs) * j < 2 ^ LENGTH('c)
 6. \<forall>s f. xf (xf_update f s) = f (xf s) \<and> globals (xf_update f s) = globals s
 7. 0 < j
 8. \<And>x y. xf y = word_of_nat (length (map f xs)) * word_of_nat j \<Longrightarrow> xf y = word_of_nat (length xs) * word_of_nat j proof (prove)
goal:
No subgoals!