[STATEMENT]
theorem hoare_partial_sound:
  "\<turnstile>\<^sub>p {P} S {Q} \<Longrightarrow> well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<turnstile>\<^sub>p {P} S {Q}; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
proof (induction rule: hoare_partial.induct)
[PROOF STATE]
proof (state)
goal (6 subgoals):
 1. \<And>P. \<lbrakk>is_quantum_predicate P; well_com SKIP\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} SKIP {P}
 2. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 3. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 4. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 5. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 6. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
case (1 P)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
well_com SKIP

goal (6 subgoals):
 1. \<And>P. \<lbrakk>is_quantum_predicate P; well_com SKIP\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} SKIP {P}
 2. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 3. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 4. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 5. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 6. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
is_quantum_predicate P
well_com SKIP
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
well_com SKIP

goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {P} SKIP {P}
[PROOF STEP]
unfolding hoare_partial_correct_def
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
well_com SKIP

goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (P * \<rho>) \<le> trace (P * denote SKIP \<rho>) + (trace \<rho> - trace (denote SKIP \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {P} SKIP {P}

goal (5 subgoals):
 1. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 2. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 3. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 4. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 5. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (5 subgoals):
 1. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 2. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 3. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 4. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 5. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
case (2 P U)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
well_com (Utrans U)

goal (5 subgoals):
 1. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 2. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 3. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 4. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 5. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
(*utrans*)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
well_com (Utrans U)

goal (5 subgoals):
 1. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 2. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 3. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 4. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 5. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
is_quantum_predicate P
well_com (Utrans U)
[PROOF STEP]
have dU: "U \<in> carrier_mat d d" and "unitary U" and dP: "P \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
well_com (Utrans U)

goal (1 subgoal):
 1. U \<in> carrier_mat d d &&& unitary U &&& P \<in> carrier_mat d d
[PROOF STEP]
using is_quantum_predicate_def
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
well_com (Utrans U)
is_quantum_predicate ?P = (?P \<in> carrier_mat d d \<and> positive ?P \<and> ?P \<le>\<^sub>L 1\<^sub>m d)

goal (1 subgoal):
 1. U \<in> carrier_mat d d &&& unitary U &&& P \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
U \<in> carrier_mat d d
unitary U
P \<in> carrier_mat d d

goal (5 subgoals):
 1. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 2. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 3. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 4. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 5. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
U \<in> carrier_mat d d
unitary U
P \<in> carrier_mat d d
[PROOF STEP]
have uU: "adjoint U * U = 1\<^sub>m d"
[PROOF STATE]
proof (prove)
using this:
U \<in> carrier_mat d d
unitary U
P \<in> carrier_mat d d

goal (1 subgoal):
 1. adjoint U * U = 1\<^sub>m d
[PROOF STEP]
using unitary_def
[PROOF STATE]
proof (prove)
using this:
U \<in> carrier_mat d d
unitary U
P \<in> carrier_mat d d
unitary ?A = (?A \<in> carrier_mat (dim_row ?A) (dim_row ?A) \<and> inverts_mat ?A (adjoint ?A))

goal (1 subgoal):
 1. adjoint U * U = 1\<^sub>m d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
adjoint U * U = 1\<^sub>m d

goal (5 subgoals):
 1. \<And>P U. \<lbrakk>is_quantum_predicate P; well_com (Utrans U)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
 2. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 3. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 4. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 5. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}
[PROOF STEP]
unfolding hoare_partial_correct_def denote.simps(2)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
fix \<rho>
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
assume "\<rho> \<in> density_states"
[PROOF STATE]
proof (state)
this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<rho> \<in> density_states
[PROOF STEP]
have dr: "\<rho> \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d
[PROOF STEP]
using density_states_def
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states
density_states = {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
have e1: "trace (U * \<rho> * adjoint U) = trace ((adjoint U * U) * \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (U * \<rho> * adjoint U) = trace (adjoint U * U * \<rho>)
[PROOF STEP]
using dr dU
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> carrier_mat d d
U \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (U * \<rho> * adjoint U) = trace (adjoint U * U * \<rho>)
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace (U * \<rho> * adjoint U) = trace (adjoint U * U * \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (U * \<rho> * adjoint U) = trace (adjoint U * U * \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
have "\<dots> = trace \<rho>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint U * U * \<rho>) = trace \<rho>
[PROOF STEP]
using uU dr
[PROOF STATE]
proof (prove)
using this:
adjoint U * U = 1\<^sub>m d
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (adjoint U * U * \<rho>) = trace \<rho>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (adjoint U * U * \<rho>) = trace \<rho>

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
trace (U * \<rho> * adjoint U) = trace \<rho>
[PROOF STEP]
have e1: "trace (U * \<rho> * adjoint U) = trace \<rho>"
[PROOF STATE]
proof (prove)
using this:
trace (U * \<rho> * adjoint U) = trace \<rho>

goal (1 subgoal):
 1. trace (U * \<rho> * adjoint U) = trace \<rho>
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
trace (U * \<rho> * adjoint U) = trace \<rho>

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
have e2: "trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
[PROOF STEP]
using dU dP dr
[PROOF STATE]
proof (prove)
using this:
U \<in> carrier_mat d d
P \<in> carrier_mat d d
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
with e1
[PROOF STATE]
proof (chain)
picking this:
trace (U * \<rho> * adjoint U) = trace \<rho>
trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
[PROOF STEP]
have "trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)"
[PROOF STATE]
proof (prove)
using this:
trace (U * \<rho> * adjoint U) = trace \<rho>
trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)

goal (1 subgoal):
 1. trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
[PROOF STEP]
using e1
[PROOF STATE]
proof (prove)
using this:
trace (U * \<rho> * adjoint U) = trace \<rho>
trace (P * (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
trace (U * \<rho> * adjoint U) = trace \<rho>

goal (1 subgoal):
 1. trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)
[PROOF STEP]
show "trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))"
[PROOF STATE]
proof (prove)
using this:
trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U)) = trace (adjoint U * P * U * \<rho>)

goal (1 subgoal):
 1. trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (adjoint U * P * U * \<rho>) \<le> trace (P * (U * \<rho> * adjoint U)) + (trace \<rho> - trace (U * \<rho> * adjoint U))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {adjoint U * P * U} Utrans U {P}

goal (4 subgoals):
 1. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 2. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 3. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 4. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (4 subgoals):
 1. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 2. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 3. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 4. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
case (3 P Q R S1 S2)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate R
\<turnstile>\<^sub>p {P} S1 {Q}
\<turnstile>\<^sub>p {Q} S2 {R}
well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}
well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}
well_com (S1;; S2)

goal (4 subgoals):
 1. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 2. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 3. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 4. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
(*seq*)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate R
\<turnstile>\<^sub>p {P} S1 {Q}
\<turnstile>\<^sub>p {Q} S2 {R}
well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}
well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}
well_com (S1;; S2)

goal (4 subgoals):
 1. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 2. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 3. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 4. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate R
\<turnstile>\<^sub>p {P} S1 {Q}
\<turnstile>\<^sub>p {Q} S2 {R}
well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}
well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}
well_com (S1;; S2)
[PROOF STEP]
have wc1: "\<Turnstile>\<^sub>p {P} S1 {Q}" and wc2: "\<Turnstile>\<^sub>p {Q} S2 {R}"
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate R
\<turnstile>\<^sub>p {P} S1 {Q}
\<turnstile>\<^sub>p {Q} S2 {R}
well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}
well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}
well_com (S1;; S2)

goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {P} S1 {Q} &&& \<Turnstile>\<^sub>p {Q} S2 {R}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {P} S1 {Q}
\<Turnstile>\<^sub>p {Q} S2 {R}

goal (4 subgoals):
 1. \<And>P Q R S1 S2. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate R; \<turnstile>\<^sub>p {P} S1 {Q}; well_com S1 \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1 {Q}; \<turnstile>\<^sub>p {Q} S2 {R}; well_com S2 \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S2 {R}; well_com (S1;; S2)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S1;; S2 {R}
 2. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 3. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 4. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {P} S1;; S2 {R}
[PROOF STEP]
unfolding hoare_partial_correct_def denote.simps(3)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
proof clarify
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
fix \<rho>
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
assume \<rho>: "\<rho> \<in> density_states"
[PROOF STATE]
proof (state)
this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
have 1: "trace (P * \<rho>) \<le> trace (Q * denote S1 \<rho>) + (trace \<rho> - trace (denote S1 \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (Q * denote S1 \<rho>) + (trace \<rho> - trace (denote S1 \<rho>))
[PROOF STEP]
using wc1 hoare_partial_correct_def \<rho>
[PROOF STATE]
proof (prove)
using this:
\<Turnstile>\<^sub>p {P} S1 {Q}
(\<Turnstile>\<^sub>p {?P} ?S {?Q}) = (\<forall>\<rho>\<in>density_states. trace (?P * \<rho>) \<le> trace (?Q * denote ?S \<rho>) + (trace \<rho> - trace (denote ?S \<rho>)))
\<rho> \<in> density_states

goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (Q * denote S1 \<rho>) + (trace \<rho> - trace (denote S1 \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (P * \<rho>) \<le> trace (Q * denote S1 \<rho>) + (trace \<rho> - trace (denote S1 \<rho>))

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
have \<rho>': "denote S1 \<rho> \<in> density_states"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. denote S1 \<rho> \<in> density_states
[PROOF STEP]
using 3(8) denote_density_states \<rho>
[PROOF STATE]
proof (prove)
using this:
well_com (S1;; S2)
\<lbrakk>?\<rho> \<in> density_states; well_com ?S\<rbrakk> \<Longrightarrow> denote ?S ?\<rho> \<in> density_states
\<rho> \<in> density_states

goal (1 subgoal):
 1. denote S1 \<rho> \<in> density_states
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
denote S1 \<rho> \<in> density_states

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
have 2: "trace (Q * denote S1 \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace (denote S1 \<rho>) - trace (denote S2 (denote S1 \<rho>)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * denote S1 \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace (denote S1 \<rho>) - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
using wc2 hoare_partial_correct_def \<rho>'
[PROOF STATE]
proof (prove)
using this:
\<Turnstile>\<^sub>p {Q} S2 {R}
(\<Turnstile>\<^sub>p {?P} ?S {?Q}) = (\<forall>\<rho>\<in>density_states. trace (?P * \<rho>) \<le> trace (?Q * denote ?S \<rho>) + (trace \<rho> - trace (denote ?S \<rho>)))
denote S1 \<rho> \<in> density_states

goal (1 subgoal):
 1. trace (Q * denote S1 \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace (denote S1 \<rho>) - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (Q * denote S1 \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace (denote S1 \<rho>) - trace (denote S2 (denote S1 \<rho>)))

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
show "trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
using 1 2
[PROOF STATE]
proof (prove)
using this:
trace (P * \<rho>) \<le> trace (Q * denote S1 \<rho>) + (trace \<rho> - trace (denote S1 \<rho>))
trace (Q * denote S1 \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace (denote S1 \<rho>) - trace (denote S2 (denote S1 \<rho>)))

goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (P * \<rho>) \<le> trace (R * denote S2 (denote S1 \<rho>)) + (trace \<rho> - trace (denote S2 (denote S1 \<rho>)))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {P} S1;; S2 {R}

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
case (4 n P Q S M)
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> is_quantum_predicate (P ?k)
is_quantum_predicate Q
?k < n \<Longrightarrow> \<turnstile>\<^sub>p {P ?k} S ! ?k {Q}
\<lbrakk>?k < n; well_com (S ! ?k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
well_com (Measure n M S)

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
(*if*)
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> is_quantum_predicate (P ?k)
is_quantum_predicate Q
?k < n \<Longrightarrow> \<turnstile>\<^sub>p {P ?k} S ! ?k {Q}
\<lbrakk>?k < n; well_com (S ! ?k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
well_com (Measure n M S)

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?k < n \<Longrightarrow> is_quantum_predicate (P ?k)
is_quantum_predicate Q
?k < n \<Longrightarrow> \<turnstile>\<^sub>p {P ?k} S ! ?k {Q}
\<lbrakk>?k < n; well_com (S ! ?k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
well_com (Measure n M S)
[PROOF STEP]
have wc: "k < n \<Longrightarrow> well_com (S!k)"
    and c: "k < n \<Longrightarrow> \<Turnstile>\<^sub>p {P k} (S!k) {Q}" and m: "measurement d n M"
    and dMk: "k < n \<Longrightarrow> M k \<in> carrier_mat d d"
    and aMMkleq: "k < n \<Longrightarrow> adjoint (M k) * M k \<le>\<^sub>L 1\<^sub>m d"
    and dPk: "k < n \<Longrightarrow> P k \<in> carrier_mat d d"
    and dQ: "Q \<in> carrier_mat d d"
    for k
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> is_quantum_predicate (P ?k)
is_quantum_predicate Q
?k < n \<Longrightarrow> \<turnstile>\<^sub>p {P ?k} S ! ?k {Q}
\<lbrakk>?k < n; well_com (S ! ?k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
well_com (Measure n M S)

goal (1 subgoal):
 1. ((k < n \<Longrightarrow> well_com (S ! k)) &&& (k < n \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}) &&& measurement d n M) &&& ((k < n \<Longrightarrow> M k \<in> carrier_mat d d) &&& (k < n \<Longrightarrow> adjoint (M k) * M k \<le>\<^sub>L 1\<^sub>m d)) &&& (k < n \<Longrightarrow> P k \<in> carrier_mat d d) &&& Q \<in> carrier_mat d d
[PROOF STEP]
using is_quantum_predicate_def measurement_def measure_well_com measurement_le_one_mat
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> is_quantum_predicate (P ?k)
is_quantum_predicate Q
?k < n \<Longrightarrow> \<turnstile>\<^sub>p {P ?k} S ! ?k {Q}
\<lbrakk>?k < n; well_com (S ! ?k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
well_com (Measure n M S)
is_quantum_predicate ?P = (?P \<in> carrier_mat d d \<and> positive ?P \<and> ?P \<le>\<^sub>L 1\<^sub>m d)
measurement ?d ?n ?M = ((\<forall>j<?n. ?M j \<in> carrier_mat ?d ?d) \<and> matrix_sum ?d (\<lambda>j. adjoint (?M j) * ?M j) ?n = 1\<^sub>m ?d)
\<lbrakk>well_com (Measure ?n ?M ?S); ?k < ?n\<rbrakk> \<Longrightarrow> well_com (?S ! ?k)
\<lbrakk>measurement ?d ?n ?f; ?j < ?n\<rbrakk> \<Longrightarrow> adjoint (?f ?j) * ?f ?j \<le>\<^sub>L 1\<^sub>m ?d

goal (1 subgoal):
 1. ((k < n \<Longrightarrow> well_com (S ! k)) &&& (k < n \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}) &&& measurement d n M) &&& ((k < n \<Longrightarrow> M k \<in> carrier_mat d d) &&& (k < n \<Longrightarrow> adjoint (M k) * M k \<le>\<^sub>L 1\<^sub>m d)) &&& (k < n \<Longrightarrow> P k \<in> carrier_mat d d) &&& Q \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> well_com (S ! ?k)
?k < n \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
measurement d n M
?k < n \<Longrightarrow> M ?k \<in> carrier_mat d d
?k < n \<Longrightarrow> adjoint (M ?k) * M ?k \<le>\<^sub>L 1\<^sub>m d
?k < n \<Longrightarrow> P ?k \<in> carrier_mat d d
Q \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
{
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> well_com (S ! ?k)
?k < n \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}
measurement d n M
?k < n \<Longrightarrow> M ?k \<in> carrier_mat d d
?k < n \<Longrightarrow> adjoint (M ?k) * M ?k \<le>\<^sub>L 1\<^sub>m d
?k < n \<Longrightarrow> P ?k \<in> carrier_mat d d
Q \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
fix \<rho>
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
assume \<rho>: "\<rho> \<in> density_states"
[PROOF STATE]
proof (state)
this:
\<rho> \<in> density_states

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<rho> \<in> density_states
[PROOF STEP]
have dr: "\<rho> \<in> carrier_mat d d" and pdor: "partial_density_operator \<rho>"
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d &&& partial_density_operator \<rho>
[PROOF STEP]
using density_states_def
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states
density_states = {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d &&& partial_density_operator \<rho>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<rho> \<in> carrier_mat d d
partial_density_operator \<rho>

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have dsr: "k < n \<Longrightarrow> (M k) * \<rho> * adjoint (M k) \<in> density_states" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k < n \<Longrightarrow> M k * \<rho> * adjoint (M k) \<in> density_states
[PROOF STEP]
unfolding density_states_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k < n \<Longrightarrow> M k * \<rho> * adjoint (M k) \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}
[PROOF STEP]
using dMk pdo_close_under_measurement[OF dMk dr pdor aMMkleq] dr
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k \<in> carrier_mat d d
\<lbrakk>?k1 < n; ?k1 < n\<rbrakk> \<Longrightarrow> partial_density_operator (M ?k1 * \<rho> * adjoint (M ?k1))
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> M k * \<rho> * adjoint (M k) \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> density_states

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> density_states
[PROOF STEP]
have leqk: "k < n \<Longrightarrow> trace ((P k) * ((M k) * \<rho> * adjoint (M k))) \<le>
        trace (Q * (denote (S!k) ((M k) * \<rho> * adjoint (M k)))) +
        (trace ((M k) * \<rho> * adjoint (M k)) - trace (denote (S ! k) ((M k) * \<rho> * adjoint (M k))))" for k
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> density_states

goal (1 subgoal):
 1. k < n \<Longrightarrow> trace (P k * (M k * \<rho> * adjoint (M k))) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
using c
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> density_states
?k < n \<Longrightarrow> \<Turnstile>\<^sub>p {P ?k} S ! ?k {Q}

goal (1 subgoal):
 1. k < n \<Longrightarrow> trace (P k * (M k * \<rho> * adjoint (M k))) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
unfolding hoare_partial_correct_def
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> density_states
?k < n \<Longrightarrow> \<forall>\<rho>\<in>density_states. trace (P ?k * \<rho>) \<le> trace (Q * denote (S ! ?k) \<rho>) + (trace \<rho> - trace (denote (S ! ?k) \<rho>))

goal (1 subgoal):
 1. k < n \<Longrightarrow> trace (P k * (M k * \<rho> * adjoint (M k))) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> trace (P ?k * (M ?k * \<rho> * adjoint (M ?k))) \<le> trace (Q * denote (S ! ?k) (M ?k * \<rho> * adjoint (M ?k))) + (trace (M ?k * \<rho> * adjoint (M ?k)) - trace (denote (S ! ?k) (M ?k * \<rho> * adjoint (M ?k))))

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "k < n \<Longrightarrow> M k * \<rho> * adjoint (M k) \<in> carrier_mat d d" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k < n \<Longrightarrow> M k * \<rho> * adjoint (M k) \<in> carrier_mat d d
[PROOF STEP]
using dMk dr
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k \<in> carrier_mat d d
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> M k * \<rho> * adjoint (M k) \<in> carrier_mat d d
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> carrier_mat d d
[PROOF STEP]
have dsMrk: "k < n \<Longrightarrow> matrix_sum d (\<lambda>k. (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d" for k
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k \<in> carrier_mat d d
[PROOF STEP]
using matrix_sum_dim[of k "\<lambda>k. (M k * \<rho> * adjoint (M k))" d]
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> carrier_mat d d
(\<And>ka. ka < k \<Longrightarrow> M ka * \<rho> * adjoint (M ka) \<in> carrier_mat d d) \<Longrightarrow> matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k \<in> carrier_mat d d
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) ?k \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "k < n \<Longrightarrow> adjoint (M k) * P k * M k \<in> carrier_mat d d" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k < n \<Longrightarrow> adjoint (M k) * P k * M k \<in> carrier_mat d d
[PROOF STEP]
using dMk dPk
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> M ?k \<in> carrier_mat d d
?k < n \<Longrightarrow> P ?k \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> adjoint (M k) * P k * M k \<in> carrier_mat d d
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> adjoint (M ?k) * P ?k * M ?k \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?k < n \<Longrightarrow> adjoint (M ?k) * P ?k * M ?k \<in> carrier_mat d d
[PROOF STEP]
have dsMP: "k < n \<Longrightarrow> matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k \<in> carrier_mat d d" for k
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> adjoint (M ?k) * P ?k * M ?k \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k \<in> carrier_mat d d
[PROOF STEP]
using matrix_sum_dim[of k "\<lambda>k. adjoint (M k) * P k * M k" d]
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> adjoint (M ?k) * P ?k * M ?k \<in> carrier_mat d d
(\<And>ka. ka < k \<Longrightarrow> adjoint (M ka) * P ka * M ka \<in> carrier_mat d d) \<Longrightarrow> matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k \<in> carrier_mat d d
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) ?k \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have dSMrk: "k < n \<Longrightarrow> denote (S ! k) (M k * \<rho> * adjoint (M k)) \<in> carrier_mat d d" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k < n \<Longrightarrow> denote (S ! k) (M k * \<rho> * adjoint (M k)) \<in> carrier_mat d d
[PROOF STEP]
using denote_dim[OF wc, of k "M k * \<rho> * adjoint (M k)"] dsr density_states_def
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>k < n; M k * \<rho> * adjoint (M k) \<in> carrier_mat d d; partial_density_operator (M k * \<rho> * adjoint (M k))\<rbrakk> \<Longrightarrow> denote (S ! k) (M k * \<rho> * adjoint (M k)) \<in> carrier_mat d d
?k < n \<Longrightarrow> M ?k * \<rho> * adjoint (M ?k) \<in> density_states
density_states = {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. k < n \<Longrightarrow> denote (S ! k) (M k * \<rho> * adjoint (M k)) \<in> carrier_mat d d
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> denote (S ! ?k) (M ?k * \<rho> * adjoint (M ?k)) \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have dsSMrk: "k < n \<Longrightarrow> matrix_sum d (\<lambda>k. denote (S!k) (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k < n \<Longrightarrow> matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d
[PROOF STEP]
using matrix_sum_dim[of k "\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))" d, OF dSMrk]
[PROOF STATE]
proof (prove)
using this:
(\<And>ka. ka < k \<Longrightarrow> ka < n) \<Longrightarrow> matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d

goal (1 subgoal):
 1. k < n \<Longrightarrow> matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) ?k \<in> carrier_mat d d

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "k \<le> n \<Longrightarrow>
          trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>)
         \<le> trace (Q * (denote (Measure k M S) \<rho>)) + (trace (matrix_sum d (\<lambda>k. (M k) * \<rho> * adjoint (M k)) k) - trace (denote (Measure k M S) \<rho>))" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (Measure k M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (denote (Measure k M S) \<rho>))
[PROOF STEP]
unfolding denote_measure_expand[OF _ 4(5)]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
[PROOF STEP]
proof (induct k)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. 0 \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) 0 * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) 0) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0))
 2. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:
0 \<le> n

goal (2 subgoals):
 1. 0 \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) 0 * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) 0) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0))
 2. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 \<le> n
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
0 \<le> n

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) 0 * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) 0) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0))
[PROOF STEP]
using dQ dr pdor partial_density_operator_def positive_trace
[PROOF STATE]
proof (prove)
using this:
0 \<le> n
Q \<in> carrier_mat d d
\<rho> \<in> carrier_mat d d
partial_density_operator \<rho>
partial_density_operator ?A = (positive ?A \<and> trace ?A \<le> 1)
\<lbrakk>?A \<in> carrier_mat ?n ?n; positive ?A\<rbrakk> \<Longrightarrow> 0 \<le> trace ?A

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) 0 * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) 0) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) 0 * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) 0) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) 0))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
case (Suc k)
[PROOF STATE]
proof (state)
this:
k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
Suc k \<le> n

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
Suc k \<le> n
[PROOF STEP]
have k: "k < n"
[PROOF STATE]
proof (prove)
using this:
k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
Suc k \<le> n

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

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
have eq1: "trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>)
          = trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) = trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>)
