[STATEMENT]
lemma star_rectangle_decompose:
  assumes "rectangle a"
  shows "(a \<squnion> x)\<^sup>\<star> = x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a \<squnion> x)\<^sup>\<star> = x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
proof (rule order.antisym)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
have 1: "1 \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reflexive (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>)
[PROOF STEP]
by (simp add: star.circ_reflexive sup.coboundedI1)
[PROOF STATE]
proof (state)
this:
reflexive (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>)

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
have "(a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) = a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) = a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>
[PROOF STEP]
by (metis comp_associative semiring.combine_common_factor semiring.distrib_left sup_commute)
[PROOF STATE]
proof (state)
this:
(a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) = a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) = a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
have "... = a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>
[PROOF STEP]
using assms rectangle_star_rectangle
[PROOF STATE]
proof (prove)
using this:
rectangle a
rectangle ?a \<Longrightarrow> ?a * ?x\<^sup>\<star> * ?a \<le> ?a

goal (1 subgoal):
 1. a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>
[PROOF STEP]
by (simp add: mult_left_isotone sup_absorb1)
[PROOF STATE]
proof (state)
this:
a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
a * x\<^sup>\<star> \<squnion> a * x\<^sup>\<star> * a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
have "... = x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
by (metis comp_associative star.circ_loop_fixpoint sup_assoc sup_commute)
[PROOF STATE]
proof (state)
this:
a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
a * x\<^sup>\<star> \<squnion> x\<^sup>+ \<squnion> x\<^sup>+ * a * x\<^sup>\<star> = x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
have "... \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
using star.left_plus_below_circ sup_left_isotone
[PROOF STATE]
proof (prove)
using this:
?x\<^sup>+ \<le> ?x\<^sup>\<star>
?x \<le> ?y \<Longrightarrow> ?x \<squnion> ?z \<le> ?y \<squnion> ?z

goal (1 subgoal):
 1. x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x\<^sup>+ \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>

goal (2 subgoals):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
 2. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
show "(a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>"
[PROOF STATE]
proof (prove)
using this:
(a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>

goal (1 subgoal):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
using 1
[PROOF STATE]
proof (prove)
using this:
(a \<squnion> x) * (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>) \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
reflexive (x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>)

goal (1 subgoal):
 1. (a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>
[PROOF STEP]
by (metis comp_right_one le_supI star_left_induct)
[PROOF STATE]
proof (state)
this:
(a \<squnion> x)\<^sup>\<star> \<le> x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star>

goal (1 subgoal):
 1. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
show "x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>
[PROOF STEP]
by (metis comp_isotone le_supE le_supI star.circ_increasing star.circ_transitive_equal star_isotone sup_ge2)
[PROOF STATE]
proof (state)
this:
x\<^sup>\<star> \<squnion> x\<^sup>\<star> * a * x\<^sup>\<star> \<le> (a \<squnion> x)\<^sup>\<star>

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma lm04_24_multiple_step_states:
fixes c :: nat
    and l :: register
    and ic :: configuration
    and p :: program
    and q :: nat
    and a :: nat

  defines "b == B c"
      and "m == length p"

assumes is_val: "is_valid_initial ic p a"
assumes c_gt_cells: "cells_bounded ic p c"
assumes d: "d \<le> m-1" and "0 < d"
    and q: "q > 0"

assumes terminate: "terminates ic p q"

assumes c: "c > 1"

  defines "r \<equiv> RLe ic p b q"
      and "z \<equiv> ZLe ic p b q"
      and "s \<equiv> SKe ic p b q"
      and "e \<equiv> \<Sum>t = 0..q. b^t"

shows "s d = b * (\<Sum>S+ p d s)
           + b * (\<Sum>S- p d (\<lambda>k. z (modifies (p!k)) && s k))
           + b * (\<Sum>S0 p d (\<lambda>k. (e - z (modifies (p!k))) && s k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "program_includes_halt p"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. program_includes_halt p
[PROOF STEP]
using is_val is_valid_initial_def[of "ic" "p" "a"] is_valid_def[of "ic" "p"]
[PROOF STATE]
proof (prove)
using this:
is_valid_initial ic p a
is_valid_initial ic p a = (is_valid ic p \<and> tape_check_initial (snd ic) a \<and> fst ic = 0)
is_valid ic p = (program_includes_halt p \<and> program_state_check p \<and> program_register_check p (length (snd ic)))

goal (1 subgoal):
 1. program_includes_halt p
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
program_includes_halt p

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have halt_term0: "t \<le> q-1 \<longrightarrow> (if ishalt (p!(fst (steps ic p t))) \<and> d = fst (steps ic p t)
                                    then Suc 0 else 0) = 0" for t
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. t \<le> q - 1 \<longrightarrow> (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0) = 0
[PROOF STEP]
using terminate terminates_def
[PROOF STATE]
proof (prove)
using this:
terminates ic p q
terminates ?c ?p ?q = (0 < ?q \<and> correct_halt ?c ?p ?q \<and> (\<forall>x<?q. \<not> ishalt (?p ! fst (steps ?c ?p x))))

goal (1 subgoal):
 1. t \<le> q - 1 \<longrightarrow> (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0) = 0
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?t \<le> q - 1 \<longrightarrow> (if ishalt (p ! fst (steps ic p ?t)) \<and> d = fst (steps ic p ?t) then Suc 0 else 0) = 0

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have single_step: "S ic p d (Suc t) = (\<Sum>S+ p d (\<lambda>k. S ic p k t))
                   + (\<Sum>S- p d (\<lambda>k. Z ic p (modifies (p!k)) t * S ic p k t))
                   + (\<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p!k)) t) * S ic p k t))
                   + (if ishalt (p!(fst (steps ic p t))) \<and> d = fst (steps ic p t) then Suc 0 else 0)" for t
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. S ic p d (Suc t) = \<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0)
[PROOF STEP]
using lm04_07_one_step_relation_state[of "ic" "p" "a" "d"] is_val `d>0` d
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>is_valid_initial ic p a; d < length p\<rbrakk> \<Longrightarrow> S ic p d (Suc ?t) = \<Sum>S+ p d (\<lambda>k. S ic p k ?t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) ?t * S ic p k ?t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) ?t) * S ic p k ?t)  + (if ishalt (p ! fst (steps ic p ?t)) \<and> d = fst (steps ic p ?t) then Suc 0 else 0)
is_valid_initial ic p a
0 < d
d \<le> m - 1

