[STATEMENT]
lemma ntt_coeff_poly_mult:
assumes "l<n"
shows "ntt_coeff_poly (f*g) l = ntt_coeff_poly f l * ntt_coeff_poly g l"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
define f1 where "f1 = (\<lambda>x. \<lambda> y.
        conv_sign ((int x - int y) div int n) *
        poly.coeff (of_qr f) y *
        poly.coeff (of_qr g) (nat ((int x - int y) mod int n)))"
[PROOF STATE]
proof (state)
this:
f1 = (\<lambda>x y. conv_sign ((int x - int y) div int n) * poly.coeff (of_qr f) y * poly.coeff (of_qr g) (nat ((int x - int y) mod int n)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "ntt_coeff_poly (f*g) l = (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j *
        \<psi>^(j*(2*l+1)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
unfolding ntt_coeff_poly_def mult_negacycl
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ntt_coeff_poly (f * g) l = (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
ntt_coeff_poly (f * g) l = (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "\<dots> = (\<Sum>j=0..<n. (\<Sum>i<n. f1 j i * \<psi>^(j*(2*l+1))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
proof (subst sum.cong[of "{0..<n}" "{0..<n}"
      "(\<lambda>j. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi>^(j*(2*l+1)))"
      "(\<lambda>j. (\<Sum>i<n. f1 j i * \<psi>^(j*(2*l+1))))"],
      goal_cases)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. {0..<n} = {0..<n}
 2. \<And>x. x \<in> {0..<n} \<Longrightarrow> poly.coeff (of_qr (negacycl_conv f g)) x * \<psi> ^ (x * (2 * l + 1)) = (\<Sum>i<n. f1 x i * \<psi> ^ (x * (2 * l + 1)))
 3. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
case (2 j)
[PROOF STATE]
proof (state)
this:
j \<in> {0..<n}

goal (3 subgoals):
 1. {0..<n} = {0..<n}
 2. \<And>x. x \<in> {0..<n} \<Longrightarrow> poly.coeff (of_qr (negacycl_conv f g)) x * \<psi> ^ (x * (2 * l + 1)) = (\<Sum>i<n. f1 x i * \<psi> ^ (x * (2 * l + 1)))
 3. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
j \<in> {0..<n}
[PROOF STEP]
have "j<n"
[PROOF STATE]
proof (prove)
using this:
j \<in> {0..<n}

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

goal (3 subgoals):
 1. {0..<n} = {0..<n}
 2. \<And>x. x \<in> {0..<n} \<Longrightarrow> poly.coeff (of_qr (negacycl_conv f g)) x * \<psi> ^ (x * (2 * l + 1)) = (\<Sum>i<n. f1 x i * \<psi> ^ (x * (2 * l + 1)))
 3. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
have "poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) =
      (\<Sum>na<n. (conv_sign ((int j - int na) div int n) *
         poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n))) *
        \<psi> ^ (j * (2 * l + 1)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
apply (subst nth_coeffs_negacycl[OF \<open>j<n\<close>])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. conv_sign ((int j - int i) div int n) * poly.coeff (of_qr f) i * poly.coeff (of_qr g) (nat ((int j - int i) mod int n))) * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
apply (subst sum_distrib_right)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1)))

goal (3 subgoals):
 1. {0..<n} = {0..<n}
 2. \<And>x. x \<in> {0..<n} \<Longrightarrow> poly.coeff (of_qr (negacycl_conv f g)) x * \<psi> ^ (x * (2 * l + 1)) = (\<Sum>i<n. f1 x i * \<psi> ^ (x * (2 * l + 1)))
 3. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1)))

goal (3 subgoals):
 1. {0..<n} = {0..<n}
 2. \<And>x. x \<in> {0..<n} \<Longrightarrow> poly.coeff (of_qr (negacycl_conv f g)) x * \<psi> ^ (x * (2 * l + 1)) = (\<Sum>i<n. f1 x i * \<psi> ^ (x * (2 * l + 1)))
 3. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
have "\<dots> = (\<Sum>na<n. f1 j na * \<psi> ^ (j * (2 * l + 1)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>na<n. f1 j na * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
unfolding f1_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>na<n. conv_sign ((int j - int na) div int n) * poly.coeff (of_qr f) na * poly.coeff (of_qr g) (nat ((int j - int na) mod int n)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>na<n. f1 j na * \<psi> ^ (j * (2 * l + 1)))

goal (3 subgoals):
 1. {0..<n} = {0..<n}
 2. \<And>x. x \<in> {0..<n} \<Longrightarrow> poly.coeff (of_qr (negacycl_conv f g)) x * \<psi> ^ (x * (2 * l + 1)) = (\<Sum>i<n. f1 x i * \<psi> ^ (x * (2 * l + 1)))
 3. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>na<n. f1 j na * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>na<n. f1 j na * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1)) = (\<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))

goal (2 subgoals):
 1. {0..<n} = {0..<n}
 2. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
qed auto
[PROOF STATE]
proof (state)
this:
(\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>j = 0..<n. poly.coeff (of_qr (negacycl_conv f g)) j * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "\<dots> = (\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by (subst atLeast0LessThan, subst sum.swap, auto)
[PROOF STATE]
proof (state)
this:
(\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>j = 0..<n. \<Sum>i<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "\<dots> = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) *
    (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) *
        (if int j - int i < 0 then -1 else 1) *
         \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))
[PROOF STEP]
proof (subst sum.cong[of "{..<n}" "{..<n}" "(\<lambda>i. (\<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))))"
    "(\<lambda>i. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) *
        (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) *
        (if int j - int i < 0 then -1 else 1) *
         \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))"], goal_cases)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. {..<n} = {..<n}
 2. \<And>x. x \<in> {..<n} \<Longrightarrow> (\<Sum>j<n. f1 j x * \<psi> ^ (j * (2 * l + 1))) = poly.coeff (of_qr f) x * \<psi> ^ (x * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int x) mod int n)) * (if int j - int x < 0 then - 1 else 1) * \<psi>inv ^ (x * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))
 3. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))
[PROOF STEP]
case (2 i)
[PROOF STATE]
proof (state)
this:
i \<in> {..<n}

goal (3 subgoals):
 1. {..<n} = {..<n}
 2. \<And>x. x \<in> {..<n} \<Longrightarrow> (\<Sum>j<n. f1 j x * \<psi> ^ (j * (2 * l + 1))) = poly.coeff (of_qr f) x * \<psi> ^ (x * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int x) mod int n)) * (if int j - int x < 0 then - 1 else 1) * \<psi>inv ^ (x * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))
 3. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i \<in> {..<n}
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
i \<in> {..<n}

goal (1 subgoal):
 1. (\<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
proof (subst sum_distrib_left, subst sum.cong[of "{..<n}" "{..<n}"
      "(\<lambda>j. f1 j i * \<psi> ^ (j * (2 * l + 1)))"
      "(\<lambda>j. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) *
        (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) *
        (if int j - int i < 0 then - 1 else 1) *
        \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))"], goal_cases)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<And>x. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}; x \<in> {..<n}\<rbrakk> \<Longrightarrow> f1 x i * \<psi> ^ (x * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int x - int i) mod int n)) * (if int x - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (x * (2 * l + 1)))
 3. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
case (2 j)
[PROOF STATE]
proof (state)
this:
i \<in> {..<n}
i \<in> {..<n}
j \<in> {..<n}

goal (3 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<And>x. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}; x \<in> {..<n}\<rbrakk> \<Longrightarrow> f1 x i * \<psi> ^ (x * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int x - int i) mod int n)) * (if int x - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (x * (2 * l + 1)))
 3. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