[PROOF STEP]
unfolding matrix_sum.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace ((adjoint (M k) * P k * M k + matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k) * \<rho>) = trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>)
[PROOF STEP]
using dMk[OF k] dPk[OF k] dr dsMP[OF k]
[PROOF STATE]
proof (prove)
using this:
M k \<in> carrier_mat d d
P k \<in> carrier_mat d d
\<rho> \<in> carrier_mat d d
matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k \<in> carrier_mat d d

goal (1 subgoal):
 1. trace ((adjoint (M k) * P k * M k + matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k) * \<rho>) = trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>)
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) = trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>)

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
have "trace (adjoint (M k) * P k * M k * \<rho>) = trace (P k * (M k * \<rho> * adjoint (M k)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) = trace (P k * (M k * \<rho> * adjoint (M k)))
[PROOF STEP]
using dMk[OF k] dPk[OF k] dr
[PROOF STATE]
proof (prove)
using this:
M k \<in> carrier_mat d d
P k \<in> carrier_mat d d
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) = trace (P k * (M k * \<rho> * adjoint (M k)))
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace (adjoint (M k) * P k * M k * \<rho>) = trace (P k * (M k * \<rho> * adjoint (M k)))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (adjoint (M k) * P k * M k * \<rho>) = trace (P k * (M k * \<rho> * adjoint (M k)))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
have "\<dots> \<le> trace (Q * (denote (S!k) ((M k) * \<rho> * adjoint (M k)))) +
          (trace ((M k) * \<rho> * adjoint (M k)) - trace (denote (S ! k) ((M k) * \<rho> * adjoint (M k))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P k * (M k * \<rho> * adjoint (M k))) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
using leqk k
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> trace (P ?k * (M ?k * \<rho> * adjoint (M ?k))) \<le> trace (Q * denote (S ! ?k) (M ?k * \<rho> * adjoint (M ?k))) + (trace (M ?k * \<rho> * adjoint (M ?k)) - trace (denote (S ! ?k) (M ?k * \<rho> * adjoint (M ?k))))
k < n

goal (1 subgoal):
 1. trace (P k * (M k * \<rho> * adjoint (M k))) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (P k * (M k * \<rho> * adjoint (M k))) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
trace (adjoint (M k) * P k * M k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
have eq2: "trace (adjoint (M k) * P k * M k * \<rho>) \<le> trace (Q * (denote (S!k) ((M k) * \<rho> * adjoint (M k)))) +
          (trace ((M k) * \<rho> * adjoint (M k)) - trace (denote (S ! k) ((M k) * \<rho> * adjoint (M k))))"
[PROOF STATE]
proof (prove)
using this:
trace (adjoint (M k) * P k * M k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))

goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
trace (adjoint (M k) * P k * M k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + (trace (M k * \<rho> * adjoint (M k)) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k))))

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
have eq3: "trace (Q * matrix_sum d (\<lambda>k. denote (S!k) (M k * \<rho> * adjoint (M k))) (Suc k))
          = trace (Q * (denote (S!k) (M k * \<rho> * adjoint (M k)))) + trace (Q * matrix_sum d (\<lambda>k. denote (S!k) (M k * \<rho> * adjoint (M k))) k)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) = trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)
[PROOF STEP]
unfolding matrix_sum.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)) = trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)
[PROOF STEP]
using dQ dSMrk[OF k] dsSMrk[OF k]
[PROOF STATE]
proof (prove)
using this:
Q \<in> carrier_mat d d
denote (S ! k) (M k * \<rho> * adjoint (M k)) \<in> carrier_mat d d
matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (Q * (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)) = trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) = trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
have eq4: "trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S!k) (M k * \<rho> * adjoint (M k))) k)
          = trace (denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (matrix_sum d (\<lambda>k. denote (S!k) (M k * \<rho> * adjoint (M k))) k)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) = trace (denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)
[PROOF STEP]
using dSMrk[OF k] dsSMrk[OF k]
[PROOF STATE]
proof (prove)
using this:
denote (S ! k) (M k * \<rho> * adjoint (M k)) \<in> carrier_mat d d
matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) = trace (denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) = trace (denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)

goal (1 subgoal):
 1. \<And>k. \<lbrakk>k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)); Suc k \<le> n\<rbrakk> \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
apply (subst eq1)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
apply (subst eq3)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))
[PROOF STEP]
apply (simp del: less_eq_complex_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (M k * \<rho> * adjoint (M k) + matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
[PROOF STEP]
apply (subst trace_add_linear[of "M k * \<rho> * adjoint (M k)" d "matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k"])
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. M k * \<rho> * adjoint (M k) \<in> carrier_mat d d
 2. matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k \<in> carrier_mat d d
 3. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (M k * \<rho> * adjoint (M k)) + trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
[PROOF STEP]
apply (simp add: dMk adjoint_dim[OF dMk] dr mult_carrier_mat[of _ d d _ d] k)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k \<in> carrier_mat d d
 2. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (M k * \<rho> * adjoint (M k)) + trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
[PROOF STEP]
apply (simp add: dsMrk k)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (M k * \<rho> * adjoint (M k)) + trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - trace (denote (S ! k) (M k * \<rho> * adjoint (M k)) + matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k))
[PROOF STEP]
apply (subst eq4)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (adjoint (M k) * P k * M k * \<rho>) + trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) k * \<rho>) \<le> trace (Q * denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k) + (trace (M k * \<rho> * adjoint (M k)) + trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) k) - (trace (denote (S ! k) (M k * \<rho> * adjoint (M k))) + trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) k)))
[PROOF STEP]
apply (insert eq2 Suc(1) k, fastforce simp: less_eq_complex_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) (Suc k) * \<rho>) \<le> trace (Q * matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) (Suc k)) - trace (matrix_sum d (\<lambda>k. denote (S ! k) (M k * \<rho> * adjoint (M k))) (Suc k)))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) ?k * \<rho>) \<le> trace (Q * denote (Measure ?k M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) ?k) - trace (denote (Measure ?k M S) \<rho>))

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) ?k * \<rho>) \<le> trace (Q * denote (Measure ?k M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) ?k) - trace (denote (Measure ?k M S) \<rho>))
[PROOF STEP]
have leq: "trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>)
         \<le> trace (Q * denote (Measure n M S) \<rho>) +
            (trace (matrix_sum d (\<lambda>k. (M k) * \<rho> * adjoint (M k)) n) - trace (denote (Measure n M S) \<rho>))"
[PROOF STATE]
proof (prove)
using this:
?k \<le> n \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) ?k * \<rho>) \<le> trace (Q * denote (Measure ?k M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) ?k) - trace (denote (Measure ?k M S) \<rho>))

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) - trace (denote (Measure n M S) \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) - trace (denote (Measure n M S) \<rho>))

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "trace (matrix_sum d (\<lambda>k. (M k) * \<rho> * adjoint (M k)) n) = trace \<rho>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) = trace \<rho>
[PROOF STEP]
using trace_measurement m dr
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>measurement ?d ?n ?M; ?A \<in> carrier_mat ?d ?d\<rbrakk> \<Longrightarrow> trace (matrix_sum ?d (\<lambda>k. ?M k * ?A * adjoint (?M k)) ?n) = trace ?A
measurement d n M
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) = trace \<rho>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) = trace \<rho>

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
with leq
[PROOF STATE]
proof (chain)
picking this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) - trace (denote (Measure n M S) \<rho>))
trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) = trace \<rho>
[PROOF STEP]
have "trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>)
         \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace \<rho> - trace (denote (Measure n M S) \<rho>))"
[PROOF STATE]
proof (prove)
using this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) - trace (denote (Measure n M S) \<rho>))
trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) = trace \<rho>

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace \<rho> - trace (denote (Measure n M S) \<rho>))
[PROOF STEP]
unfolding denote_measure_def
[PROOF STATE]
proof (prove)
using this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) - trace (denote (Measure n M S) \<rho>))
trace (matrix_sum d (\<lambda>k. M k * \<rho> * adjoint (M k)) n) = trace \<rho>

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace \<rho> - trace (denote (Measure n M S) \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace \<rho> - trace (denote (Measure n M S) \<rho>))

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
}
[PROOF STATE]
proof (state)
this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * ?\<rho>2) \<le> trace (Q * denote (Measure n M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (Measure n M S) ?\<rho>2))

goal (3 subgoals):
 1. \<And>n P Q S M. \<lbrakk>\<And>k. k < n \<Longrightarrow> is_quantum_predicate (P k); is_quantum_predicate Q; \<And>k. k < n \<Longrightarrow> \<turnstile>\<^sub>p {P k} S ! k {Q}; \<And>k. \<lbrakk>k < n; well_com (S ! k)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P k} S ! k {Q}; well_com (Measure n M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
 2. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 3. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * ?\<rho>2) \<le> trace (Q * denote (Measure n M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (Measure n M S) ?\<rho>2))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * ?\<rho>2) \<le> trace (Q * denote (Measure n M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (Measure n M S) ?\<rho>2))

goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}
[PROOF STEP]
unfolding hoare_partial_correct_def
[PROOF STATE]
proof (prove)
using this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * ?\<rho>2) \<le> trace (Q * denote (Measure n M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (Measure n M S) ?\<rho>2))

goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n * \<rho>) \<le> trace (Q * denote (Measure n M S) \<rho>) + (trace \<rho> - trace (denote (Measure n M S) \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {matrix_sum d (\<lambda>k. adjoint (M k) * P k * M k) n} Measure n M S {Q}

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
case (5 P Q S M)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
is_quantum_predicate Q
\<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com (While M S)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
(*while*)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
is_quantum_predicate Q
\<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com (While M S)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
define M0 where "M0 = M 0"
[PROOF STATE]
proof (state)
this:
M0 = M 0

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
define M1 where "M1 = M 1"
[PROOF STATE]
proof (state)
this:
M1 = M 1

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
from 5
[PROOF STATE]
proof (chain)
picking this:
is_quantum_predicate P
is_quantum_predicate Q
\<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com (While M S)
[PROOF STEP]
have wcs: "well_com S" and c: "\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}"
    and m: "measurement d 2 M"
    and dM0: "M0 \<in> carrier_mat d d" and dM1: "M1 \<in> carrier_mat d d"
    and dP: "P \<in> carrier_mat d d" and dQ: "Q \<in> carrier_mat d d"
    and qpQ: "is_quantum_predicate Q"
    and wc: "well_com (While M S)"
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
is_quantum_predicate Q
\<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com (While M S)

goal (1 subgoal):
 1. ((well_com S &&& \<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}) &&& measurement d 2 M &&& M0 \<in> carrier_mat d d) &&& (M1 \<in> carrier_mat d d &&& P \<in> carrier_mat d d) &&& Q \<in> carrier_mat d d &&& is_quantum_predicate Q &&& well_com (While M S)
[PROOF STEP]
using measurement_def is_quantum_predicate_def M0_def M1_def
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
is_quantum_predicate Q
\<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}
well_com (While M S)
measurement ?d ?n ?M = ((\<forall>j<?n. ?M j \<in> carrier_mat ?d ?d) \<and> matrix_sum ?d (\<lambda>j. adjoint (?M j) * ?M j) ?n = 1\<^sub>m ?d)
is_quantum_predicate ?P = (?P \<in> carrier_mat d d \<and> positive ?P \<and> ?P \<le>\<^sub>L 1\<^sub>m d)
M0 = M 0
M1 = M 1

goal (1 subgoal):
 1. ((well_com S &&& \<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}) &&& measurement d 2 M &&& M0 \<in> carrier_mat d d) &&& (M1 \<in> carrier_mat d d &&& P \<in> carrier_mat d d) &&& Q \<in> carrier_mat d d &&& is_quantum_predicate Q &&& well_com (While M S)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