goal (1 subgoal):
 1. S ic p d (Suc t) = \<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0)
[PROOF STEP]
by (simp add: m_def)
[PROOF STATE]
proof (state)
this:
S ic p d (Suc ?t) = \<Sum>S+ p d (\<lambda>k. S ic p k ?t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) ?t * S ic p k ?t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) ?t) * S ic p k ?t)  + (if ishalt (p ! fst (steps ic p ?t)) \<and> d = fst (steps ic p ?t) then Suc 0 else 0)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have b: "b > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < b
[PROOF STEP]
using b_def B_def
[PROOF STATE]
proof (prove)
using this:
b \<equiv> B c
B ?c = 2 ^ Suc ?c

goal (1 subgoal):
 1. 0 < b
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
0 < b

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have halt: "ishalt (p!fst(steps ic p q))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ishalt (p ! fst (steps ic p q))
[PROOF STEP]
using terminate terminates_def correct_halt_def
[PROOF STATE]
proof (prove)
using this:
terminates ic p q
terminates ?c ?p ?q = (0 < ?q \<and> correct_halt ?c ?p ?q \<and> (\<forall>x<?q. \<not> ishalt (?p ! fst (steps ?c ?p x))))
correct_halt ?c ?p ?q = (ishalt (?p ! fst (steps ?c ?p ?q)) \<and> (\<forall>l<length (snd ?c). snd (steps ?c ?p ?q) ! l = 0))