i \<in> {..<n}
i \<in> {..<n}
j \<in> {..<n}
[PROOF STEP]
have *: "conv_sign ((int j - int i) div int n) =
        (if int j - int i < 0 then - 1 else 1)"
[PROOF STATE]
proof (prove)
using this:
i \<in> {..<n}
i \<in> {..<n}
j \<in> {..<n}

goal (1 subgoal):
 1. conv_sign ((int j - int i) div int n) = (if int j - int i < 0 then - 1 else 1)
[PROOF STEP]
using conv_sign_if
[PROOF STATE]
proof (prove)
using this:
i \<in> {..<n}
i \<in> {..<n}
j \<in> {..<n}
\<lbrakk>?x < n; ?y < n\<rbrakk> \<Longrightarrow> conv_sign ((int ?x - int ?y) div int n) = (if int ?x - int ?y < 0 then - 1 else 1)

goal (1 subgoal):
 1. conv_sign ((int j - int i) div int n) = (if int j - int i < 0 then - 1 else 1)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
conv_sign ((int j - int i) div int n) = (if int j - int i < 0 then - 1 else 1)

goal (3 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<And>x. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}; x \<in> {..<n}\<rbrakk> \<Longrightarrow> f1 x i * \<psi> ^ (x * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int x - int i) mod int n)) * (if int x - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (x * (2 * l + 1)))
 3. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
have "f1 j i * \<psi> ^ (j * (2 * l + 1)) =
        \<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f1 j i * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))
[PROOF STEP]
using psi_psiinv
[PROOF STATE]
proof (prove)
using this:
\<psi> * \<psi>inv = 1

goal (1 subgoal):
 1. f1 j i * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))
[PROOF STEP]
by (simp add: left_right_inverse_power)
[PROOF STATE]
proof (state)
this:
f1 j i * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))

goal (3 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<And>x. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}; x \<in> {..<n}\<rbrakk> \<Longrightarrow> f1 x i * \<psi> ^ (x * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int x - int i) mod int n)) * (if int x - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (x * (2 * l + 1)))
 3. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
f1 j i * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))

goal (3 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<And>x. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}; x \<in> {..<n}\<rbrakk> \<Longrightarrow> f1 x i * \<psi> ^ (x * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int x - int i) mod int n)) * (if int x - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (x * (2 * l + 1)))
 3. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
have "\<dots> = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) *
      (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) *
      (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
unfolding f1_def mult.assoc
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ (i * (2 * l + 1)) * (conv_sign ((int j - int i) div int n) * (poly.coeff (of_qr f) i * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (\<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))))) = poly.coeff (of_qr f) i * (\<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * ((if int j - int i < 0 then - 1 else 1) * (\<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))))
[PROOF STEP]
by (simp add: "*" mult.left_commute)
[PROOF STATE]
proof (state)
this:
\<psi> ^ (i * (2 * l + 1)) * f1 j i * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))

goal (3 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<And>x. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}; x \<in> {..<n}\<rbrakk> \<Longrightarrow> f1 x i * \<psi> ^ (x * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int x - int i) mod int n)) * (if int x - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (x * (2 * l + 1)))
 3. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
f1 j i * \<psi> ^ (j * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
f1 j i * \<psi> ^ (j * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))

goal (1 subgoal):
 1. f1 j i * \<psi> ^ (j * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
f1 j i * \<psi> ^ (j * (2 * l + 1)) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))

goal (2 subgoals):
 1. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> {..<n} = {..<n}
 2. \<lbrakk>i \<in> {..<n}; i \<in> {..<n}\<rbrakk> \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (poly.coeff (of_qr g) (nat ((int na - int i) mod int n)) * (if int na - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (na * (2 * l + 1))))
[PROOF STEP]
qed auto
[PROOF STATE]
proof (state)
this:
(\<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))

goal (2 subgoals):
 1. {..<n} = {..<n}
 2. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))
[PROOF STEP]
qed auto
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. \<Sum>j<n. f1 j i * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "\<dots> = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) *
    (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
define x' where "x' = (\<lambda>j i. nat ((int j - int i) mod int n))"
[PROOF STATE]
proof (state)
this:
x' = (\<lambda>j i. nat ((int j - int i) mod int n))

goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
let ?if_inv = "(\<lambda>i j. (if int j - int i < 0 then - 1 else 1) *
      \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
have rewrite: "(if int j - int i < 0 then - 1 else 1) *
      \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) =
      \<psi> ^ ((x' j i) * (2 * l + 1))"  if "i<n" "j<n" for i j
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
proof (cases "int j - int i <0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
int j - int i < 0

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have lt: "i * (2 * l + 1) < n * (2 * l + 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i * (2 * l + 1) < n * (2 * l + 1)
[PROOF STEP]
using \<open>i<n\<close>
[PROOF STATE]
proof (prove)
using this:
i < n

goal (1 subgoal):
 1. i * (2 * l + 1) < n * (2 * l + 1)
[PROOF STEP]
by (metis One_nat_def add_gr_0 lessI mult_less_mono1)
[PROOF STATE]
proof (state)
this:
i * (2 * l + 1) < n * (2 * l + 1)

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have "?if_inv i j = (-1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = - 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
int j - int i < 0

goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = - 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))
[PROOF STEP]
by (auto split: if_splits)
[PROOF STATE]
proof (state)
this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = - 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = - 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have "\<dots> = \<psi>^((n-i+j)* (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((n - i + j) * (2 * l + 1))
[PROOF STEP]
unfolding psi_props(2)[of l, symmetric]
         negative_psi[OF lt]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ (n * (2 * l + 1) - i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((n - i + j) * (2 * l + 1))
[PROOF STEP]
by (metis comm_semiring_class.distrib diff_mult_distrib power_add)
[PROOF STATE]
proof (state)
this:
- 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((n - i + j) * (2 * l + 1))

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
- 1 * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((n - i + j) * (2 * l + 1))

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have "\<dots> = \<psi> ^ ((x' j i) * (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ ((n - i + j) * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
unfolding x'_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ ((n - i + j) * (2 * l + 1)) = \<psi> ^ (nat ((int j - int i) mod int n) * (2 * l + 1))
[PROOF STEP]
by (smt (verit, best) True mod_add_self2 mod_pos_pos_trivial nat_int_add
        nat_less_le of_nat_0_le_iff of_nat_diff that(1))
[PROOF STATE]
proof (state)
this:
\<psi> ^ ((n - i + j) * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))

goal (2 subgoals):
 1. int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
 2. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))

goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> int j - int i < 0

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> int j - int i < 0
[PROOF STEP]
have "i\<le>j"
[PROOF STATE]
proof (prove)
using this:
\<not> int j - int i < 0

goal (1 subgoal):
 1. i \<le> j
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i \<le> j

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have lt: "i * (2 * l + 1) \<le> j * (2 * l + 1)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i * (2 * l + 1) \<le> j * (2 * l + 1)
[PROOF STEP]
using \<open>i\<le>j\<close>
[PROOF STATE]
proof (prove)
using this:
i \<le> j

goal (1 subgoal):
 1. i * (2 * l + 1) \<le> j * (2 * l + 1)
[PROOF STEP]
using add_gr_0 less_one mult_less_mono1
[PROOF STATE]
proof (prove)
using this:
i \<le> j
(0 < ?m + ?n) = (0 < ?m \<or> 0 < ?n)
(?n < 1) = (?n = 0)
\<lbrakk>?i < ?j; 0 < ?k\<rbrakk> \<Longrightarrow> ?i * ?k < ?j * ?k