well_com S
\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}
measurement d 2 M
M0 \<in> carrier_mat d d
M1 \<in> carrier_mat d d
P \<in> carrier_mat d d
Q \<in> carrier_mat d d
is_quantum_predicate Q
well_com (While M S)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
well_com S
\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}
measurement d 2 M
M0 \<in> carrier_mat d d
M1 \<in> carrier_mat d d
P \<in> carrier_mat d d
Q \<in> carrier_mat d d
is_quantum_predicate Q
well_com (While M S)
[PROOF STEP]
have M0leq: "adjoint M0 * M0 \<le>\<^sub>L 1\<^sub>m d" and M1leq: "adjoint M1 * M1 \<le>\<^sub>L 1\<^sub>m d"
[PROOF STATE]
proof (prove)
using this:
well_com S
\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}
measurement d 2 M
M0 \<in> carrier_mat d d
M1 \<in> carrier_mat d d
P \<in> carrier_mat d d
Q \<in> carrier_mat d d
is_quantum_predicate Q
well_com (While M S)

goal (1 subgoal):
 1. adjoint M0 * M0 \<le>\<^sub>L 1\<^sub>m d &&& adjoint M1 * M1 \<le>\<^sub>L 1\<^sub>m d
[PROOF STEP]
using measurement_le_one_mat[OF m] M0_def M1_def
[PROOF STATE]
proof (prove)
using this:
well_com S
\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}
measurement d 2 M
M0 \<in> carrier_mat d d
M1 \<in> carrier_mat d d
P \<in> carrier_mat d d
Q \<in> carrier_mat d d
is_quantum_predicate Q
well_com (While M S)
?j < 2 \<Longrightarrow> adjoint (M ?j) * M ?j \<le>\<^sub>L 1\<^sub>m d
M0 = M 0
M1 = M 1

goal (1 subgoal):
 1. adjoint M0 * M0 \<le>\<^sub>L 1\<^sub>m d &&& adjoint M1 * M1 \<le>\<^sub>L 1\<^sub>m d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
adjoint M0 * M0 \<le>\<^sub>L 1\<^sub>m d
adjoint M1 * M1 \<le>\<^sub>L 1\<^sub>m d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
define DS where "DS = denote S"
[PROOF STATE]
proof (state)
this:
DS = denote S

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "\<forall>\<rho> \<in> density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS \<rho>) + trace \<rho> - trace (DS \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS \<rho>) + trace \<rho> - trace (DS \<rho>)
[PROOF STEP]
using hoare_partial_correct_def[of Q S "adjoint M0 * P * M0 + adjoint M1 * Q * M1"] c DS_def
[PROOF STATE]
proof (prove)
using this:
(\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}) = (\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>)))
\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}
DS = denote S

goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS \<rho>) + trace \<rho> - trace (DS \<rho>)
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS \<rho>) + trace \<rho> - trace (DS \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
define D0 where "D0 = denote_while_n M0 M1 DS"
[PROOF STATE]
proof (state)
this:
D0 = denote_while_n M0 M1 DS

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
define D1 where "D1 = denote_while_n_comp M0 M1 DS"
[PROOF STATE]
proof (state)
this:
D1 = denote_while_n_comp M0 M1 DS

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
define D where "D = denote_while_n_iter M0 M1 DS"
[PROOF STATE]
proof (state)
this:
D = denote_while_n_iter M0 M1 DS

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
{
[PROOF STATE]
proof (state)
this:
D = denote_while_n_iter M0 M1 DS

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
fix \<rho>
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
assume dsr: "\<rho> \<in> density_states"
[PROOF STATE]
proof (state)
this:
\<rho> \<in> density_states

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<rho> \<in> density_states
[PROOF STEP]
have dr: "\<rho> \<in> carrier_mat d d" and pr: "positive \<rho>" and pdor: "partial_density_operator \<rho>"
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d &&& positive \<rho> &&& partial_density_operator \<rho>
[PROOF STEP]
using density_states_def partial_density_operator_def
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states
density_states = {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}
partial_density_operator ?A = (positive ?A \<and> trace ?A \<le> 1)

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d &&& positive \<rho> &&& partial_density_operator \<rho>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<rho> \<in> carrier_mat d d
positive \<rho>
partial_density_operator \<rho>

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have pdoDkr: "\<And>k. partial_density_operator (D k \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. partial_density_operator (D k \<rho>)
[PROOF STEP]
unfolding D_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. partial_density_operator (denote_while_n_iter M0 M1 DS k \<rho>)
[PROOF STEP]
using pdo_denote_while_n_iter[OF dr pdor dM1 M1leq]
        denote_partial_density_operator[OF wcs] denote_dim[OF wcs, folded DS_def]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>\<And>\<rho>. \<rho> \<in> carrier_mat d d \<and> partial_density_operator \<rho> \<Longrightarrow> partial_density_operator (?DS \<rho>); \<And>\<rho>. \<rho> \<in> carrier_mat d d \<and> partial_density_operator \<rho> \<Longrightarrow> ?DS \<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (denote_while_n_iter ?M0.0 M1 ?DS ?n \<rho>)
\<lbrakk>partial_density_operator ?\<rho>; ?\<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (denote S ?\<rho>)
\<lbrakk>?\<rho> \<in> carrier_mat d d; partial_density_operator ?\<rho>\<rbrakk> \<Longrightarrow> DS ?\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. partial_density_operator (denote_while_n_iter M0 M1 DS k \<rho>)
[PROOF STEP]
apply (fold DS_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. \<lbrakk>\<And>DS M0 n. \<lbrakk>\<And>\<rho>. \<rho> \<in> carrier_mat d d \<and> partial_density_operator \<rho> \<Longrightarrow> partial_density_operator (DS \<rho>); \<And>\<rho>. \<rho> \<in> carrier_mat d d \<and> partial_density_operator \<rho> \<Longrightarrow> DS \<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (denote_while_n_iter M0 M1 DS n \<rho>); \<And>\<rho>. \<lbrakk>partial_density_operator \<rho>; \<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (DS \<rho>); \<And>\<rho>. \<lbrakk>\<rho> \<in> carrier_mat d d; partial_density_operator \<rho>\<rbrakk> \<Longrightarrow> DS \<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (denote_while_n_iter M0 M1 DS k \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
partial_density_operator (D ?k \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
partial_density_operator (D ?k \<rho>)
[PROOF STEP]
have pDkr: "\<And>k. positive (D k \<rho>)"
[PROOF STATE]
proof (prove)
using this:
partial_density_operator (D ?k \<rho>)

goal (1 subgoal):
 1. \<And>k. positive (D k \<rho>)
[PROOF STEP]
unfolding partial_density_operator_def
[PROOF STATE]
proof (prove)
using this:
positive (D ?k \<rho>) \<and> trace (D ?k \<rho>) \<le> 1

goal (1 subgoal):
 1. \<And>k. positive (D k \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
positive (D ?k \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have dDkr: "\<And>k. D k \<rho> \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. D k \<rho> \<in> carrier_mat d d
[PROOF STEP]
using denote_while_n_iter_dim[OF dr pdor dM1 M1leq denote_dim_pdo[OF wcs, folded DS_def], of id M0, simplified, folded D_def]
[PROOF STATE]
proof (prove)
using this:
D ?n \<rho> \<in> carrier_mat d d \<and> partial_density_operator (D ?n \<rho>)

goal (1 subgoal):
 1. \<And>k. D k \<rho> \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
D ?k \<rho> \<in> carrier_mat d d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
D ?k \<rho> \<in> carrier_mat d d
[PROOF STEP]
have dD0kr: "\<And>k. D0 k \<rho> \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
using this:
D ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. D0 k \<rho> \<in> carrier_mat d d
[PROOF STEP]
unfolding D0_def denote_while_n.simps
[PROOF STATE]
proof (prove)
using this:
D ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. M0 * denote_while_n_iter M0 M1 DS k \<rho> * adjoint M0 \<in> carrier_mat d d
[PROOF STEP]
apply (fold D_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. (\<And>k. D k \<rho> \<in> carrier_mat d d) \<Longrightarrow> M0 * D k \<rho> * adjoint M0 \<in> carrier_mat d d
[PROOF STEP]
using dM0
[PROOF STATE]
proof (prove)
using this:
M0 \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. (\<And>k. D k \<rho> \<in> carrier_mat d d) \<Longrightarrow> M0 * D k \<rho> * adjoint M0 \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
D0 ?k \<rho> \<in> carrier_mat d d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
D0 ?k \<rho> \<in> carrier_mat d d
[PROOF STEP]
have dPD0kr: "\<And>k. P * (D0 k \<rho>) \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
using this:
D0 ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. P * D0 k \<rho> \<in> carrier_mat d d
[PROOF STEP]
using dP
[PROOF STATE]
proof (prove)
using this:
D0 ?k \<rho> \<in> carrier_mat d d
P \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. P * D0 k \<rho> \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
P * D0 ?k \<rho> \<in> carrier_mat d d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "\<And>k. positive (D0 k \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. positive (D0 k \<rho>)
[PROOF STEP]
unfolding D0_def denote_while_n.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>k. positive (M0 * denote_while_n_iter M0 M1 DS k \<rho> * adjoint M0)
[PROOF STEP]
by (fold D_def, rule positive_close_under_left_right_mult_adjoint[OF dM0 dDkr pDkr])
[PROOF STATE]
proof (state)
this:
positive (D0 ?k \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
positive (D0 ?k \<rho>)
[PROOF STEP]
have trge0: "\<And>k. trace (D0 k \<rho>) \<ge> 0"
[PROOF STATE]
proof (prove)
using this:
positive (D0 ?k \<rho>)

goal (1 subgoal):
 1. \<And>k. 0 \<le> trace (D0 k \<rho>)
[PROOF STEP]
using positive_trace dD0kr
[PROOF STATE]
proof (prove)
using this:
positive (D0 ?k \<rho>)
\<lbrakk>?A \<in> carrier_mat ?n ?n; positive ?A\<rbrakk> \<Longrightarrow> 0 \<le> trace ?A
D0 ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>k. 0 \<le> trace (D0 k \<rho>)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
0 \<le> trace (D0 ?k \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have DSr: "\<rho> \<in> density_states \<Longrightarrow> DS \<rho> \<in> density_states" for "\<rho>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<rho> \<in> density_states \<Longrightarrow> DS \<rho> \<in> density_states
[PROOF STEP]
unfolding DS_def density_states_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<rho> \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>} \<Longrightarrow> denote S \<rho> \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}
[PROOF STEP]
using denote_partial_density_operator denote_dim wcs
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>well_com ?S; partial_density_operator ?\<rho>; ?\<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (denote ?S ?\<rho>)
\<lbrakk>well_com ?S; ?\<rho> \<in> carrier_mat d d; partial_density_operator ?\<rho>\<rbrakk> \<Longrightarrow> denote ?S ?\<rho> \<in> carrier_mat d d
well_com S

goal (1 subgoal):
 1. \<rho> \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>} \<Longrightarrow> denote S \<rho> \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?\<rho> \<in> density_states \<Longrightarrow> DS ?\<rho> \<in> density_states

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have dsD1nr: "D1 n \<rho> \<in> density_states" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D1 n \<rho> \<in> density_states
[PROOF STEP]
unfolding D1_def denote_while_n_comp.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M1 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M1 \<in> density_states
[PROOF STEP]
apply (fold D_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M1 * D n \<rho> * adjoint M1 \<in> density_states
[PROOF STEP]
unfolding density_states_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. M1 * D n \<rho> * adjoint M1 \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}
[PROOF STEP]
apply (auto)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. M1 * D n \<rho> * adjoint M1 \<in> carrier_mat d d
 2. partial_density_operator (M1 * D n \<rho> * adjoint M1)
[PROOF STEP]
apply (insert dDkr dM1 adjoint_dim[OF dM1], auto)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<And>k. D k \<rho> \<in> carrier_mat d d; M1 \<in> carrier_mat d d; adjoint M1 \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (M1 * D n \<rho> * adjoint M1)
[PROOF STEP]
apply (rule pdo_close_under_measurement[OF dM1 spec[OF allI[OF dDkr], of "\<lambda>x. n"] spec[OF allI[OF pdoDkr], of "\<lambda>x. n"] M1leq])
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
D1 ?n \<rho> \<in> density_states

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have leQn: "trace (Q * D1 n \<rho>)
          \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)
          + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
have "(\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
using c hoare_partial_correct_def
[PROOF STATE]
proof (prove)
using this:
\<Turnstile>\<^sub>p {Q} S {adjoint M0 * P * M0 + adjoint M1 * Q * M1}
(\<Turnstile>\<^sub>p {?P} ?S {?Q}) = (\<forall>\<rho>\<in>density_states. trace (?P * \<rho>) \<le> trace (?Q * denote ?S \<rho>) + (trace \<rho> - trace (denote ?S \<rho>)))

goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
have leQn': "trace (Q * (D1 n \<rho>))
          \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * (DS (D1 n \<rho>)))
          + (trace (D1 n \<rho>) - trace (DS (D1 n \<rho>)))"
[PROOF STATE]
proof (prove)
using this:
\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) + (trace (D1 n \<rho>) - trace (DS (D1 n \<rho>)))
[PROOF STEP]
using dsD1nr[of n] DS_def
[PROOF STATE]
proof (prove)
using this:
\<forall>\<rho>\<in>density_states. trace (Q * \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
D1 n \<rho> \<in> density_states
DS = denote S

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) + (trace (D1 n \<rho>) - trace (DS (D1 n \<rho>)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (Q * D1 n \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) + (trace (D1 n \<rho>) - trace (DS (D1 n \<rho>)))

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
have "(DS (D1 n \<rho>)) \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. DS (D1 n \<rho>) \<in> carrier_mat d d
[PROOF STEP]
unfolding DS_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. denote S (D1 n \<rho>) \<in> carrier_mat d d
[PROOF STEP]
using denote_dim[OF wcs] dsD1nr density_states_def
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?\<rho> \<in> carrier_mat d d; partial_density_operator ?\<rho>\<rbrakk> \<Longrightarrow> denote S ?\<rho> \<in> carrier_mat d d
D1 ?n \<rho> \<in> density_states
density_states = {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. denote S (D1 n \<rho>) \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
DS (D1 n \<rho>) \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
DS (D1 n \<rho>) \<in> carrier_mat d d
[PROOF STEP]
have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * (DS (D1 n \<rho>)))
        = trace (P * (M0 * (DS (D1 n \<rho>)) * adjoint M0))
        + trace (Q * (M1 * (DS (D1 n \<rho>)) * adjoint M1))"
[PROOF STATE]
proof (prove)
using this:
DS (D1 n \<rho>) \<in> carrier_mat d d

goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) + trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1))
[PROOF STEP]
using dP dQ dM0 dM1
[PROOF STATE]
proof (prove)
using this:
DS (D1 n \<rho>) \<in> carrier_mat d d
P \<in> carrier_mat d d
Q \<in> carrier_mat d d
M0 \<in> carrier_mat d d
M1 \<in> carrier_mat d d

goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) + trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1))
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) + trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1))

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) + trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1))

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
have "trace (P * (M0 * (DS (D1 n \<rho>)) * adjoint M0)) = trace (P * D0 (Suc n) \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * D0 (Suc n) \<rho>)
[PROOF STEP]
unfolding D0_def denote_while_n.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * (M0 * denote_while_n_iter M0 M1 DS (Suc n) \<rho> * adjoint M0))
[PROOF STEP]
apply (subst denote_while_n_iter_assoc)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * (M0 * DS (M1 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M1) * adjoint M0))
[PROOF STEP]
by (fold denote_while_n_comp.simps D1_def, auto)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * D0 (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * D0 (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
have "trace (Q * (M1 * (DS (D1 n \<rho>)) * adjoint M1)) = trace (Q * D1 (Suc n) \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * D1 (Suc n) \<rho>)
[PROOF STEP]
apply (subst (2) D1_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * denote_while_n_comp M0 M1 DS (Suc n) \<rho>)
[PROOF STEP]
unfolding denote_while_n_comp.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * (M1 * denote_while_n_iter M0 M1 DS (Suc n) \<rho> * adjoint M1))
[PROOF STEP]
apply (subst denote_while_n_iter_assoc)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * (M1 * DS (M1 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M1) * adjoint M1))
[PROOF STEP]
by (fold denote_while_n_comp.simps D1_def, auto)
[PROOF STATE]
proof (state)
this:
trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * D1 (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) + trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1))
trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * D0 (Suc n) \<rho>)
trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * D1 (Suc n) \<rho>)
[PROOF STEP]
have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * (DS (D1 n \<rho>)))
        = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)"