goal (1 subgoal):
 1. ishalt (p ! fst (steps ic p q))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ishalt (p ! fst (steps ic p q))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have add_conditions: "(if isadd (p ! k) \<and> d = goes_to (p ! k)
            then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0)
         = (if isadd (p ! k) \<and> d = goes_to (p ! k)
            then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
[PROOF STEP]
apply (cases "p!k"; cases "d = goes_to (p!k)")
[PROOF STATE]
proof (prove)
goal (6 subgoals):
 1. \<And>x11 x12. \<lbrakk>p ! k = Add x11 x12; d = goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 2. \<And>x11 x12. \<lbrakk>p ! k = Add x11 x12; d \<noteq> goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 3. \<And>x21 x22 x23. \<lbrakk>p ! k = Sub x21 x22 x23; d = goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 4. \<And>x21 x22 x23. \<lbrakk>p ! k = Sub x21 x22 x23; d \<noteq> goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 5. \<lbrakk>p ! k = Halt; d = goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 6. \<lbrakk>p ! k = Halt; d \<noteq> goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
[PROOF STEP]
using q S_def b halt
[PROOF STATE]
proof (prove)
using this:
0 < q
S ?c ?p ?k ?t = (if fst (steps ?c ?p ?t) = ?k then Suc 0 else 0)
0 < b
ishalt (p ! fst (steps ic p q))

goal (6 subgoals):
 1. \<And>x11 x12. \<lbrakk>p ! k = Add x11 x12; d = goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 2. \<And>x11 x12. \<lbrakk>p ! k = Add x11 x12; d \<noteq> goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 3. \<And>x21 x22 x23. \<lbrakk>p ! k = Sub x21 x22 x23; d = goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 4. \<And>x21 x22 x23. \<lbrakk>p ! k = Sub x21 x22 x23; d \<noteq> goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 5. \<lbrakk>p ! k = Halt; d = goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
 6. \<lbrakk>p ! k = Halt; d \<noteq> goes_to (p ! k)\<rbrakk> \<Longrightarrow> (if isadd (p ! k) \<and> d = goes_to (p ! k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t) + b ^ q * S ic p k q else 0) = (if isadd (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p k t else 0)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if isadd (p ! ?k) \<and> d = goes_to (p ! ?k) then (\<Sum>t = 0..q - Suc 0. b ^ t * S ic p ?k t) + b ^ q * S ic p ?k q else 0) = (if isadd (p ! ?k) \<and> d = goes_to (p ! ?k) then \<Sum>t = 0..q - Suc 0. b ^ t * S ic p ?k t else 0)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "b * b ^ (q - Suc 0) = b ^ (q - Suc 0 + Suc 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b * b ^ (q - Suc 0) = b ^ (q - Suc 0 + Suc 0)
[PROOF STEP]
using q
[PROOF STATE]
proof (prove)
using this:
0 < q

goal (1 subgoal):
 1. b * b ^ (q - Suc 0) = b ^ (q - Suc 0 + Suc 0)
[PROOF STEP]
by (simp add: power_eq_if)
[PROOF STATE]
proof (state)
this:
b * b ^ (q - Suc 0) = b ^ (q - Suc 0 + Suc 0)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "(\<lambda>k. (\<Sum>t = 0..(q-1).       b^t * S ic p k t) + b^(Suc (q-1)) * S ic p k (Suc (q-1)))
      = (\<lambda>k. (\<Sum>t = 0..(Suc (q-1)). b^t * S ic p k t))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ Suc (q - 1) * S ic p k (Suc (q - 1))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ Suc (q - 1) * S ic p k (Suc (q - 1))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence "\<Sum>S+ p d (\<lambda>k. (\<Sum>t = 0..(q-1).       b^t * S ic p k t) + b^q * S ic p k (Suc (q-1)))
       = \<Sum>S+ p d (\<lambda>k.  \<Sum>t = 0..(Suc (q-1)). b^t * S ic p k t)"
[PROOF STATE]
proof (prove)
using this:
(\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ Suc (q - 1) * S ic p k (Suc (q - 1))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)

goal (1 subgoal):
 1. \<Sum>S+ p d (\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ q * S ic p k (Suc (q - 1)))  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)
[PROOF STEP]
using q
[PROOF STATE]
proof (prove)
using this:
(\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ Suc (q - 1) * S ic p k (Suc (q - 1))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)
0 < q

goal (1 subgoal):
 1. \<Sum>S+ p d (\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ q * S ic p k (Suc (q - 1)))  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Sum>S+ p d (\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ q * S ic p k (Suc (q - 1)))  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence add_q: "\<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..(q-1). b^t * S ic p k t)
              = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b^t * S ic p k t)"
[PROOF STATE]
proof (prove)
using this:
\<Sum>S+ p d (\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * S ic p k t) + b ^ q * S ic p k (Suc (q - 1)))  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * S ic p k t)

goal (1 subgoal):
 1. \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)
[PROOF STEP]
by (auto simp add: sum_sadd.simps q add_conditions)
[PROOF STATE]
proof (state)
this:
\<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "issub (p!k) \<Longrightarrow> b ^ (Suc (q-1)) * (Z ic p (modifies (p ! k)) (Suc (q-1)) *
        (if fst (steps ic p (Suc (q-1))) = k then Suc 0 else 0)) = 0" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> b ^ Suc (q - 1) * (Z ic p (modifies (p ! k)) (Suc (q - 1)) * (if fst (steps ic p (Suc (q - 1))) = k then Suc 0 else 0)) = 0
[PROOF STEP]
by (auto simp: q halt)
[PROOF STATE]
proof (state)
this:
issub (p ! ?k) \<Longrightarrow> b ^ Suc (q - 1) * (Z ic p (modifies (p ! ?k)) (Suc (q - 1)) * (if fst (steps ic p (Suc (q - 1))) = ?k then Suc 0 else 0)) = 0

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence sum_equiv_nzero: "issub (p!k) \<Longrightarrow>
        (\<Sum>t = 0..q-1. b ^ t * (Z ic p (modifies (p ! k)) t *
            (if fst (steps ic p t) = k then Suc 0 else 0)))
      = (\<Sum>t = 0..(Suc (q-1)). b ^ t * (Z ic p (modifies (p ! k)) t *
            (if fst (steps ic p t) = k then Suc 0 else 0)))" for k
[PROOF STATE]
proof (prove)
using this:
issub (p ! ?k) \<Longrightarrow> b ^ Suc (q - 1) * (Z ic p (modifies (p ! ?k)) (Suc (q - 1)) * (if fst (steps ic p (Suc (q - 1))) = ?k then Suc 0 else 0)) = 0

goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0)))
[PROOF STEP]
using sum.atLeast0_atMost_Suc[of "\<lambda>t. b ^ t * (Z ic p (modifies (p ! k)) t
                                  * (if fst (steps ic p t) = k then Suc 0 else 0))" "q-1"]
[PROOF STATE]
proof (prove)
using this:
issub (p ! ?k) \<Longrightarrow> b ^ Suc (q - 1) * (Z ic p (modifies (p ! ?k)) (Suc (q - 1)) * (if fst (steps ic p (Suc (q - 1))) = ?k then Suc 0 else 0)) = 0
(\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) + b ^ Suc (q - 1) * (Z ic p (modifies (p ! k)) (Suc (q - 1)) * (if fst (steps ic p (Suc (q - 1))) = k then Suc 0 else 0))

goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
issub (p ! ?k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! ?k)) t * (if fst (steps ic p t) = ?k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! ?k)) t * (if fst (steps ic p t) = ?k then Suc 0 else 0)))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence sub_nzero_conditions: "(if issub (p ! k) \<and> d = goes_to (p ! k) then
          \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)
       = (if issub (p ! k) \<and> d = goes_to (p ! k) then
          \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)" for k
[PROOF STATE]
proof (prove)
using this:
issub (p ! ?k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! ?k)) t * (if fst (steps ic p t) = ?k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! ?k)) t * (if fst (steps ic p t) = ?k then Suc 0 else 0)))

goal (1 subgoal):
 1. (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)
[PROOF STEP]
apply (cases "issub (p!k)")
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>\<And>k. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))); issub (p ! k)\<rbrakk> \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)
 2. \<lbrakk>\<And>k. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))); \<not> issub (p ! k)\<rbrakk> \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)
[PROOF STEP]
using q S_def halt b
[PROOF STATE]
proof (prove)
using this:
0 < q
S ?c ?p ?k ?t = (if fst (steps ?c ?p ?t) = ?k then Suc 0 else 0)
ishalt (p ! fst (steps ic p q))
0 < b

goal (2 subgoals):
 1. \<lbrakk>\<And>k. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))); issub (p ! k)\<rbrakk> \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)
 2. \<lbrakk>\<And>k. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))) = (\<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * (if fst (steps ic p t) = k then Suc 0 else 0))); \<not> issub (p ! k)\<rbrakk> \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to (p ! k) then \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t) else 0)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if issub (p ! ?k) \<and> d = goes_to (p ! ?k) then \<Sum>t = 0..q - Suc 0. b ^ t * (Z ic p (modifies (p ! ?k)) t * S ic p ?k t) else 0) = (if issub (p ! ?k) \<and> d = goes_to (p ! ?k) then \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! ?k)) t * S ic p ?k t) else 0)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "(\<lambda>k. (\<Sum>t=0..(q-1). b^t * (Z ic p (modifies (p!k)) t * S ic p k t))
                    + b^(Suc (q-1)) * (Z ic p (modifies (p!k)) (Suc (q-1)) * S ic p k (Suc (q-1))))
      = (\<lambda>k. \<Sum>t=0..(Suc (q-1)). b^t * (Z ic p (modifies (p!k)) t * S ic p k t))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) + b ^ Suc (q - 1) * (Z ic p (modifies (p ! k)) (Suc (q - 1)) * S ic p k (Suc (q - 1)))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) + b ^ Suc (q - 1) * (Z ic p (modifies (p ! k)) (Suc (q - 1)) * S ic p k (Suc (q - 1)))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence sub_nzero_q: "(\<Sum>S- p d (\<lambda>k. \<Sum>t=0..(q-1). b^t * (Z ic p (modifies (p!k)) t * S ic p k t)))
                   = (\<Sum>S- p d (\<lambda>k. \<Sum>t=0..q. b^t * (Z ic p (modifies (p!k)) t * S ic p k t)))"
[PROOF STATE]
proof (prove)
using this:
(\<lambda>k. (\<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) + b ^ Suc (q - 1) * (Z ic p (modifies (p ! k)) (Suc (q - 1)) * S ic p k (Suc (q - 1)))) = (\<lambda>k. \<Sum>t = 0..Suc (q - 1). b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))

goal (1 subgoal):
 1. \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  = \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))
[PROOF STEP]
by (auto simp: sum_ssub_nzero.simps q sub_nzero_conditions)
[PROOF STATE]
proof (state)
this:
\<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  = \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "issub (p!k) \<Longrightarrow> b ^ (Suc (q-1)) * ((Suc 0 - Z ic p (modifies (p ! k)) (Suc (q-1)))
          * S ic p k (Suc (q-1))) = 0" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> b ^ Suc (q - 1) * ((Suc 0 - Z ic p (modifies (p ! k)) (Suc (q - 1))) * S ic p k (Suc (q - 1))) = 0