goal (1 subgoal):
 1. i * (2 * l + 1) \<le> j * (2 * l + 1)
[PROOF STEP]
using mult_le_cancel2
[PROOF STATE]
proof (prove)
using this:
i \<le> j
(0 < ?m + ?n) = (0 < ?m \<or> 0 < ?n)
(?n < 1) = (?n = 0)
\<lbrakk>?i < ?j; 0 < ?k\<rbrakk> \<Longrightarrow> ?i * ?k < ?j * ?k
(?m * ?k \<le> ?n * ?k) = (0 < ?k \<longrightarrow> ?m \<le> ?n)

goal (1 subgoal):
 1. i * (2 * l + 1) \<le> j * (2 * l + 1)
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
i * (2 * l + 1) \<le> j * (2 * l + 1)

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have "?if_inv i j = \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))
[PROOF STEP]
using False
[PROOF STATE]
proof (prove)
using this:
\<not> int j - int i < 0

goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))
[PROOF STEP]
by (auto split: if_splits)
[PROOF STATE]
proof (state)
this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have "\<dots> = \<psi>^((j-i)* (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((j - i) * (2 * l + 1))
[PROOF STEP]
using negative_psi'[OF lt]  diff_mult_distrib
[PROOF STATE]
proof (prove)
using this:
\<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (j * (2 * l + 1) - i * (2 * l + 1))
(?m - ?n) * ?k = ?m * ?k - ?n * ?k

goal (1 subgoal):
 1. \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((j - i) * (2 * l + 1))
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
\<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((j - i) * (2 * l + 1))

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ ((j - i) * (2 * l + 1))

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
have "\<dots> = \<psi> ^ ((x' j i) * (2 * l + 1))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ ((j - i) * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
unfolding x'_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<psi> ^ ((j - i) * (2 * l + 1)) = \<psi> ^ (nat ((int j - int i) mod int n) * (2 * l + 1))
[PROOF STEP]
by (metis \<open>i \<le> j\<close> less_imp_diff_less mod_pos_pos_trivial nat_int
          of_nat_0_le_iff of_nat_diff of_nat_less_iff that(2))
[PROOF STATE]
proof (state)
this:
\<psi> ^ ((j - i) * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))

goal (1 subgoal):
 1. \<not> int j - int i < 0 \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))

goal (1 subgoal):
 1. (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
(if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?i < n; ?j < n\<rbrakk> \<Longrightarrow> (if int ?j - int ?i < 0 then - 1 else 1) * \<psi>inv ^ (?i * (2 * l + 1)) * \<psi> ^ (?j * (2 * l + 1)) = \<psi> ^ (x' ?j ?i * (2 * l + 1))

goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>?i < n; ?j < n\<rbrakk> \<Longrightarrow> (if int ?j - int ?i < 0 then - 1 else 1) * \<psi>inv ^ (?i * (2 * l + 1)) * \<psi> ^ (?j * (2 * l + 1)) = \<psi> ^ (x' ?j ?i * (2 * l + 1))
[PROOF STEP]
have "(\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) *
      (if int j - int i < 0 then - 1 else 1) *
      \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) =
      (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))"
      (is "(\<Sum>j<n. ?left j i) = _") if "i<n" for i
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?i < n; ?j < n\<rbrakk> \<Longrightarrow> (if int ?j - int ?i < 0 then - 1 else 1) * \<psi>inv ^ (?i * (2 * l + 1)) * \<psi> ^ (?j * (2 * l + 1)) = \<psi> ^ (x' ?j ?i * (2 * l + 1))

goal (1 subgoal):
 1. (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<And>i j. \<lbrakk>i < n; j < n\<rbrakk> \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))) \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
have *: "(\<Sum>j<n. ?left j i) =
        (\<Sum>j<n. poly.coeff (of_qr g) (x' j i) * \<psi> ^ ((x' j i) * (2 * l + 1)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j<n. poly.coeff (of_qr g) (x' j i) * \<psi> ^ (x' j i * (2 * l + 1)))
[PROOF STEP]
using rewrite[OF that] x'_def
[PROOF STATE]
proof (prove)
using this:
?j < n \<Longrightarrow> (if int ?j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (?j * (2 * l + 1)) = \<psi> ^ (x' ?j i * (2 * l + 1))
x' = (\<lambda>j i. nat ((int j - int i) mod int n))

goal (1 subgoal):
 1. (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j<n. poly.coeff (of_qr g) (x' j i) * \<psi> ^ (x' j i * (2 * l + 1)))
[PROOF STEP]
by (smt (verit, ccfv_SIG) lessThan_iff mult.assoc sum.cong)
[PROOF STATE]
proof (state)
this:
(\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>j<n. poly.coeff (of_qr g) (x' j i) * \<psi> ^ (x' j i * (2 * l + 1)))

goal (1 subgoal):
 1. (\<And>i j. \<lbrakk>i < n; j < n\<rbrakk> \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))) \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
have eq: "(\<lambda>j. x' j i) ` {..<n} = {..<n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>j. x' j i) ` {..<n} = {..<n}
[PROOF STEP]
unfolding x'_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n} = {..<n}
[PROOF STEP]
proof (safe, goal_cases)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>x j. j < n \<Longrightarrow> nat ((int j - int i) mod int n) < n
 2. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
case (1 _ j)
[PROOF STATE]
proof (state)
this:
j < n

goal (2 subgoals):
 1. \<And>x j. j < n \<Longrightarrow> nat ((int j - int i) mod int n) < n
 2. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
j < n
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
j < n

goal (1 subgoal):
 1. nat ((int j - int i) mod int n) < n
[PROOF STEP]
using Euclidean_Division.pos_mod_bound Euclidean_Division.pos_mod_sign
        n_gt_zero nat_less_iff
[PROOF STATE]
proof (prove)
using this:
j < n
0 < ?l \<Longrightarrow> ?k mod ?l < ?l
0 < ?l \<Longrightarrow> 0 \<le> ?k mod ?l
0 < int n
0 \<le> ?w \<Longrightarrow> (nat ?w < ?m) = (?w < int ?m)

goal (1 subgoal):
 1. nat ((int j - int i) mod int n) < n
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
nat ((int j - int i) mod int n) < n

goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
case (2 x)
[PROOF STATE]
proof (state)
this:
x < n

goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
define j where "j = (x+i) mod n"
[PROOF STATE]
proof (state)
this:
j = (x + i) mod n

goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
have "j\<in>{..<n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j \<in> {..<n}
[PROOF STEP]
by (metis j_def lessThan_iff mod_less_divisor n_gt_zero of_nat_0_less_iff)
[PROOF STATE]
proof (state)
this:
j \<in> {..<n}

goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
j \<in> {..<n}

goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
have "x = nat ((int j - int i) mod int n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x = nat ((int j - int i) mod int n)
[PROOF STEP]
unfolding j_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x = nat ((int ((x + i) mod n) - int i) mod int n)
[PROOF STEP]
by (simp add: "2" mod_diff_cong zmod_int)
[PROOF STATE]
proof (state)
this:
x = nat ((int j - int i) mod int n)

goal (1 subgoal):
 1. \<And>x. x < n \<Longrightarrow> x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
j \<in> {..<n}
x = nat ((int j - int i) mod int n)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
j \<in> {..<n}
x = nat ((int j - int i) mod int n)

goal (1 subgoal):
 1. x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x \<in> (\<lambda>j. nat ((int j - int i) mod int n)) ` {..<n}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<lambda>j. x' j i) ` {..<n} = {..<n}

goal (1 subgoal):
 1. (\<And>i j. \<lbrakk>i < n; j < n\<rbrakk> \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))) \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