[PROOF STATE]
proof (prove)
using this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) + trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1))
trace (P * (M0 * DS (D1 n \<rho>) * adjoint M0)) = trace (P * D0 (Suc n) \<rho>)
trace (Q * (M1 * DS (D1 n \<rho>) * adjoint M1)) = trace (Q * D1 (Suc n) \<rho>)

goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
have "trace (DS (D1 n \<rho>)) = trace (D (Suc n) \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (DS (D1 n \<rho>)) = trace (D (Suc n) \<rho>)
[PROOF STEP]
unfolding D_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (DS (D1 n \<rho>)) = trace (denote_while_n_iter M0 M1 DS (Suc n) \<rho>)
[PROOF STEP]
apply (subst denote_while_n_iter_assoc)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (DS (D1 n \<rho>)) = trace (DS (M1 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M1))
[PROOF STEP]
by (fold denote_while_n_comp.simps D1_def, auto)
[PROOF STATE]
proof (state)
this:
trace (DS (D1 n \<rho>)) = trace (D (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)
trace (DS (D1 n \<rho>)) = trace (D (Suc n) \<rho>)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)
trace (DS (D1 n \<rho>)) = trace (D (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
using leQn'
[PROOF STATE]
proof (prove)
using this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) = trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>)
trace (DS (D1 n \<rho>)) = trace (D (Suc n) \<rho>)
trace (Q * D1 n \<rho>) \<le> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * DS (D1 n \<rho>)) + (trace (D1 n \<rho>) - trace (DS (D1 n \<rho>)))

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (Q * D1 n \<rho>) \<le> trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
trace (Q * D1 ?n \<rho>) \<le> trace (P * D0 (Suc ?n) \<rho>) + trace (Q * D1 (Suc ?n) \<rho>) + trace (D1 ?n \<rho>) - trace (D (Suc ?n) \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have 12: "trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
    \<le> (\<Sum>k=0..<(n+2). trace (P * (D0 k \<rho>))) + trace (Q * (D1 (n+1) \<rho>))
      + (\<Sum>k=0..<(n+1). trace (D1 k \<rho>) - trace (D (k+1) \<rho>))" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
proof (induct n)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<0 + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (0 + 1) \<rho>) + (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
 2. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:

goal (2 subgoals):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<0 + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (0 + 1) \<rho>) + (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
 2. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<0 + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (0 + 1) \<rho>) + (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
apply (simp del: less_eq_complex_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * D0 0 \<rho>) + trace (P * D0 (Suc 0) \<rho>) + trace (Q * D1 (Suc 0) \<rho>) + (trace (D1 0 \<rho>) - trace (D (Suc 0) \<rho>))
[PROOF STEP]
unfolding D0_def D1_def D_def  denote_while_n_comp.simps denote_while_n.simps denote_while_n_iter.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * (M0 * \<rho> * adjoint M0)) + trace (P * (M0 * DS (M1 * \<rho> * adjoint M1) * adjoint M0)) + trace (Q * (M1 * DS (M1 * \<rho> * adjoint M1) * adjoint M1)) + (trace (M1 * \<rho> * adjoint M1) - trace (DS (M1 * \<rho> * adjoint M1)))
[PROOF STEP]
using leQn[of 0]
[PROOF STATE]
proof (prove)
using this:
trace (Q * D1 0 \<rho>) \<le> trace (P * D0 (Suc 0) \<rho>) + trace (Q * D1 (Suc 0) \<rho>) + trace (D1 0 \<rho>) - trace (D (Suc 0) \<rho>)

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * (M0 * \<rho> * adjoint M0)) + trace (P * (M0 * DS (M1 * \<rho> * adjoint M1) * adjoint M0)) + trace (Q * (M1 * DS (M1 * \<rho> * adjoint M1) * adjoint M1)) + (trace (M1 * \<rho> * adjoint M1) - trace (DS (M1 * \<rho> * adjoint M1)))
[PROOF STEP]
unfolding D1_def D0_def D_def denote_while_n.simps denote_while_n_comp.simps denote_while_n_iter.simps
[PROOF STATE]
proof (prove)
using this:
trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * (M0 * DS (M1 * \<rho> * adjoint M1) * adjoint M0)) + trace (Q * (M1 * DS (M1 * \<rho> * adjoint M1) * adjoint M1)) + trace (M1 * \<rho> * adjoint M1) - trace (DS (M1 * \<rho> * adjoint M1))

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * (M0 * \<rho> * adjoint M0)) + trace (P * (M0 * DS (M1 * \<rho> * adjoint M1) * adjoint M0)) + trace (Q * (M1 * DS (M1 * \<rho> * adjoint M1) * adjoint M1)) + (trace (M1 * \<rho> * adjoint M1) - trace (DS (M1 * \<rho> * adjoint M1)))
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<0 + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (0 + 1) \<rho>) + (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
case (Suc n)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
have "trace (Q * D1 (n + 1) \<rho>)
          \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>)
          + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * D1 (n + 1) \<rho>) \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)
[PROOF STEP]
using leQn[of "n + 1"]
[PROOF STATE]
proof (prove)
using this:
trace (Q * D1 (n + 1) \<rho>) \<le> trace (P * D0 (Suc (n + 1)) \<rho>) + trace (Q * D1 (Suc (n + 1)) \<rho>) + trace (D1 (n + 1) \<rho>) - trace (D (Suc (n + 1)) \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 (n + 1) \<rho>) \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (Q * D1 (n + 1) \<rho>) \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
with Suc
[PROOF STATE]
proof (chain)
picking this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
trace (Q * D1 (n + 1) \<rho>) \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
trace (Q * D1 (n + 1) \<rho>) \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))
[PROOF STEP]
apply (simp del: less_eq_complex_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n. trace (P * D0 k \<rho>)) + trace (P * D0 n \<rho>) + trace (P * D0 (Suc n) \<rho>) + trace (Q * D1 (Suc n) \<rho>) + ((\<Sum>k = 0..<n. trace (D1 k \<rho>) - trace (D (Suc k) \<rho>)) + (trace (D1 n \<rho>) - trace (D (Suc n) \<rho>))); trace (Q * D1 (Suc n) \<rho>) \<le> trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)\<rbrakk> \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n. trace (P * D0 k \<rho>)) + trace (P * D0 n \<rho>) + trace (P * D0 (Suc n) \<rho>) + trace (P * D0 (Suc (Suc n)) \<rho>) + trace (Q * D1 (Suc (Suc n)) \<rho>) + ((\<Sum>k = 0..<n. trace (D1 k \<rho>) - trace (D (Suc k) \<rho>)) + (trace (D1 n \<rho>) - trace (D (Suc n) \<rho>)) + (trace (D1 (Suc n) \<rho>) - trace (D (Suc (Suc n)) \<rho>)))
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<Suc n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (Suc n + 1) \<rho>) + (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<?n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (?n + 1) \<rho>) + (\<Sum>k = 0..<?n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have tr_measurement: "\<rho> \<in> carrier_mat d d
      \<Longrightarrow> trace (M0 * \<rho> * adjoint M0) + trace (M1 * \<rho> * adjoint M1) = trace \<rho>" for \<rho>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d \<Longrightarrow> trace (M0 * \<rho> * adjoint M0) + trace (M1 * \<rho> * adjoint M1) = trace \<rho>
[PROOF STEP]
using trace_measurement2[OF m, folded M0_def M1_def]
[PROOF STATE]
proof (prove)
using this:
?A \<in> carrier_mat d d \<Longrightarrow> trace (M0 * ?A * adjoint M0) + trace (M1 * ?A * adjoint M1) = trace ?A

goal (1 subgoal):
 1. \<rho> \<in> carrier_mat d d \<Longrightarrow> trace (M0 * \<rho> * adjoint M0) + trace (M1 * \<rho> * adjoint M1) = trace \<rho>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?\<rho> \<in> carrier_mat d d \<Longrightarrow> trace (M0 * ?\<rho> * adjoint M0) + trace (M1 * ?\<rho> * adjoint M1) = trace ?\<rho>

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have 14: "(\<Sum>k=0..<(n+1). trace (D1 k \<rho>) - trace (D (k+1) \<rho>)) = trace \<rho> - trace (D (n+1) \<rho>) - (\<Sum>k=0..<(n+1). trace (D0 k \<rho>))" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))
[PROOF STEP]
proof (induct n)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (0 + 1) \<rho>) - (\<Sum>k = 0..<0 + 1. trace (D0 k \<rho>))
 2. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:

goal (2 subgoals):
 1. (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (0 + 1) \<rho>) - (\<Sum>k = 0..<0 + 1. trace (D0 k \<rho>))
 2. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (0 + 1) \<rho>) - (\<Sum>k = 0..<0 + 1. trace (D0 k \<rho>))
[PROOF STEP]
apply (simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (D1 0 \<rho>) = trace \<rho> - trace (D0 0 \<rho>)
[PROOF STEP]
unfolding D1_def D0_def denote_while_n_comp.simps denote_while_n.simps denote_while_n_iter.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (M1 * \<rho> * adjoint M1) = trace \<rho> - trace (M0 * \<rho> * adjoint M0)
[PROOF STEP]
using tr_measurement[OF dr]
[PROOF STATE]
proof (prove)
using this:
trace (M0 * \<rho> * adjoint M0) + trace (M1 * \<rho> * adjoint M1) = trace \<rho>

goal (1 subgoal):
 1. trace (M1 * \<rho> * adjoint M1) = trace \<rho> - trace (M0 * \<rho> * adjoint M0)
[PROOF STEP]
by (auto simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<0 + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (0 + 1) \<rho>) - (\<Sum>k = 0..<0 + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
case (Suc n)
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
have "trace (D0 (Suc n) \<rho>) + trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (D0 (Suc n) \<rho>) + trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>)
[PROOF STEP]
unfolding D0_def D1_def denote_while_n.simps denote_while_n_comp.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (M0 * denote_while_n_iter M0 M1 DS (Suc n) \<rho> * adjoint M0) + trace (M1 * denote_while_n_iter M0 M1 DS (Suc n) \<rho> * adjoint M1) = trace (D (Suc n) \<rho>)
[PROOF STEP]
apply (fold D_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (M0 * D (Suc n) \<rho> * adjoint M0) + trace (M1 * D (Suc n) \<rho> * adjoint M1) = trace (D (Suc n) \<rho>)
[PROOF STEP]
using tr_measurement dDkr
[PROOF STATE]
proof (prove)
using this:
?\<rho> \<in> carrier_mat d d \<Longrightarrow> trace (M0 * ?\<rho> * adjoint M0) + trace (M1 * ?\<rho> * adjoint M1) = trace ?\<rho>
D ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (M0 * D (Suc n) \<rho> * adjoint M0) + trace (M1 * D (Suc n) \<rho> * adjoint M1) = trace (D (Suc n) \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (D0 (Suc n) \<rho>) + trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>)

goal (1 subgoal):
 1. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
trace (D0 (Suc n) \<rho>) + trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>)
[PROOF STEP]
have "trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>) - trace (D0 (Suc n) \<rho>)"
[PROOF STATE]
proof (prove)
using this:
trace (D0 (Suc n) \<rho>) + trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>)

goal (1 subgoal):
 1. trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>) - trace (D0 (Suc n) \<rho>)
[PROOF STEP]
by (auto simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>) - trace (D0 (Suc n) \<rho>)

goal (1 subgoal):
 1. \<And>n. (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<Longrightarrow> (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>) - trace (D0 (Suc n) \<rho>)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>) - trace (D0 (Suc n) \<rho>)