[PROOF STEP]
using q halt S_def
[PROOF STATE]
proof (prove)
using this:
0 < q
ishalt (p ! fst (steps ic p q))
S ?c ?p ?k ?t = (if fst (steps ?c ?p ?t) = ?k then Suc 0 else 0)

goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> b ^ Suc (q - 1) * ((Suc 0 - Z ic p (modifies (p ! k)) (Suc (q - 1))) * S ic p k (Suc (q - 1))) = 0
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
issub (p ! ?k) \<Longrightarrow> b ^ Suc (q - 1) * ((Suc 0 - Z ic p (modifies (p ! ?k)) (Suc (q - 1))) * S ic p ?k (Suc (q - 1))) = 0

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence sum_equiv_zero: "issub (p!k) \<Longrightarrow>
         (\<Sum>t = 0..q-1. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t))
       = (\<Sum>t = 0..Suc (q-1). b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t))" for k
[PROOF STATE]
proof (prove)
using this:
issub (p ! ?k) \<Longrightarrow> b ^ Suc (q - 1) * ((Suc 0 - Z ic p (modifies (p ! ?k)) (Suc (q - 1))) * S ic p ?k (Suc (q - 1))) = 0

goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t)) = (\<Sum>t = 0..Suc (q - 1). b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
using sum.atLeast0_atMost_Suc[of "\<lambda>t. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t)
                                      * S ic p k t)" "q-1"]
[PROOF STATE]
proof (prove)
using this:
issub (p ! ?k) \<Longrightarrow> b ^ Suc (q - 1) * ((Suc 0 - Z ic p (modifies (p ! ?k)) (Suc (q - 1))) * S ic p ?k (Suc (q - 1))) = 0
(\<Sum>t = 0..Suc (q - 1). b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t)) = (\<Sum>t = 0..q - 1. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t)) + b ^ Suc (q - 1) * ((Suc 0 - Z ic p (modifies (p ! k)) (Suc (q - 1))) * S ic p k (Suc (q - 1)))

goal (1 subgoal):
 1. issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t)) = (\<Sum>t = 0..Suc (q - 1). b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
issub (p ! ?k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t)) = (\<Sum>t = 0..Suc (q - 1). b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "(if issub (p ! k) \<and> d = goes_to_alt (p ! k) then
            \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)
      = (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then
            \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)
[PROOF STEP]
apply (cases "issub (p!k)")
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. issub (p ! k) \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)
 2. \<not> issub (p ! k) \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)
[PROOF STEP]
using sum_equiv_zero[of "k"] q
[PROOF STATE]
proof (prove)
using this:
issub (p ! k) \<Longrightarrow> (\<Sum>t = 0..q - 1. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t)) = (\<Sum>t = 0..Suc (q - 1). b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t))
0 < q

goal (2 subgoals):
 1. issub (p ! k) \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)
 2. \<not> issub (p ! k) \<Longrightarrow> (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0) = (if issub (p ! k) \<and> d = goes_to_alt (p ! k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! k)) t) * S ic p k t) else 0)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if issub (p ! ?k) \<and> d = goes_to_alt (p ! ?k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t) else 0) = (if issub (p ! ?k) \<and> d = goes_to_alt (p ! ?k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t) else 0)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
hence sub_zero_q: "(\<Sum>S0 p d (\<lambda>k.\<Sum>t=0..q-1. b^t * ((1 - Z ic p (modifies(p!k)) t) * S ic p k t)))
                   = (\<Sum>S0 p d (\<lambda>k.\<Sum>t=0..q. b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
using this:
(if issub (p ! ?k) \<and> d = goes_to_alt (p ! ?k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t) else 0) = (if issub (p ! ?k) \<and> d = goes_to_alt (p ! ?k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t) else 0)

goal (1 subgoal):
 1. \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
using sum_ssub_zero.simps q
[PROOF STATE]
proof (prove)
using this:
(if issub (p ! ?k) \<and> d = goes_to_alt (p ! ?k) then \<Sum>t = 0..q - Suc 0. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t) else 0) = (if issub (p ! ?k) \<and> d = goes_to_alt (p ! ?k) then \<Sum>t = 0..q. b ^ t * ((Suc 0 - Z ic p (modifies (p ! ?k)) t) * S ic p ?k t) else 0)
\<Sum>S0 ?p ?d ?f  = (\<Sum>k = 0..length ?p - 1. if issub (?p ! k) \<and> ?d = goes_to_alt (?p ! k) then ?f k else 0)
0 < q

goal (1 subgoal):
 1. \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
(* Start *)
[PROOF STATE]
proof (state)
this:
\<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "s d = (\<Sum>t = 0..q. b^t * S ic p d t)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. s d = (\<Sum>t = 0..q. b ^ t * S ic p d t)
[PROOF STEP]
using s_def SKe_def
[PROOF STATE]
proof (prove)
using this:
s \<equiv> SKe ic p b q
SKe ?c ?p ?b ?q ?k = (\<Sum>t = 0..?q. ?b ^ t * S ?c ?p ?k t)

goal (1 subgoal):
 1. s d = (\<Sum>t = 0..q. b ^ t * S ic p d t)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
s d = (\<Sum>t = 0..q. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
s d = (\<Sum>t = 0..q. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = S ic p d 0 + (\<Sum>t = 1..q. b^t * S ic p d t)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t = 0..q. b ^ t * S ic p d t) = S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t)
[PROOF STEP]
by (auto simp: q comm_monoid_add_class.sum.atLeast_Suc_atMost)
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q. b ^ t * S ic p d t) = S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q. b ^ t * S ic p d t) = S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = (\<Sum>t = 1..q. b^t * S ic p d t)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t = 1..q. b ^ t * S ic p d t)
[PROOF STEP]
using S_def `d>0` is_val is_valid_initial_def[of "ic" "p" "a"]
[PROOF STATE]
proof (prove)
using this:
S ?c ?p ?k ?t = (if fst (steps ?c ?p ?t) = ?k then Suc 0 else 0)
0 < d
is_valid_initial ic p a
is_valid_initial ic p a = (is_valid ic p \<and> tape_check_initial (snd ic) a \<and> fst ic = 0)