have inj: "inj_on (\<lambda>j. x' j i) {..<n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on (\<lambda>j. x' j i) {..<n}
[PROOF STEP]
unfolding x'_def inj_on_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>x\<in>{..<n}. \<forall>y\<in>{..<n}. nat ((int x - int i) mod int n) = nat ((int y - int i) mod int n) \<longrightarrow> x = y
[PROOF STEP]
proof (safe, goal_cases)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x < n; y < n; nat ((int x - int i) mod int n) = nat ((int y - int i) mod int n)\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
case (1 x y)
[PROOF STATE]
proof (state)
this:
x < n
y < n
nat ((int x - int i) mod int n) = nat ((int y - int i) mod int n)

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x < n; y < n; nat ((int x - int i) mod int n) = nat ((int y - int i) mod int n)\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x < n
y < n
nat ((int x - int i) mod int n) = nat ((int y - int i) mod int n)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
x < n
y < n
nat ((int x - int i) mod int n) = nat ((int y - int i) mod int n)

goal (1 subgoal):
 1. x = y
[PROOF STEP]
by (smt (verit, best) Euclidean_Division.pos_mod_sign int_nat_eq
          less_imp_le_nat mod_diff_cong mod_pos_pos_trivial of_nat_0_less_iff
          of_nat_diff of_nat_eq_iff of_nat_less_0_iff zero_less_diff)
[PROOF STATE]
proof (state)
this:
x = y

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
inj_on (\<lambda>j. x' j i) {..<n}

goal (1 subgoal):
 1. (\<And>i j. \<lbrakk>i < n; j < n\<rbrakk> \<Longrightarrow> (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)) = \<psi> ^ (x' j i * (2 * l + 1))) \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
unfolding *
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>j<n. poly.coeff (of_qr g) (x' j i) * \<psi> ^ (x' j i * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
by (subst sum.reindex_cong[OF inj eq[symmetric],
        of "(\<lambda>x. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))"
        "(\<lambda>j. poly.coeff (of_qr g) (x' j i) * \<psi> ^ (x' j i * (2 * l + 1)))"], auto)
[PROOF STATE]
proof (state)
this:
(\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?i < n \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int ?i) mod int n)) * (if int j - int ?i < 0 then - 1 else 1) * \<psi>inv ^ (?i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))

goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?i < n \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int ?i) mod int n)) * (if int j - int ?i < 0 then - 1 else 1) * \<psi>inv ^ (?i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
?i < n \<Longrightarrow> (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int ?i) mod int n)) * (if int j - int ?i < 0 then - 1 else 1) * \<psi>inv ^ (?i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1))) = (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))

goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>j<n. poly.coeff (of_qr g) (nat ((int j - int i) mod int n)) * (if int j - int i < 0 then - 1 else 1) * \<psi>inv ^ (i * (2 * l + 1)) * \<psi> ^ (j * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1))))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "\<dots> = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) *
    (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1)))