goal (1 subgoal):
 1. (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
using Suc
[PROOF STATE]
proof (prove)
using this:
trace (D1 (Suc n) \<rho>) = trace (D (Suc n) \<rho>) - trace (D0 (Suc n) \<rho>)
(\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. (\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<Suc n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (Suc n + 1) \<rho>) - (\<Sum>k = 0..<Suc n + 1. trace (D0 k \<rho>))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<?n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) = trace \<rho> - trace (D (?n + 1) \<rho>) - (\<Sum>k = 0..<?n + 1. trace (D0 k \<rho>))

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have 15: "trace (Q * (D1 n \<rho>)) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
have QleId: "Q \<le>\<^sub>L 1\<^sub>m d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Q \<le>\<^sub>L 1\<^sub>m d
[PROOF STEP]
using is_quantum_predicate_def qpQ
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate ?P = (?P \<in> carrier_mat d d \<and> positive ?P \<and> ?P \<le>\<^sub>L 1\<^sub>m d)
is_quantum_predicate Q

goal (1 subgoal):
 1. Q \<le>\<^sub>L 1\<^sub>m d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Q \<le>\<^sub>L 1\<^sub>m d

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Q \<le>\<^sub>L 1\<^sub>m d
[PROOF STEP]
have "trace (Q * (D1 n \<rho>)) \<le> trace (1\<^sub>m d * (D1 n \<rho>))"
[PROOF STATE]
proof (prove)
using this:
Q \<le>\<^sub>L 1\<^sub>m d

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (1\<^sub>m d * D1 n \<rho>)
[PROOF STEP]
using
          dsD1nr[of n]
[PROOF STATE]
proof (prove)
using this:
Q \<le>\<^sub>L 1\<^sub>m d
D1 n \<rho> \<in> density_states

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (1\<^sub>m d * D1 n \<rho>)
[PROOF STEP]
unfolding density_states_def lowner_le_trace[OF dQ one_carrier_mat]
[PROOF STATE]
proof (prove)
using this:
\<forall>\<rho>\<in>carrier_mat d d. partial_density_operator \<rho> \<longrightarrow> trace (Q * \<rho>) \<le> trace (1\<^sub>m d * \<rho>)
D1 n \<rho> \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (1\<^sub>m d * D1 n \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (Q * D1 n \<rho>) \<le> trace (1\<^sub>m d * D1 n \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (Q * D1 n \<rho>) \<le> trace (1\<^sub>m d * D1 n \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
have "\<dots> = trace (D1 n \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (1\<^sub>m d * D1 n \<rho>) = trace (D1 n \<rho>)
[PROOF STEP]
using dsD1nr[of n]
[PROOF STATE]
proof (prove)
using this:
D1 n \<rho> \<in> density_states

goal (1 subgoal):
 1. trace (1\<^sub>m d * D1 n \<rho>) = trace (D1 n \<rho>)
[PROOF STEP]
unfolding density_states_def
[PROOF STATE]
proof (prove)
using this:
D1 n \<rho> \<in> {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. trace (1\<^sub>m d * D1 n \<rho>) = trace (D1 n \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (1\<^sub>m d * D1 n \<rho>) = trace (D1 n \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (1\<^sub>m d * D1 n \<rho>) = trace (D1 n \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
have "\<dots> = trace (M1 * (D n \<rho>) * adjoint M1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (D1 n \<rho>) = trace (M1 * D n \<rho> * adjoint M1)
[PROOF STEP]
unfolding D1_def denote_while_n_comp.simps D_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (M1 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M1) = trace (M1 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M1)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (D1 n \<rho>) = trace (M1 * D n \<rho> * adjoint M1)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (D1 n \<rho>) = trace (M1 * D n \<rho> * adjoint M1)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
have "\<dots> = trace (D n \<rho>) - trace (M0 * (D n \<rho>) * adjoint M0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (M1 * D n \<rho> * adjoint M1) = trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0)
[PROOF STEP]
using tr_measurement[OF dDkr[of n]]
[PROOF STATE]
proof (prove)
using this:
trace (M0 * D n \<rho> * adjoint M0) + trace (M1 * D n \<rho> * adjoint M1) = trace (D n \<rho>)

goal (1 subgoal):
 1. trace (M1 * D n \<rho> * adjoint M1) = trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0)
[PROOF STEP]
by (simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
trace (M1 * D n \<rho> * adjoint M1) = trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (M1 * D n \<rho> * adjoint M1) = trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
have "\<dots> = trace (D n \<rho>) - trace (D0 n \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0) = trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
unfolding D0_def denote_while_n.simps
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0) = trace (D n \<rho>) - trace (M0 * denote_while_n_iter M0 M1 DS n \<rho> * adjoint M0)
[PROOF STEP]
by (fold D_def, auto)
[PROOF STATE]
proof (state)
this:
trace (D n \<rho>) - trace (M0 * D n \<rho> * adjoint M0) = trace (D n \<rho>) - trace (D0 n \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)

goal (1 subgoal):
 1. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>) - trace (D0 n \<rho>)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
trace (Q * D1 ?n \<rho>) \<le> trace (D ?n \<rho>) - trace (D0 ?n \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have tmp: "\<And>a b c. 0 \<le> a \<Longrightarrow> b \<le> c - a \<Longrightarrow> b \<le> (c::complex)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a b c. \<lbrakk>0 \<le> a; b \<le> c - a\<rbrakk> \<Longrightarrow> b \<le> c
[PROOF STEP]
by (simp add: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
\<lbrakk>0 \<le> ?a; ?b \<le> ?c - ?a\<rbrakk> \<Longrightarrow> ?b \<le> ?c

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>0 \<le> ?a; ?b \<le> ?c - ?a\<rbrakk> \<Longrightarrow> ?b \<le> ?c
[PROOF STEP]
have 151: "\<And>n. trace (Q * (D1 n \<rho>)) \<le> trace (D n \<rho>)"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>0 \<le> ?a; ?b \<le> ?c - ?a\<rbrakk> \<Longrightarrow> ?b \<le> ?c

goal (1 subgoal):
 1. \<And>n. trace (Q * D1 n \<rho>) \<le> trace (D n \<rho>)
[PROOF STEP]
by (auto simp add: tmp[OF trge0 15] simp del: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (Q * D1 ?n \<rho>) \<le> trace (D ?n \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have main_leq: "\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
          \<le> trace (P * (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
fix n
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have "(\<Sum>k=0..<(n+2). trace (P * (D0 k \<rho>))) + trace (Q * (D1 (n+1) \<rho>))
            + (\<Sum>k=0..<(n+1). trace (D1 k \<rho>) - trace (D (k+1) \<rho>))
            \<le> (\<Sum>k=0..<(n+2). trace (P * (D0 k \<rho>))) + trace (Q * (D1 (n+1) \<rho>))
            + trace \<rho> - trace (D (n+1) \<rho>) - (\<Sum>k=0..<(n+1). trace (D0 k \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))
[PROOF STEP]
by (subst 14, auto)
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have
        "\<dots> \<le> (\<Sum>k=0..<(n+2). trace (P * (D0 k \<rho>))) + trace (D (n+1) \<rho>) - trace (D0 (n+1) \<rho>)
            + trace \<rho> - trace (D (n+1) \<rho>) - (\<Sum>k=0..<(n+1). trace (D0 k \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))
[PROOF STEP]
using 15[of "n+1"]
[PROOF STATE]
proof (prove)
using this:
trace (Q * D1 (n + 1) \<rho>) \<le> trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>)

goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have "\<dots> = (\<Sum>k=0..<(n+2). trace (P * (D0 k \<rho>))) + trace \<rho> - (\<Sum>k=0..<(n+2). trace (D0 k \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) = (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) = (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (D (n + 1) \<rho>) - trace (D0 (n + 1) \<rho>) + trace \<rho> - trace (D (n + 1) \<rho>) - (\<Sum>k = 0..<n + 1. trace (D0 k \<rho>)) = (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have "\<dots> = trace (matrix_sum d (\<lambda>k. (P * (D0 k \<rho>))) (n+2)) + trace \<rho> - (\<Sum>k=0..<(n+2). trace (D0 k \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))
[PROOF STEP]
using trace_matrix_sum_linear[of "n+2" "\<lambda>k. (P * (D0 k \<rho>))" d, symmetric] dPD0kr
[PROOF STATE]
proof (prove)
using this:
(\<And>k. k < n + 2 \<Longrightarrow> P * D0 k \<rho> \<in> carrier_mat d d) \<Longrightarrow> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2))
P * D0 ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have "\<dots> = trace (matrix_sum d (\<lambda>k. (P * (D0 k \<rho>))) (n+2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
using trace_matrix_sum_linear[of "n+2" "\<lambda>k. D0 k \<rho>" d, symmetric] dD0kr
[PROOF STATE]
proof (prove)
using this:
(\<And>k. k < n + 2 \<Longrightarrow> D0 k \<rho> \<in> carrier_mat d d) \<Longrightarrow> (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
D0 ?k \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - (\<Sum>k = 0..<n + 2. trace (D0 k \<rho>)) = trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have "\<dots> = trace (P * (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) = trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
using matrix_sum_distrib_left[OF dP dD0kr, of id "n+2"]
[PROOF STATE]
proof (prove)
using this:
matrix_sum d (\<lambda>k. P * D0 (id k) \<rho>) (n + 2) = P * matrix_sum d (\<lambda>k. D0 (id k) \<rho>) (n + 2)

goal (1 subgoal):
 1. trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) = trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (matrix_sum d (\<lambda>k. P * D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) = trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
have
        "(\<Sum>k=0..<(n+2). trace (P * (D0 k \<rho>))) + trace (Q * (D1 (n+1) \<rho>))
         + (\<Sum>k=0..<(n+1). trace (D1 k \<rho>) - trace (D (k+1) \<rho>))
        \<le> trace (P * (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))"
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal (1 subgoal):
 1. (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal (1 subgoal):
 1. \<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
show "trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
          \<le> trace (P * (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))"
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
using 12[of n]
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> (\<Sum>k = 0..<n + 2. trace (P * D0 k \<rho>)) + trace (Q * D1 (n + 1) \<rho>) + (\<Sum>k = 0..<n + 1. trace (D1 k \<rho>) - trace (D (k + 1) \<rho>))

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2))

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n)) (denote (While M S) \<rho>) d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d
[PROOF STEP]
using limit_mat_denote_while_n[OF wc dr pdor]
[PROOF STATE]
proof (prove)
using this:
limit_mat (matrix_sum d (\<lambda>k. denote_while_n (M 0) (M 1) (denote S) k \<rho>)) (denote (While M S) \<rho>) d

goal (1 subgoal):
 1. limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d
[PROOF STEP]
unfolding D0_def M0_def M1_def DS_def
[PROOF STATE]
proof (prove)
using this:
limit_mat (matrix_sum d (\<lambda>k. denote_while_n (M 0) (M 1) (denote S) k \<rho>)) (denote (While M S) \<rho>) d

goal (1 subgoal):
 1. limit_mat (matrix_sum d (\<lambda>k. denote_while_n (M 0) (M 1) (denote S) k \<rho>)) (denote (While M S) \<rho>) d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d
[PROOF STEP]
have limp2: "limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d"
[PROOF STATE]
proof (prove)
using this:
limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d

goal (1 subgoal):
 1. limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d
[PROOF STEP]
using limit_mat_ignore_initial_segment[of "\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n)" "(denote (While M S) \<rho>)" d 2]
[PROOF STATE]
proof (prove)
using this:
limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d
limit_mat (matrix_sum d (\<lambda>k. D0 k \<rho>)) (denote (While M S) \<rho>) d \<Longrightarrow> limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d

goal (1 subgoal):
 1. limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d
[PROOF STEP]
have "limit_mat (\<lambda>n. (P * (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2)))) (P * (denote (While M S) \<rho>)) d"
[PROOF STATE]
proof (prove)
using this:
limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d

goal (1 subgoal):
 1. limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d
[PROOF STEP]
using mat_mult_limit[OF dP]
[PROOF STATE]
proof (prove)
using this:
limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d
limit_mat ?X ?A d \<Longrightarrow> limit_mat (mat_mult_seq P ?X) (P * ?A) d

goal (1 subgoal):
 1. limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d
[PROOF STEP]
unfolding mat_mult_seq_def
[PROOF STATE]
proof (prove)
using this:
limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d
limit_mat ?X ?A d \<Longrightarrow> limit_mat (\<lambda>n. P * ?X n) (P * ?A) d

goal (1 subgoal):
 1. limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d
[PROOF STEP]
have limPm: "(\<lambda>n. trace (P * (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2)))) \<longlonglongrightarrow> trace (P * (denote (While M S) \<rho>))"
[PROOF STATE]
proof (prove)
using this:
limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d

goal (1 subgoal):
 1. (\<lambda>n. trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (P * denote (While M S) \<rho>)
[PROOF STEP]
using mat_trace_limit
[PROOF STATE]
proof (prove)
using this:
limit_mat (\<lambda>n. P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (P * denote (While M S) \<rho>) d
limit_mat ?g ?A ?d \<Longrightarrow> (\<lambda>n. trace (?g n)) \<longlonglongrightarrow> trace ?A

goal (1 subgoal):
 1. (\<lambda>n. trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (P * denote (While M S) \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (P * denote (While M S) \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have limm: "(\<lambda>n. trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n+2))) \<longlonglongrightarrow> trace (denote (While M S) \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (denote (While M S) \<rho>)
[PROOF STEP]
using mat_trace_limit limp2
[PROOF STATE]
proof (prove)
using this:
limit_mat ?g ?A ?d \<Longrightarrow> (\<lambda>n. trace (?g n)) \<longlonglongrightarrow> trace ?A
limit_mat (\<lambda>n. matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) (denote (While M S) \<rho>) d

goal (1 subgoal):
 1. (\<lambda>n. trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (denote (While M S) \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (denote (While M S) \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have leq_lim: "trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
      \<le> trace (P * (denote (While M S) \<rho>)) + trace \<rho> - trace (denote (While M S) \<rho>)" (is "?lhs \<le> ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
using main_leq
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2))

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
define seq where "seq n = trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) " for n
[PROOF STATE]
proof (state)
this:
seq ?n = trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2))

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
define seqlim where "seqlim = trace (P * (denote (While M S) \<rho>)) - trace (denote (While M S) \<rho>)"
[PROOF STATE]
proof (state)
this:
seqlim = trace (P * denote (While M S) \<rho>) - trace (denote (While M S) \<rho>)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have main_leq': "?lhs \<le> trace \<rho> + seq n" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seq n
[PROOF STEP]
unfolding seq_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + (trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)))
[PROOF STEP]
using main_leq
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (?n + 2))

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + (trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)))
[PROOF STEP]
by (simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seq ?n

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have limseq: "seq \<longlonglongrightarrow> seqlim"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. seq \<longlonglongrightarrow> seqlim
[PROOF STEP]
unfolding seq_def seqlim_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (P * denote (While M S) \<rho>) - trace (denote (While M S) \<rho>)
[PROOF STEP]
using tendsto_diff[OF limPm limm]
[PROOF STATE]
proof (prove)
using this:
(\<lambda>x. trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (x + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (x + 2))) \<longlonglongrightarrow> trace (P * denote (While M S) \<rho>) - trace (denote (While M S) \<rho>)

goal (1 subgoal):
 1. (\<lambda>n. trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<longlonglongrightarrow> trace (P * denote (While M S) \<rho>) - trace (denote (While M S) \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
seq \<longlonglongrightarrow> seqlim

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have limrs: "(\<lambda>n. trace \<rho> + seq n) \<longlonglongrightarrow> (trace \<rho> + seqlim)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. trace \<rho> + seq n) \<longlonglongrightarrow> trace \<rho> + seqlim
[PROOF STEP]
using tendsto_add[OF _ limseq]
[PROOF STATE]
proof (prove)
using this:
?f \<longlonglongrightarrow> ?a \<Longrightarrow> (\<lambda>x. ?f x + seq x) \<longlonglongrightarrow> ?a + seqlim

goal (1 subgoal):
 1. (\<lambda>n. trace \<rho> + seq n) \<longlonglongrightarrow> trace \<rho> + seqlim
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. trace \<rho> + seq n) \<longlonglongrightarrow> trace \<rho> + seqlim

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have limrsRe: "(\<lambda>n. Re (trace \<rho> + seq n)) \<longlonglongrightarrow> Re (trace \<rho> + seqlim)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. Re (trace \<rho> + seq n)) \<longlonglongrightarrow> Re (trace \<rho> + seqlim)
[PROOF STEP]
using tendsto_Re[OF limrs]
[PROOF STATE]
proof (prove)
using this:
(\<lambda>x. Re (trace \<rho> + seq x)) \<longlonglongrightarrow> Re (trace \<rho> + seqlim)

goal (1 subgoal):
 1. (\<lambda>n. Re (trace \<rho> + seq n)) \<longlonglongrightarrow> Re (trace \<rho> + seqlim)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. Re (trace \<rho> + seq n)) \<longlonglongrightarrow> Re (trace \<rho> + seqlim)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have main_leq_Re: "Re ?lhs \<le> Re (trace \<rho> + seq n)" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seq n)
[PROOF STEP]
using main_leq'
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seq ?n

goal (1 subgoal):
 1. Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seq n)
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seq ?n)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have Re: "Re ?lhs \<le> Re (trace \<rho> + seqlim)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seqlim)
[PROOF STEP]
using Lim_bounded2[OF limrsRe ]  main_leq_Re
[PROOF STATE]
proof (prove)
using this:
\<forall>n\<ge>?N. ?C \<le> Re (trace \<rho> + seq n) \<Longrightarrow> ?C \<le> Re (trace \<rho> + seqlim)
Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seq ?n)

goal (1 subgoal):
 1. Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seqlim)
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seqlim)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have limrsIm: "(\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace \<rho> + seqlim)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace \<rho> + seqlim)
[PROOF STEP]
using tendsto_Im[OF limrs]
[PROOF STATE]
proof (prove)
using this:
(\<lambda>x. Im (trace \<rho> + seq x)) \<longlonglongrightarrow> Im (trace \<rho> + seqlim)

goal (1 subgoal):
 1. (\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace \<rho> + seqlim)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace \<rho> + seqlim)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have main_leq_Im: "Im ?lhs = Im (trace \<rho> + seq n)" for n
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq n)
[PROOF STEP]
using main_leq'
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seq ?n

goal (1 subgoal):
 1. Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq n)
[PROOF STEP]
unfolding less_eq_complex_def
[PROOF STATE]
proof (prove)
using this:
Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seq ?n) \<and> Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq ?n)

goal (1 subgoal):
 1. Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq n)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq ?n)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq ?n)
[PROOF STEP]
have limIm: "(\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im ?lhs"
[PROOF STATE]
proof (prove)
using this:
Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq ?n)

goal (1 subgoal):
 1. (\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)))
[PROOF STEP]
using tendsto_intros(1)
[PROOF STATE]
proof (prove)
using this:
Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seq ?n)
((\<lambda>x. x) \<longlongrightarrow> ?a) (at ?a within ?s)

goal (1 subgoal):
 1. (\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<lambda>n. Im (trace \<rho> + seq n)) \<longlonglongrightarrow> Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)))

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have Im: "Im ?lhs = Im (trace \<rho> + seqlim)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seqlim)
[PROOF STEP]
using tendsto_unique[OF _ limIm limrsIm]
[PROOF STATE]
proof (prove)
using this:
sequentially \<noteq> bot \<Longrightarrow> Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seqlim)