goal (1 subgoal):
 1. S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t = 1..q. b ^ t * S ic p d t)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t = 1..q. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
S ic p d 0 + (\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t = 1..q. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = (\<Sum>t \<in> (Suc ` {0..(q-1)}). b^t * S ic p d t)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t)
[PROOF STEP]
using q
[PROOF STATE]
proof (prove)
using this:
0 < q

goal (1 subgoal):
 1. (\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 1..q. b ^ t * S ic p d t) = (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = (sum  ((\<lambda>t. b^t * S ic p d t) \<circ> Suc)) {0..(q-1)}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t) = sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1}
[PROOF STEP]
using comm_monoid_add_class.sum.reindex[of "Suc" "{0..(q-1)}" "(\<lambda>t. b^t * S ic p d t)"]
[PROOF STATE]
proof (prove)
using this:
inj_on Suc {0..q - 1} \<Longrightarrow> (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t) = sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1}

goal (1 subgoal):
 1. (\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t) = sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t) = sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1}

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t\<in>Suc ` {0..q - 1}. b ^ t * S ic p d t) = sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1}

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = (\<Sum>t = 0..(q-1). b^(Suc t) *((\<Sum>S+ p d (\<lambda>k. S ic p k t))
                                 + (\<Sum>S- p d (\<lambda>k. Z ic p (modifies (p!k)) t * S ic p k t))
                                 + (\<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p!k)) t) * S ic p k t))
                                 + (if ishalt (p!(fst (steps ic p t))) \<and> d = fst (steps ic p t)
                                    then Suc 0 else 0)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1} = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0)))
[PROOF STEP]
using single_step
[PROOF STATE]
proof (prove)
using this:
S ic p d (Suc ?t) = \<Sum>S+ p d (\<lambda>k. S ic p k ?t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) ?t * S ic p k ?t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) ?t) * S ic p k ?t)  + (if ishalt (p ! fst (steps ic p ?t)) \<and> d = fst (steps ic p ?t) then Suc 0 else 0)

goal (1 subgoal):
 1. sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1} = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1} = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0)))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
sum ((\<lambda>t. b ^ t * S ic p d t) \<circ> Suc) {0..q - 1} = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0)))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = (\<Sum>t = 0..(q-1). b^(Suc t) *((\<Sum>S+ p d (\<lambda>k. S ic p k t))
                                 + (\<Sum>S- p d (\<lambda>k. Z ic p (modifies (p!k)) t * S ic p k t))
                                 + (\<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p!k)) t) * S ic p k t))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0))) = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ))
[PROOF STEP]
using halt_term0
[PROOF STATE]
proof (prove)
using this:
?t \<le> q - 1 \<longrightarrow> (if ishalt (p ! fst (steps ic p ?t)) \<and> d = fst (steps ic p ?t) then Suc 0 else 0) = 0

goal (1 subgoal):
 1. (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0))) = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0))) = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t)  + (if ishalt (p ! fst (steps ic p t)) \<and> d = fst (steps ic p t) then Suc 0 else 0))) = (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... =  (\<Sum>t = 0..(q-1). (b^(Suc t) * (\<Sum>S+ p d (\<lambda>k. S ic p k t))
                      + b^(Suc t) * (\<Sum>S- p d (\<lambda>k. Z ic p (modifies (p!k)) t * S ic p k t))
                      + b^(Suc t) * (\<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p!k)) t) * S ic p k t))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )) = (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t)  + b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )
[PROOF STEP]
by (simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )) = (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t)  + b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * (\<Sum>S+ p d (\<lambda>k. S ic p k t)  + \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )) = (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t)  + b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = (\<Sum>t = 0..(q-1). (b^(Suc t) * (\<Sum>S+ p d (\<lambda>k. S ic p k t))))
           +(\<Sum>t=0..(q-1). b^(Suc t)*(\<Sum>S- p d (\<lambda>k. Z ic p (modifies (p!k)) t * S ic p k t)))
           +(\<Sum>t=0..(q-1). b^(Suc t)*(\<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t)  + b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )
[PROOF STEP]
by (auto simp only: sum.distrib)
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t)  + b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t)  + b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t)  + b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = b * (\<Sum>t = 0..(q-1). (b^t * (\<Sum>S+ p d (\<lambda>k. S ic p k t))))
           + b*(\<Sum>t=0..(q-1). b^t*(\<Sum>S- p d (\<lambda>k. Z ic p (modifies (p!k)) t * S ic p k t)))
           + b*(\<Sum>t=0..(q-1). b^t*(\<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )
[PROOF STEP]
by (auto simp: algebra_simps sum_distrib_left)
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + (\<Sum>t = 0..q - 1. b ^ Suc t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = b * (\<Sum>t = 0..(q-1). (\<Sum>S+ p d (\<lambda>k. b^t * S ic p k t)))
          + b*(\<Sum>t=0..(q-1). (\<Sum>S- p d (\<lambda>k. b^t * (Z ic p (modifies (p!k)) t * S ic p k t))))
          + b*(\<Sum>t=0..(q-1). (\<Sum>S0 p d (\<lambda>k. b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) )
[PROOF STEP]
using sum_sadd_distrib sum_ssub_nzero_distrib sum_ssub_zero_distrib
[PROOF STATE]
proof (prove)
using this:
?a * \<Sum>S+ ?p ?d ?f  = \<Sum>S+ ?p ?d (\<lambda>k. ?a * ?f k)
?a * \<Sum>S- ?p ?d ?f  = \<Sum>S- ?p ?d (\<lambda>k. ?a * ?f k)
?a * \<Sum>S0 ?p ?d ?f  = \<Sum>S0 ?p ?d (\<lambda>k. ?a * ?f k)

goal (1 subgoal):
 1. b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) )
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S+ p d (\<lambda>k. S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S- p d (\<lambda>k. Z ic p (modifies (p ! k)) t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. b ^ t * \<Sum>S0 p d (\<lambda>k. (1 - Z ic p (modifies (p ! k)) t) * S ic p k t) ) = b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) )

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = b * (\<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..(q-1). b^t * S ic p k t))
           + b*(\<Sum>S- p d (\<lambda>k. \<Sum>t=0..(q-1). b^t * (Z ic p (modifies (p!k)) t * S ic p k t)))
           + b*(\<Sum>S0 p d (\<lambda>k. \<Sum>t=0..(q-1). b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) ) = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
using sum_sadd_commutative sum_ssub_nzero_commutative sum_ssub_zero_commutative
[PROOF STATE]
proof (prove)
using this:
(\<Sum>t = 0..?q. \<Sum>S+ ?p ?l (\<lambda>k. ?f k t) ) = \<Sum>S+ ?p ?l (\<lambda>k. sum (?f k) {0..?q})
(\<Sum>t = 0..?q. \<Sum>S- ?p ?l (\<lambda>k. ?f k t) ) = \<Sum>S- ?p ?l (\<lambda>k. sum (?f k) {0..?q})
(\<Sum>t = 0..?q. \<Sum>S0 ?p ?l (\<lambda>k. ?f k t) ) = \<Sum>S0 ?p ?l (\<lambda>k. sum (?f k) {0..?q})

goal (1 subgoal):
 1. b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) ) = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) ) = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