[PROOF STEP]
unfolding sum_distrib_right
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))) = (\<Sum>na<n. poly.coeff (of_qr f) na * \<psi> ^ (na * (2 * l + 1)) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1))))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1)) * (\<Sum>x<n. poly.coeff (of_qr g) x * \<psi> ^ (x * (2 * l + 1)))) = (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1)))

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
have "\<dots> = ntt_coeff_poly f l * ntt_coeff_poly g l"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1))) = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
unfolding ntt_coeff_poly_def atLeast0LessThan
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1))) = (\<Sum>j<n. poly.coeff (of_qr f) j * \<psi> ^ (j * (2 * l + 1))) * (\<Sum>j<n. poly.coeff (of_qr g) j * \<psi> ^ (j * (2 * l + 1)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>i<n. poly.coeff (of_qr f) i * \<psi> ^ (i * (2 * l + 1))) * (\<Sum>x'<n. poly.coeff (of_qr g) x' * \<psi> ^ (x' * (2 * l + 1))) = ntt_coeff_poly f l * ntt_coeff_poly g l

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l

goal (1 subgoal):
 1. ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
ntt_coeff_poly (f * g) l = ntt_coeff_poly f l * ntt_coeff_poly g l

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma bisim_composeI [intro]:
  "\<lbrakk> bisim12 s1 s2; bisim23 s2 s3 \<rbrakk> \<Longrightarrow> (bisim12 \<circ>\<^sub>B bisim23) s1 s3"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>bisim12 s1 s2; bisim23 s2 s3\<rbrakk> \<Longrightarrow> (bisim12 \<circ>\<^sub>B bisim23) s1 s3
[PROOF STEP]
by(auto simp add: bisim_compose_def)


[STATEMENT]
lemma llength_ltake': "enat n < llength xs \<Longrightarrow> llength (ltake (enat n) xs) = enat n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. enat n < llength xs \<Longrightarrow> llength (ltake (enat n) xs) = enat n
[PROOF STEP]
by (metis llength_ltake min.strict_order_iff)


[STATEMENT]
lemma ndec_seqn1:"\<lbrakk>a \<in> (A::nat set); \<not> (\<exists>m. m\<in>A \<and> (\<forall>x\<in>A. m \<le> x))\<rbrakk> \<Longrightarrow>
                       (ndec_seq A a (Suc n)) \<le> (ndec_seq A a n) - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>a \<in> A; \<nexists>m. m \<in> A \<and> (\<forall>x\<in>A. m \<le> x)\<rbrakk> \<Longrightarrow> ndec_seq A a (Suc n) \<le> ndec_seq A a n - 1
[PROOF STEP]
apply (frule ndec_seqn [of "a" "A" "n"], assumption+,
       thin_tac "\<not> (\<exists>m. m \<in> A \<and> (\<forall>x\<in>A. m \<le> x))")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>a \<in> A; ndec_seq A a (Suc n) < ndec_seq A a n\<rbrakk> \<Longrightarrow> ndec_seq A a (Suc n) \<le> ndec_seq A a n - 1
[PROOF STEP]
apply (simp del:ndec_seq_Suc)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma addition_assoc:"\<lbrakk>assoc_bpp A f; x \<in> addition_set f A;
                       y \<in> addition_set f A; z \<in> addition_set f A\<rbrakk> \<Longrightarrow>
            (x \<^sub>f+ y) \<^sub>f+ z = x \<^sub>f+ (y \<^sub>f+ z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>assoc_bpp A f; x \<in> addition_set f A; y \<in> addition_set f A; z \<in> addition_set f A\<rbrakk> \<Longrightarrow> x \<^sub>f+ y \<^sub>f+ z = x \<^sub>f+ (y \<^sub>f+ z)
[PROOF STEP]
apply (simp add:assoc_bpp_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma mat_index_conjugate[simp]:
  shows "i < dim_row m \<Longrightarrow> j < dim_col m \<Longrightarrow> conjugate m  $$ (i,j) = conjugate (m $$ (i,j))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>i < dim_row m; j < dim_col m\<rbrakk> \<Longrightarrow> conjugate m $$ (i, j) = conjugate (m $$ (i, j))
[PROOF STEP]
unfolding conjugate_mat_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>i < dim_row m; j < dim_col m\<rbrakk> \<Longrightarrow> mat (dim_row m) (dim_col m) (\<lambda>(i, j). conjugate (m $$ (i, j))) $$ (i, j) = conjugate (m $$ (i, j))
[PROOF STEP]
by auto


[STATEMENT]
lemma to_list_filter: "p = sum_list [term * (Var v) ^ i. (term,i)\<leftarrow>((filter (\<lambda>(x,_). x\<noteq>0) (to_list v p)))]"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
define L where "L = to_list v p"
[PROOF STATE]
proof (state)
this:
L = to_list v p

goal (1 subgoal):
 1. p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
have "(\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, _). x \<noteq> 0) (to_list v p). term * Var v ^ i)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
unfolding L_def[symmetric]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(term, i)\<leftarrow>L. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) L. term * Var v ^ i)
[PROOF STEP]
apply(induction L)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. (\<Sum>a\<leftarrow>[]. case a of (term, i) \<Rightarrow> term * Var v ^ i) = (\<Sum>a\<leftarrow>filter (\<lambda>a. case a of (x, uu_) \<Rightarrow> x \<noteq> 0) []. case a of (term, i) \<Rightarrow> term * Var v ^ i)
 2. \<And>a L. (\<Sum>a\<leftarrow>L. case a of (term, i) \<Rightarrow> term * Var v ^ i) = (\<Sum>a\<leftarrow>filter (\<lambda>a. case a of (x, uu_) \<Rightarrow> x \<noteq> 0) L. case a of (term, i) \<Rightarrow> term * Var v ^ i) \<Longrightarrow> (\<Sum>a\<leftarrow>a # L. case a of (term, i) \<Rightarrow> term * Var v ^ i) = (\<Sum>a\<leftarrow>filter (\<lambda>a. case a of (x, uu_) \<Rightarrow> x \<noteq> 0) (a # L). case a of (term, i) \<Rightarrow> term * Var v ^ i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)

goal (1 subgoal):
 1. p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)

goal (1 subgoal):
 1. p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
using to_list_p[of p v]
[PROOF STATE]
proof (prove)
using this:
(\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i) = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
p = (\<Sum>(term, i)\<leftarrow>to_list v p. term * Var v ^ i)

goal (1 subgoal):
 1. p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
p = (\<Sum>(term, i)\<leftarrow>filter (\<lambda>(x, uu_). x \<noteq> 0) (to_list v p). term * Var v ^ i)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma weakly_preserves_hcomp:
    assumes "C.ide f" and "C.ide g" and "src\<^sub>C f = trg\<^sub>C g"
    shows "D.isomorphic (F f \<star>\<^sub>D F g) (F (f \<star>\<^sub>C g))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D.isomorphic (F f \<star>\<^sub>D F g) (F (f \<star>\<^sub>C g))
[PROOF STEP]
using assms D.isomorphic_def
[PROOF STATE]
proof (prove)
using this:
C.ide f
C.ide g
src\<^sub>C f = trg\<^sub>C g
D.isomorphic ?a ?a' = (\<exists>f. \<guillemotleft>f : ?a \<Rightarrow>\<^sub>D ?a'\<guillemotright> \<and> D.iso f)

goal (1 subgoal):
 1. D.isomorphic (F f \<star>\<^sub>D F g) (F (f \<star>\<^sub>C g))
[PROOF STEP]
by auto


[STATEMENT]
lemma [code_unfold]:
  "measure_pmf.expectation P (f :: 'a :: enum \<Rightarrow> real) = (\<Sum>x \<in> UNIV. pmf P x * f x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. measure_pmf.expectation P f = (\<Sum>x\<in>UNIV. pmf P x * f x)
[PROOF STEP]
by (metis (no_types, lifting) UNIV_I finite_class.finite_UNIV integral_measure_pmf
      real_scaleR_def sum.cong)


[STATEMENT]
theorem (in abelian_subgroup) a_factorgroup_is_group:
  "group (G A_Mod H)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Group.group (G A_Mod H)
[PROOF STEP]
by (rule normal.factorgroup_is_group [OF a_normal,
    folded A_FactGroup_def, simplified monoid_record_simps])


[STATEMENT]
lemma Top_dual_Bot: "Top cl = Bot (dual cl)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Top cl = Bot (dual cl)
[PROOF STEP]
by (simp add: Top_def Bot_def least_def greatest_def)


[STATEMENT]
lemma pseudo_divmod_impl [code]:
  "pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))"
    for f g :: "'a::comm_ring_1 poly"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
proof (cases "g = 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
g \<noteq> 0

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
g \<noteq> 0
[PROOF STEP]
have "last (coeffs g) \<noteq> 0"
    and "last (coeffs g) = lead_coeff g"
    and "coeffs g \<noteq> []"
[PROOF STATE]
proof (prove)
using this:
g \<noteq> 0

goal (1 subgoal):
 1. last (coeffs g) \<noteq> (0::'a) &&& last (coeffs g) = lead_coeff g &&& coeffs g \<noteq> []
[PROOF STEP]
by (simp_all add: last_coeffs_eq_coeff_degree)
[PROOF STATE]
proof (state)
this:
last (coeffs g) \<noteq> (0::'a)
last (coeffs g) = lead_coeff g
coeffs g \<noteq> []

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
last (coeffs g) \<noteq> (0::'a)
last (coeffs g) = lead_coeff g
coeffs g \<noteq> []

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
obtain q r where qr: "pseudo_divmod_main_list
    (last (coeffs g)) (rev [])
    (rev (coeffs f)) (rev (coeffs g))
    (1 + length (coeffs f) -
    length (coeffs g)) = (q, rev (rev r))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>q r. pseudo_divmod_main_list (last (coeffs g)) (rev []) (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, rev (rev r)) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
pseudo_divmod_main_list (last (coeffs g)) (rev []) (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, rev (rev r))

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
last (coeffs g) \<noteq> (0::'a)
last (coeffs g) = lead_coeff g
coeffs g \<noteq> []
pseudo_divmod_main_list (last (coeffs g)) (rev []) (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, rev (rev r))
[PROOF STEP]
have "(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g
    (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))"
[PROOF STATE]
proof (prove)
using this:
last (coeffs g) \<noteq> (0::'a)
last (coeffs g) = lead_coeff g
coeffs g \<noteq> []
pseudo_divmod_main_list (last (coeffs g)) (rev []) (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, rev (rev r))

goal (1 subgoal):
 1. (Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))
[PROOF STEP]
by (subst pseudo_divmod_main_list_invar [symmetric]) auto
[PROOF STATE]
proof (state)
this:
(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
have "pseudo_divmod_main_list
    (hd (rev (coeffs g))) []
    (rev (coeffs f)) (rev (coeffs g))
    (1 + length (coeffs f) -
    length (coeffs g)) = (q, r)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pseudo_divmod_main_list (hd (rev (coeffs g))) [] (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, r)
[PROOF STEP]
by (metis hd_rev qr rev.simps(1) rev_swap)
[PROOF STATE]
proof (state)
this:
pseudo_divmod_main_list (hd (rev (coeffs g))) [] (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, r)

goal (2 subgoals):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
 2. g \<noteq> 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))
pseudo_divmod_main_list (hd (rev (coeffs g))) [] (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, r)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(Poly q, Poly (rev r)) = pseudo_divmod_main (lead_coeff g) 0 f g (length (coeffs f) - Suc 0) (Suc (length (coeffs f)) - length (coeffs g))
pseudo_divmod_main_list (hd (rev (coeffs g))) [] (rev (coeffs f)) (rev (coeffs g)) (1 + length (coeffs f) - length (coeffs g)) = (q, r)

goal (1 subgoal):
 1. pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
by (simp add: degree_eq_length_coeffs pseudo_divmod_def pseudo_divmod_list_def)
[PROOF STATE]
proof (state)
this:
pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))

goal (1 subgoal):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
g = 0

goal (1 subgoal):
 1. g = 0 \<Longrightarrow> pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
g = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
g = 0

goal (1 subgoal):
 1. pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))
[PROOF STEP]
by (auto simp add: pseudo_divmod_def pseudo_divmod_list_def)
[PROOF STATE]
proof (state)
this:
pseudo_divmod f g = map_prod poly_of_list poly_of_list (pseudo_divmod_list (coeffs f) (coeffs g))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma sublist_ext:
  \<open>(\<forall>i. lo\<le>i\<and>i\<le>hi \<longrightarrow> xs'!i=xs!i) \<Longrightarrow>
   length xs' = length xs \<Longrightarrow>
   lo \<le> hi \<Longrightarrow> hi < length xs \<Longrightarrow>
   sublist xs' lo hi = sublist xs lo hi\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<forall>i. lo \<le> i \<and> i \<le> hi \<longrightarrow> xs' ! i = xs ! i; length xs' = length xs; lo \<le> hi; hi < length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs' lo hi = WB_Sort.sublist xs lo hi
[PROOF STEP]
apply (auto simp add: lt_Suc[where a=hi])
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>\<forall>i. lo \<le> i \<and> i \<le> hi \<longrightarrow> xs' ! i = xs ! i; length xs' = length xs; lo \<le> hi; Suc hi = length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs' lo hi = WB_Sort.sublist xs lo hi
 2. \<lbrakk>\<forall>i. lo \<le> i \<and> i \<le> hi \<longrightarrow> xs' ! i = xs ! i; length xs' = length xs; lo \<le> hi; Suc hi < length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs' lo hi = WB_Sort.sublist xs lo hi
[PROOF STEP]
subgoal
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<forall>i. lo \<le> i \<and> i \<le> hi \<longrightarrow> xs' ! i = xs ! i; length xs' = length xs; lo \<le> hi; Suc hi = length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs' lo hi = WB_Sort.sublist xs lo hi
[PROOF STEP]
by (auto simp add: sublist_until_end_eq_drop drop_ext)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<forall>i. lo \<le> i \<and> i \<le> hi \<longrightarrow> xs' ! i = xs ! i; length xs' = length xs; lo \<le> hi; Suc hi < length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs' lo hi = WB_Sort.sublist xs lo hi
[PROOF STEP]
subgoal
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<forall>i. lo \<le> i \<and> i \<le> hi \<longrightarrow> xs' ! i = xs ! i; length xs' = length xs; lo \<le> hi; Suc hi < length xs\<rbrakk> \<Longrightarrow> WB_Sort.sublist xs' lo hi = WB_Sort.sublist xs lo hi
[PROOF STEP]
by (auto simp add: sublist_ext')
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma ladder_cut_prefix_j:
  assumes index_bound: "index < length L"
  assumes length_L: "length L > 0"
  shows "ladder_j (ladder_cut_prefix d L) index = ladder_j L index - d"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ladder_j (ladder_cut_prefix d L) index = ladder_j L index - d
[PROOF STEP]
apply (simp add: ladder_j_def ladder_cut_prefix_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. deriv_j ((ladder_shift_j d L)[0 := (ladder_n L 0, deriv_j (L ! 0) - d, ladder_i L 0 - d)] ! index) = deriv_j (L ! index) - d
[PROOF STEP]
apply (cases index)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index = 0 \<Longrightarrow> deriv_j ((ladder_shift_j d L)[0 := (ladder_n L 0, deriv_j (L ! 0) - d, ladder_i L 0 - d)] ! index) = deriv_j (L ! index) - d
 2. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j ((ladder_shift_j d L)[0 := (ladder_n L 0, deriv_j (L ! 0) - d, ladder_i L 0 - d)] ! index) = deriv_j (L ! index) - d
[PROOF STEP]
apply (auto simp add: length_L)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index = 0 \<Longrightarrow> deriv_j ((ladder_shift_j d L)[0 := (ladder_n L 0, deriv_j (L ! 0) - d, ladder_i L 0 - d)] ! 0) = deriv_j (L ! 0) - d
 2. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (ladder_shift_j d L ! Suc nat) = deriv_j (L ! Suc nat) - d
[PROOF STEP]
apply (subst nth_list_update_eq)
[PROOF STATE]
proof (prove)
goal (3 subgoals):
 1. index = 0 \<Longrightarrow> 0 < length (ladder_shift_j d L)
 2. index = 0 \<Longrightarrow> deriv_j (ladder_n L 0, deriv_j (L ! 0) - d, ladder_i L 0 - d) = deriv_j (L ! 0) - d
 3. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (ladder_shift_j d L ! Suc nat) = deriv_j (L ! Suc nat) - d
[PROOF STEP]
apply (simp only: ladder_shift_j_length length_L)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. index = 0 \<Longrightarrow> deriv_j (ladder_n L 0, deriv_j (L ! 0) - d, ladder_i L 0 - d) = deriv_j (L ! 0) - d
 2. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (ladder_shift_j d L ! Suc nat) = deriv_j (L ! Suc nat) - d
[PROOF STEP]
apply (simp add: deriv_j_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (ladder_shift_j d L ! Suc nat) = deriv_j (L ! Suc nat) - d
[PROOF STEP]
apply (subst deriv_j_ladder_shift_j)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>nat. index = Suc nat \<Longrightarrow> Suc nat < length L
 2. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (L ! Suc nat) - d = deriv_j (L ! Suc nat) - d
[PROOF STEP]
using index_bound
[PROOF STATE]
proof (prove)
using this:
index < length L

goal (2 subgoals):
 1. \<And>nat. index = Suc nat \<Longrightarrow> Suc nat < length L
 2. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (L ! Suc nat) - d = deriv_j (L ! Suc nat) - d
[PROOF STEP]
apply arith
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>nat. index = Suc nat \<Longrightarrow> deriv_j (L ! Suc nat) - d = deriv_j (L ! Suc nat) - d
[PROOF STEP]
by blast


[STATEMENT]
lemma mat_plus_gt_left_mono: assumes sd_n: "sd \<le> n" and gt: "mat_gt (\<succ>) sd A B"
  and A: "A \<in> carrier_mat n n" and B: "B \<in> carrier_mat n n" and C: "C \<in> carrier_mat n n"
  shows "mat_gt (\<succ>) sd (A + C) (B + C)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat_gt (\<succ>) sd (A + C) (B + C)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. mat_gt (\<succ>) sd (A + C) (B + C)
[PROOF STEP]
note wf = A B C
[PROOF STATE]
proof (state)
this:
A \<in> carrier_mat n n
B \<in> carrier_mat n n
C \<in> carrier_mat n n

goal (1 subgoal):
 1. mat_gt (\<succ>) sd (A + C) (B + C)
[PROOF STEP]
from mat_gtD[OF gt]
[PROOF STATE]
proof (chain)
picking this:
A \<ge>\<^sub>m B
\<exists>i<sd. \<exists>j<sd. A $$ (i, j) \<succ> B $$ (i, j)
[PROOF STEP]
obtain i j
    where AB: "A \<ge>\<^sub>m B" and ij: "i < sd" "j < sd" and gt: "A $$ (i,j) \<succ> B $$ (i,j)"
[PROOF STATE]
proof (prove)
using this:
A \<ge>\<^sub>m B
\<exists>i<sd. \<exists>j<sd. A $$ (i, j) \<succ> B $$ (i, j)

goal (1 subgoal):
 1. (\<And>i j. \<lbrakk>A \<ge>\<^sub>m B; i < sd; j < sd; A $$ (i, j) \<succ> B $$ (i, j)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A \<ge>\<^sub>m B
i < sd
j < sd
A $$ (i, j) \<succ> B $$ (i, j)

goal (1 subgoal):
 1. mat_gt (\<succ>) sd (A + C) (B + C)
[PROOF STEP]
from plus_gt_left_mono[OF gt, of "C $$ (i,j)"]
[PROOF STATE]
proof (chain)
picking this:
A $$ (i, j) + C $$ (i, j) \<succ> B $$ (i, j) + C $$ (i, j)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
A $$ (i, j) + C $$ (i, j) \<succ> B $$ (i, j) + C $$ (i, j)

goal (1 subgoal):
 1. mat_gt (\<succ>) sd (A + C) (B + C)
[PROOF STEP]
by (intro mat_gtI[OF mat_geI[of _ n n] ij], insert mat_geD[OF AB] wf ij sd_n, auto intro: plus_left_mono)
[PROOF STATE]
proof (state)
this:
mat_gt (\<succ>) sd (A + C) (B + C)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma median_est:
  assumes "interval I"
  assumes "2*card {k. k < n \<and> f k \<in> I} > n"
  shows "median n f \<in> I"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. median n f \<in> I
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. median n f \<in> I
[PROOF STEP]
have a:"{k. k < n \<and> f k \<in> I} = {i. i < n \<and> map f [0..<n] ! i \<in> I}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {k. k < n \<and> f k \<in> I} = {i. i < n \<and> map f [0..<n] ! i \<in> I}
[PROOF STEP]
apply (rule order_antisym, rule subsetI, simp)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {i. i < n \<and> map f [0..<n] ! i \<in> I} \<subseteq> {k. k < n \<and> f k \<in> I}
[PROOF STEP]
by (rule subsetI, simp, metis add_0 diff_zero nth_map_upt)
[PROOF STATE]
proof (state)
this:
{k. k < n \<and> f k \<in> I} = {i. i < n \<and> map f [0..<n] ! i \<in> I}

goal (1 subgoal):
 1. median n f \<in> I
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. median n f \<in> I
[PROOF STEP]
apply (simp add:median_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sort (map f [0..<n]) ! (n div 2) \<in> I
[PROOF STEP]
apply (rule mid_in_interval[where I="I" and xs="sort (map f [0..<n])", simplified])
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. n < 2 * length (filter (\<lambda>x. x \<in> I) (sort (map f [0..<n])))
 2. interval I
[PROOF STEP]
using assms a
[PROOF STATE]
proof (prove)
using this:
interval I
n < 2 * card {k. k < n \<and> f k \<in> I}
{k. k < n \<and> f k \<in> I} = {i. i < n \<and> map f [0..<n] ! i \<in> I}

goal (2 subgoals):
 1. n < 2 * length (filter (\<lambda>x. x \<in> I) (sort (map f [0..<n])))
 2. interval I
[PROOF STEP]
apply (simp add:filter_sort comp_def length_filter_conv_card)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. interval I
[PROOF STEP]
by (simp add:assms)
[PROOF STATE]
proof (state)
this:
median n f \<in> I

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma Inf_notin_open:
  assumes A: "open A"
    and bnd: "\<forall>a\<in>A. x < a"
  shows "Inf A \<notin> A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Inf A \<notin> A
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. Inf A \<in> A \<Longrightarrow> False
[PROOF STEP]
assume "Inf A \<in> A"
[PROOF STATE]
proof (state)
this:
Inf A \<in> A

goal (1 subgoal):
 1. Inf A \<in> A \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Inf A \<in> A
[PROOF STEP]
obtain b where "b < Inf A" "{b <.. Inf A} \<subseteq> A"
[PROOF STATE]
proof (prove)
using this:
Inf A \<in> A

goal (1 subgoal):
 1. (\<And>b. \<lbrakk>b < Inf A; {b<..Inf A} \<subseteq> A\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using open_left[of A "Inf A" x] assms
[PROOF STATE]
proof (prove)
using this:
Inf A \<in> A
\<lbrakk>open A; Inf A \<in> A; x < Inf A\<rbrakk> \<Longrightarrow> \<exists>b<Inf A. {b<..Inf A} \<subseteq> A
open A
\<forall>a\<in>A. x < a

goal (1 subgoal):
 1. (\<And>b. \<lbrakk>b < Inf A; {b<..Inf A} \<subseteq> A\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b < Inf A
{b<..Inf A} \<subseteq> A

goal (1 subgoal):
 1. Inf A \<in> A \<Longrightarrow> False
[PROOF STEP]
with dense[of b "Inf A"]
[PROOF STATE]
proof (chain)
picking this:
b < Inf A \<Longrightarrow> \<exists>z>b. z < Inf A
b < Inf A
{b<..Inf A} \<subseteq> A
[PROOF STEP]
obtain c where "c < Inf A" "c \<in> A"
[PROOF STATE]
proof (prove)
using this:
b < Inf A \<Longrightarrow> \<exists>z>b. z < Inf A
b < Inf A
{b<..Inf A} \<subseteq> A

goal (1 subgoal):
 1. (\<And>c. \<lbrakk>c < Inf A; c \<in> A\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (auto simp: subset_eq)
[PROOF STATE]
proof (state)
this:
c < Inf A
c \<in> A

goal (1 subgoal):
 1. Inf A \<in> A \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
c < Inf A
c \<in> A
[PROOF STEP]
show False
[PROOF STATE]
proof (prove)
using this:
c < Inf A
c \<in> A

goal (1 subgoal):
 1. False
[PROOF STEP]
using cInf_lower[OF \<open>c \<in> A\<close>] bnd
[PROOF STATE]
proof (prove)
using this:
c < Inf A
c \<in> A
bdd_below A \<Longrightarrow> Inf A \<le> c
\<forall>a\<in>A. x < a

goal (1 subgoal):
 1. False
[PROOF STEP]
by (metis not_le less_imp_le bdd_belowI)
[PROOF STATE]
proof (state)
this:
False

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma graph_from_list_foldl: "graph_from_list l = fold ins_edge l graph_empty"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. graph_from_list l = fold ins_edge l graph_empty
[PROOF STEP]
unfolding graph_from_list_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. foldr ins_edge l graph_empty = fold ins_edge l graph_empty
[PROOF STEP]
apply (rule foldr_fold[THEN fun_cong])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> set l; y \<in> set l\<rbrakk> \<Longrightarrow> ins_edge y \<circ> ins_edge x = ins_edge x \<circ> ins_edge y
[PROOF STEP]
by (auto simp: fun_eq_iff graph_eq_iff edges_ins_edge)


[STATEMENT]
lemma Gramian_determinant_ge1:
  assumes "k \<le> m"
  shows "1 \<le> Gramian_determinant fs k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
have "0 < Gramian_determinant fs k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0::'a) < Gramian_determinant fs k
[PROOF STEP]
by (simp add: assms Gramian_determinant(2) less_or_eq_imp_le)
[PROOF STATE]
proof (state)
this:
(0::'a) < Gramian_determinant fs k

goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(0::'a) < Gramian_determinant fs k

goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
have "Gramian_determinant fs k \<in> \<int>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Gramian_determinant fs k \<in> \<int>
[PROOF STEP]
by (simp add: Gramian_determinant_Ints assms fs_int)
[PROOF STATE]
proof (state)
this:
Gramian_determinant fs k \<in> \<int>

goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(0::'a) < Gramian_determinant fs k
Gramian_determinant fs k \<in> \<int>
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(0::'a) < Gramian_determinant fs k
Gramian_determinant fs k \<in> \<int>

goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
using Ints_nonzero_abs_ge1
[PROOF STATE]
proof (prove)
using this:
(0::'a) < Gramian_determinant fs k
Gramian_determinant fs k \<in> \<int>
\<lbrakk>?x \<in> \<int>; ?x \<noteq> (0::?'a)\<rbrakk> \<Longrightarrow> (1::?'a) \<le> \<bar>?x\<bar>

goal (1 subgoal):
 1. (1::'a) \<le> Gramian_determinant fs k
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
(1::'a) \<le> Gramian_determinant fs k

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma nat_term_compare_LEX [code]: "nat_term_compare LEX = lex_comp"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nat_term_compare Term_Order.LEX = lex_comp
[PROOF STEP]
unfolding LEX_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nat_term_compare (Abs_nat_term_order lex_comp) = lex_comp
[PROOF STEP]
using comparator_lex_comp nat_term_comp_lex_comp
[PROOF STATE]
proof (prove)
using this:
comparator lex_comp
nat_term_comp lex_comp

goal (1 subgoal):
 1. nat_term_compare (Abs_nat_term_order lex_comp) = lex_comp
[PROOF STEP]
by (rule nat_term_compare_Abs_nat_term_order_id)


[STATEMENT]
lemma dvd_power_minus_1_conv1:
  fixes x::nat
  assumes x: "x > 1"
    and a: "a > 0"
    and xa_dvd: "x ^ a - 1 dvd x^b - 1"
    and b0: "b > 0"
  shows "a dvd b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
define r where r[simp]: "r = b mod a"
[PROOF STATE]
proof (state)
this:
r = b mod a

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
define q where q[simp]: "q = b div a"
[PROOF STATE]
proof (state)
this:
q = b div a

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
have b: "b = a * q + r"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. b = a * q + r
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
b = a * q + r

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
have ra: "r < a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. r < a
[PROOF STEP]
by (simp add: a)
[PROOF STATE]
proof (state)
this:
r < a

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
hence xr_less_xa: "x ^ r - 1 < x ^ a - 1"
[PROOF STATE]
proof (prove)
using this:
r < a

goal (1 subgoal):
 1. x ^ r - 1 < x ^ a - 1
[PROOF STEP]
using x power_strict_increasing_iff diff_less_mono x
[PROOF STATE]
proof (prove)
using this:
r < a
1 < x
(1::?'a) < ?b \<Longrightarrow> (?b ^ ?x < ?b ^ ?y) = (?x < ?y)
\<lbrakk>?a < ?b; ?c \<le> ?a\<rbrakk> \<Longrightarrow> ?a - ?c < ?b - ?c
1 < x

goal (1 subgoal):
 1. x ^ r - 1 < x ^ a - 1
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
x ^ r - 1 < x ^ a - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
have dvd: "x ^ a - 1 dvd x ^ (a * q) - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x ^ a - 1 dvd x ^ (a * q) - 1
[PROOF STEP]
using x_power_aq_minus_1_rw[OF x a b0]
[PROOF STATE]
proof (prove)
using this:
x ^ (a * ?q) - 1 = (x ^ a - 1) * sum ((^) (x ^ a)) {..<?q}

goal (1 subgoal):
 1. x ^ a - 1 dvd x ^ (a * q) - 1
[PROOF STEP]
unfolding dvd_def
[PROOF STATE]
proof (prove)
using this:
x ^ (a * ?q) - 1 = (x ^ a - 1) * sum ((^) (x ^ a)) {..<?q}

goal (1 subgoal):
 1. \<exists>k. x ^ (a * q) - 1 = (x ^ a - 1) * k
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x ^ a - 1 dvd x ^ (a * q) - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
have "x^b - 1 = x^b - x^r + x^r - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x ^ b - 1 = x ^ b - x ^ r + x ^ r - 1
[PROOF STEP]
using assms(1) assms(4)
[PROOF STATE]
proof (prove)
using this:
1 < x
0 < b

goal (1 subgoal):
 1. x ^ b - 1 = x ^ b - x ^ r + x ^ r - 1
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x ^ b - 1 = x ^ b - x ^ r + x ^ r - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
x ^ b - 1 = x ^ b - x ^ r + x ^ r - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
have "... = x^r * (x^(a*q) - 1) + x^r - 1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x ^ b - x ^ r + x ^ r - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1
[PROOF STEP]
by (metis (no_types, lifting) b diff_mult_distrib2 mult.commute nat_mult_1_right power_add)
[PROOF STATE]
proof (state)
this:
x ^ b - x ^ r + x ^ r - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
x ^ b - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1
[PROOF STEP]
have "x^b - 1 = x^r * (x^(a*q) - 1) + x^r - 1"
[PROOF STATE]
proof (prove)
using this:
x ^ b - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1

goal (1 subgoal):
 1. x ^ b - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
x ^ b - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
hence "x ^ a - 1 dvd x ^ r * (x ^ (a * q) - 1) + x ^ r - 1"
[PROOF STATE]
proof (prove)
using this:
x ^ b - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1

goal (1 subgoal):
 1. x ^ a - 1 dvd x ^ r * (x ^ (a * q) - 1) + x ^ r - 1
[PROOF STEP]
using xa_dvd
[PROOF STATE]
proof (prove)
using this:
x ^ b - 1 = x ^ r * (x ^ (a * q) - 1) + x ^ r - 1
x ^ a - 1 dvd x ^ b - 1

goal (1 subgoal):
 1. x ^ a - 1 dvd x ^ r * (x ^ (a * q) - 1) + x ^ r - 1
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
x ^ a - 1 dvd x ^ r * (x ^ (a * q) - 1) + x ^ r - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
hence "x^a - 1 dvd x^r - 1"
[PROOF STATE]
proof (prove)
using this:
x ^ a - 1 dvd x ^ r * (x ^ (a * q) - 1) + x ^ r - 1

goal (1 subgoal):
 1. x ^ a - 1 dvd x ^ r - 1
[PROOF STEP]
by (metis (no_types) diff_add_inverse diff_commute dvd dvd_diff_nat dvd_trans dvd_triv_right)
[PROOF STATE]
proof (state)
this:
x ^ a - 1 dvd x ^ r - 1

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
hence "r = 0"
[PROOF STATE]
proof (prove)
using this:
x ^ a - 1 dvd x ^ r - 1

goal (1 subgoal):
 1. r = 0
[PROOF STEP]
using xr_less_xa
[PROOF STATE]
proof (prove)
using this:
x ^ a - 1 dvd x ^ r - 1
x ^ r - 1 < x ^ a - 1

goal (1 subgoal):
 1. r = 0
[PROOF STEP]
by (meson nat_dvd_not_less neq0_conv one_less_power x zero_less_diff)
[PROOF STATE]
proof (state)
this:
r = 0

goal (1 subgoal):
 1. a dvd b
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
r = 0

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

goal:
No subgoals!
[PROOF STEP]
qed