goal (1 subgoal):
 1. Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seqlim)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seqlim)

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
have "?lhs \<le> trace \<rho> + seqlim"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seqlim
[PROOF STEP]
using Re Im
[PROOF STATE]
proof (prove)
using this:
Re (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) \<le> Re (trace \<rho> + seqlim)
Im (trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))) = Im (trace \<rho> + seqlim)

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seqlim
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seqlim

goal (1 subgoal):
 1. (\<And>n. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2)) + trace \<rho> - trace (matrix_sum d (\<lambda>k. D0 k \<rho>) (n + 2))) \<Longrightarrow> trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seqlim
[PROOF STEP]
show "?lhs \<le> ?rhs"
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + seqlim

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
unfolding seqlim_def
[PROOF STATE]
proof (prove)
using this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace \<rho> + (trace (P * denote (While M S) \<rho>) - trace (denote (While M S) \<rho>))

goal (1 subgoal):
 1. trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) =
      trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) = trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
[PROOF STEP]
using dr dM0 dM1 dP dQ
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> carrier_mat d d
M0 \<in> carrier_mat d d
M1 \<in> carrier_mat d d
P \<in> carrier_mat d d
Q \<in> carrier_mat d d

goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) = trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
[PROOF STEP]
by (mat_assoc d)
[PROOF STATE]
proof (state)
this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) = trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) = trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
[PROOF STEP]
have "trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) \<le>
      trace (P * (denote (While M S) \<rho>)) + (trace \<rho> - trace (denote (While M S) \<rho>))"
[PROOF STATE]
proof (prove)
using this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) = trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))

goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) \<le> trace (P * denote (While M S) \<rho>) + (trace \<rho> - trace (denote (While M S) \<rho>))
[PROOF STEP]
using leq_lim
[PROOF STATE]
proof (prove)
using this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) = trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1))
trace (P * (M0 * \<rho> * adjoint M0)) + trace (Q * (M1 * \<rho> * adjoint M1)) \<le> trace (P * denote (While M S) \<rho>) + trace \<rho> - trace (denote (While M S) \<rho>)

goal (1 subgoal):
 1. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) \<le> trace (P * denote (While M S) \<rho>) + (trace \<rho> - trace (denote (While M S) \<rho>))
[PROOF STEP]
by (auto simp: less_eq_complex_def)
[PROOF STATE]
proof (state)
this:
trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) \<le> trace (P * denote (While M S) \<rho>) + (trace \<rho> - trace (denote (While M S) \<rho>))

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
}
[PROOF STATE]
proof (state)
this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * ?\<rho>2) \<le> trace (P * denote (While M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (While M S) ?\<rho>2))

goal (2 subgoals):
 1. \<And>P Q S M. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; \<turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {Q} S {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1}; well_com (While M S)\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
 2. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * ?\<rho>2) \<le> trace (P * denote (While M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (While M S) ?\<rho>2))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * ?\<rho>2) \<le> trace (P * denote (While M S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote (While M S) ?\<rho>2))

goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}
[PROOF STEP]
unfolding hoare_partial_correct_def denote.simps(5)
[PROOF STATE]
proof (prove)
using this:
?\<rho>2 \<in> density_states \<Longrightarrow> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * ?\<rho>2) \<le> trace (P * denote_while (M 0) (M 1) (denote S) ?\<rho>2) + (trace ?\<rho>2 - trace (denote_while (M 0) (M 1) (denote S) ?\<rho>2))

goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace ((adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1) * \<rho>) \<le> trace (P * denote_while (M 0) (M 1) (denote S) \<rho>) + (trace \<rho> - trace (denote_while (M 0) (M 1) (denote S) \<rho>))
[PROOF STEP]
apply (fold M0_def M1_def DS_def D0_def D1_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) \<le> trace (P * denote_while M0 M1 DS \<rho>) + (trace \<rho> - trace (denote_while M0 M1 DS \<rho>))) \<Longrightarrow> \<forall>\<rho>\<in>density_states. trace ((adjoint M0 * P * M0 + adjoint M1 * Q * M1) * \<rho>) \<le> trace (P * denote_while M0 M1 DS \<rho>) + (trace \<rho> - trace (denote_while M0 M1 DS \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {adjoint (M 0) * P * M 0 + adjoint (M 1) * Q * M 1} While M S {P}

goal (1 subgoal):
 1. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
case (6 P Q P' Q' S)
[PROOF STATE]
proof (state)
this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate P'
is_quantum_predicate Q'
P \<le>\<^sub>L P'
\<turnstile>\<^sub>p {P'} S {Q'}
Q' \<le>\<^sub>L Q
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}
well_com S

goal (1 subgoal):
 1. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate P'
is_quantum_predicate Q'
P \<le>\<^sub>L P'
\<turnstile>\<^sub>p {P'} S {Q'}
Q' \<le>\<^sub>L Q
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}
well_com S
[PROOF STEP]
have wcs: "well_com S" and c: "\<Turnstile>\<^sub>p {P'} S {Q'}"
    and dP: "P \<in> carrier_mat d d" and dQ: "Q \<in> carrier_mat d d"
    and dP': "P' \<in> carrier_mat d d" and dQ': "Q' \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate P'
is_quantum_predicate Q'
P \<le>\<^sub>L P'
\<turnstile>\<^sub>p {P'} S {Q'}
Q' \<le>\<^sub>L Q
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}
well_com S

goal (1 subgoal):
 1. (well_com S &&& \<Turnstile>\<^sub>p {P'} S {Q'} &&& P \<in> carrier_mat d d) &&& Q \<in> carrier_mat d d &&& P' \<in> carrier_mat d d &&& Q' \<in> carrier_mat d d
[PROOF STEP]
using is_quantum_predicate_def
[PROOF STATE]
proof (prove)
using this:
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate P'
is_quantum_predicate Q'
P \<le>\<^sub>L P'
\<turnstile>\<^sub>p {P'} S {Q'}
Q' \<le>\<^sub>L Q
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}
well_com S
is_quantum_predicate ?P = (?P \<in> carrier_mat d d \<and> positive ?P \<and> ?P \<le>\<^sub>L 1\<^sub>m d)

goal (1 subgoal):
 1. (well_com S &&& \<Turnstile>\<^sub>p {P'} S {Q'} &&& P \<in> carrier_mat d d) &&& Q \<in> carrier_mat d d &&& P' \<in> carrier_mat d d &&& Q' \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
well_com S
\<Turnstile>\<^sub>p {P'} S {Q'}
P \<in> carrier_mat d d
Q \<in> carrier_mat d d
P' \<in> carrier_mat d d
Q' \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>P Q P' Q' S. \<lbrakk>is_quantum_predicate P; is_quantum_predicate Q; is_quantum_predicate P'; is_quantum_predicate Q'; P \<le>\<^sub>L P'; \<turnstile>\<^sub>p {P'} S {Q'}; well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}; Q' \<le>\<^sub>L Q; well_com S\<rbrakk> \<Longrightarrow> \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Turnstile>\<^sub>p {P} S {Q}
[PROOF STEP]
unfolding hoare_partial_correct_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>\<rho>\<in>density_states. trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
fix \<rho>
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
assume pds: "\<rho> \<in> density_states"
[PROOF STATE]
proof (state)
this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<rho> \<in> density_states
[PROOF STEP]
have pdor: "partial_density_operator \<rho>" and dr: "\<rho> \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states

goal (1 subgoal):
 1. partial_density_operator \<rho> &&& \<rho> \<in> carrier_mat d d
[PROOF STEP]
using density_states_def
[PROOF STATE]
proof (prove)
using this:
\<rho> \<in> density_states
density_states = {\<rho> \<in> carrier_mat d d. partial_density_operator \<rho>}

goal (1 subgoal):
 1. partial_density_operator \<rho> &&& \<rho> \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
partial_density_operator \<rho>
\<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
have pdoSr: "partial_density_operator (denote S \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. partial_density_operator (denote S \<rho>)
[PROOF STEP]
using denote_partial_density_operator pdor dr wcs
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>well_com ?S; partial_density_operator ?\<rho>; ?\<rho> \<in> carrier_mat d d\<rbrakk> \<Longrightarrow> partial_density_operator (denote ?S ?\<rho>)
partial_density_operator \<rho>
\<rho> \<in> carrier_mat d d
well_com S

goal (1 subgoal):
 1. partial_density_operator (denote S \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
partial_density_operator (denote S \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
have dSr: "denote S \<rho> \<in> carrier_mat d d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. denote S \<rho> \<in> carrier_mat d d
[PROOF STEP]
using denote_dim pdor dr wcs
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>well_com ?S; ?\<rho> \<in> carrier_mat d d; partial_density_operator ?\<rho>\<rbrakk> \<Longrightarrow> denote ?S ?\<rho> \<in> carrier_mat d d
partial_density_operator \<rho>
\<rho> \<in> carrier_mat d d
well_com S

goal (1 subgoal):
 1. denote S \<rho> \<in> carrier_mat d d
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
denote S \<rho> \<in> carrier_mat d d

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
have "trace (P * \<rho>) \<le> trace (P' * \<rho>)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (P' * \<rho>)
[PROOF STEP]
using lowner_le_trace[OF dP dP'] 6 dr pdor
[PROOF STATE]
proof (prove)
using this:
(P \<le>\<^sub>L P') = (\<forall>\<rho>\<in>carrier_mat d d. partial_density_operator \<rho> \<longrightarrow> trace (P * \<rho>) \<le> trace (P' * \<rho>))
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate P'
is_quantum_predicate Q'
P \<le>\<^sub>L P'
\<turnstile>\<^sub>p {P'} S {Q'}
Q' \<le>\<^sub>L Q
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}
well_com S
\<rho> \<in> carrier_mat d d
partial_density_operator \<rho>

goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (P' * \<rho>)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (P * \<rho>) \<le> trace (P' * \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (P * \<rho>) \<le> trace (P' * \<rho>)

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
have "\<dots> \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
using c
[PROOF STATE]
proof (prove)
using this:
\<Turnstile>\<^sub>p {P'} S {Q'}

goal (1 subgoal):
 1. trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
unfolding hoare_partial_correct_def
[PROOF STATE]
proof (prove)
using this:
\<forall>\<rho>\<in>density_states. trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
using pds
[PROOF STATE]
proof (prove)
using this:
\<forall>\<rho>\<in>density_states. trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
\<rho> \<in> density_states

goal (1 subgoal):
 1. trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
trace (P' * \<rho>) \<le> trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
have "\<dots> \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>)) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
using lowner_le_trace[OF dQ' dQ] 6 dSr pdoSr
[PROOF STATE]
proof (prove)
using this:
(Q' \<le>\<^sub>L Q) = (\<forall>\<rho>\<in>carrier_mat d d. partial_density_operator \<rho> \<longrightarrow> trace (Q' * \<rho>) \<le> trace (Q * \<rho>))
is_quantum_predicate P
is_quantum_predicate Q
is_quantum_predicate P'
is_quantum_predicate Q'
P \<le>\<^sub>L P'
\<turnstile>\<^sub>p {P'} S {Q'}
Q' \<le>\<^sub>L Q
well_com S \<Longrightarrow> \<Turnstile>\<^sub>p {P'} S {Q'}
well_com S
denote S \<rho> \<in> carrier_mat d d
partial_density_operator (denote S \<rho>)

goal (1 subgoal):
 1. trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>)) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
trace (Q' * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>)) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. \<And>\<rho>. \<rho> \<in> density_states \<Longrightarrow> trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
show "trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>)) "
[PROOF STATE]
proof (prove)
using this:
trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal (1 subgoal):
 1. trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
trace (P * \<rho>) \<le> trace (Q * denote S \<rho>) + (trace \<rho> - trace (denote S \<rho>))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<Turnstile>\<^sub>p {P} S {Q}

goal:
No subgoals!
[PROOF STEP]
qed