(* extend all sums until q *)
[PROOF STATE]
proof (state)
this:
b * (\<Sum>t = 0..q - 1. \<Sum>S+ p d (\<lambda>k. b ^ t * S ic p k t) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S- p d (\<lambda>k. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t)) ) + b * (\<Sum>t = 0..q - 1. \<Sum>S0 p d (\<lambda>k. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t)) ) = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
have eq1: "s d = b * (\<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b^t * S ic p k t))
           + b*(\<Sum>S- p d (\<lambda>k. \<Sum>t=0..q. b^t * (Z ic p (modifies (p!k)) t * S ic p k t)))
           + b*(\<Sum>S0 p d (\<lambda>k. \<Sum>t=0..q. b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
using add_q sub_nzero_q sub_zero_q
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
\<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * S ic p k t)  = \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)
\<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  = \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))
\<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q - 1. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
s d = b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = b * (\<Sum>S+ p d (\<lambda>k. s k))
           + b*(\<Sum>S- p d (\<lambda>k. \<Sum>t=0..q. b^t * (Z ic p (modifies (p!k)) t * S ic p k t)))
           + b*(\<Sum>S0 p d (\<lambda>k. \<Sum>t=0..q. b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
using SKe_def s_def
[PROOF STATE]
proof (prove)
using this:
SKe ?c ?p ?b ?q ?k = (\<Sum>t = 0..?q. ?b ^ t * S ?c ?p ?k t)
s \<equiv> SKe ic p b q

goal (1 subgoal):
 1. b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b * \<Sum>S+ p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * S ic p k t)  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
have "s d = b * (\<Sum>S+ p d s)
           + b*(\<Sum>S- p d (\<lambda>k. \<Sum>t=0..q. b^t * (Z ic p (modifies (p!k)) t * S ic p k t)))
           + b*(\<Sum>S0 p d (\<lambda>k. \<Sum>t=0..q. b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
have "... = b * (\<Sum>S+ p d s)
           + b*(\<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p!k)) && SKe ic p b q k))
           + b*(\<Sum>S0 p d (\<lambda>k. \<Sum>t=0..q. b^t * ((1 - Z ic p (modifies (p!k)) t) * S ic p k t)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
using mult_to_bitAND c_gt_cells b_def c
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>cells_bounded ?ic ?p ?c; 1 < ?c; ?b = B ?c\<rbrakk> \<Longrightarrow> (\<Sum>t = 0..?q. ?b ^ t * (Z ?ic ?p ?l t * S ?ic ?p ?k t)) = ZLe ?ic ?p ?b ?q ?l && SKe ?ic ?p ?b ?q ?k
cells_bounded ic p c
b \<equiv> B c
1 < c

goal (1 subgoal):
 1. b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * (Z ic p (modifies (p ! k)) t * S ic p k t))  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))  = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
[PROOF STEP]
have "s d = b * (\<Sum>S+ p d s)
           + b*(\<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p!k)) && SKe ic p b q k))
           + b*(\<Sum>S0 p d (\<lambda>k. (e - ZLe ic p b q (modifies (p!k))) && SKe ic p b q k))"
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. e - ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)
[PROOF STEP]
using mult_to_bitAND_state c_gt_cells b_def c e_def
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. \<Sum>t = 0..q. b ^ t * ((1 - Z ic p (modifies (p ! k)) t) * S ic p k t))
\<lbrakk>cells_bounded ?ic ?p ?c; 1 < ?c; ?b = B ?c\<rbrakk> \<Longrightarrow> (\<Sum>t = 0..?q. ?b ^ t * ((1 - Z ?ic ?p ?l t) * S ?ic ?p ?k t)) = sum ((^) ?b) {0..?q} - ZLe ?ic ?p ?b ?q ?l && SKe ?ic ?p ?b ?q ?k
cells_bounded ic p c
b \<equiv> B c
1 < c
e \<equiv> sum ((^) b) {0..q}

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. e - ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. e - ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. e - ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
using s_def z_def
[PROOF STATE]
proof (prove)
using this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)  + b * \<Sum>S0 p d (\<lambda>k. e - ZLe ic p b q (modifies (p ! k)) && SKe ic p b q k)
s \<equiv> SKe ic p b q
z \<equiv> ZLe ic p b q

goal (1 subgoal):
 1. s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
s d = b * \<Sum>S+ p d s  + b * \<Sum>S- p d (\<lambda>k. z (modifies (p ! k)) && s k)  + b * \<Sum>S0 p d (\<lambda>k. e - z (modifies (p ! k)) && s k)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma norm_exp_eq_Re [simp]: "norm (exp z) = exp (Re z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. cmod (exp z) = exp (Re z)
[PROOF STEP]
by (simp add: cis.code cmod_complex_polar exp_eq_polar Complex_eq)


[STATEMENT]
lemma logic_aux2: "(\<exists>k. (k = j \<longrightarrow> x = f i j) \<and> (k \<noteq> j \<longrightarrow> x = 0)) \<longleftrightarrow> (\<exists>k. k = j \<and> x = f i j) \<or> (\<exists>k. k \<noteq> j \<and> x = 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<exists>k. (k = j \<longrightarrow> x = f i j) \<and> (k \<noteq> j \<longrightarrow> x = (0::'b))) = ((\<exists>k. k = j \<and> x = f i j) \<or> (\<exists>k. k \<noteq> j \<and> x = (0::'b)))
[PROOF STEP]
by blast


[STATEMENT]
lemma [code abstract]:
  "integer_of_natural (m * n) = integer_of_natural m * integer_of_natural n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integer_of_natural (m * n) = integer_of_natural m * integer_of_natural n
[PROOF STEP]
by transfer simp


[STATEMENT]
lemma cong_1 [simp, presburger]:
  "[b = c] (mod 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [b = c] (mod 1::'a)
[PROOF STEP]
by (simp add: cong_def)