[STATEMENT]
lemma reduce_abs_invertible_mat:
  assumes A': "A' \<in> carrier_mat m n" and a: "a<m" and j: "0<n" and b: "b<m" and ab: "a \<noteq> b"
  and A_def: "A = A' @\<^sub>r (D \<cdot>\<^sub>m (1\<^sub>m n))"
  and Aaj: "A $$ (a,0) \<noteq> 0"
  and a_less_b: "a < b"
  and mn: "m\<ge>n"
  and D_ge0: "D > 0"
shows "\<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m+n) (m+n) \<and> (reduce_abs a b D A) = P * A" (is ?thesis1)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
obtain p q u v d where pquvd: "(p,q,u,v,d) = euclid_ext2 (A$$(a,0)) (A$$(b,0))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>p q u v d. (p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (b, 0)) \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis prod_cases5)
[PROOF STATE]
proof (state)
this:
(p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (b, 0))

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
let ?A = "Matrix.mat (dim_row A) (dim_col A)
          (\<lambda>(i,k). if i = a then (p*A$$(a,k) + q*A$$(b,k))
                   else if i = b then u * A$$(a,k) + v * A$$(b,k)
                   else A$$(i,k)
            )"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have D: "D \<cdot>\<^sub>m 1\<^sub>m n \<in> carrier_mat n n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D \<cdot>\<^sub>m 1\<^sub>m n \<in> carrier_mat n n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
D \<cdot>\<^sub>m 1\<^sub>m n \<in> carrier_mat n n

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have A: "A \<in> carrier_mat (m+n) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<in> carrier_mat (m + n) n
[PROOF STEP]
using A_def A'
[PROOF STATE]
proof (prove)
using this:
A = A' @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n
A' \<in> carrier_mat m n

goal (1 subgoal):
 1. A \<in> carrier_mat (m + n) n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
hence A_carrier: "?A \<in> carrier_mat (m+n) n"
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
let ?BM = "bezout_matrix_JNF A a b 0 euclid_ext2"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have A'_BZ_A: "?A = ?BM * A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) = bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
by (rule bezout_matrix_JNF_mult_eq[OF A' _ _ ab A_def D pquvd], insert a b, auto)
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) = bezout_matrix_JNF A a b 0 euclid_ext2 * A

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have invertible_bezout: "invertible_mat ?BM"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. invertible_mat (bezout_matrix_JNF A a b 0 euclid_ext2)
[PROOF STEP]
by (rule invertible_bezout_matrix_JNF[OF A is_bezout_ext_euclid_ext2 a_less_b _ j Aaj],
        insert a_less_b b, auto)
[PROOF STATE]
proof (state)
this:
invertible_mat (bezout_matrix_JNF A a b 0 euclid_ext2)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have BM: "?BM \<in> carrier_mat (m+n) (m+n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
[PROOF STEP]
unfolding bezout_matrix_JNF_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_row A) (\<lambda>(x, y). let (p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (b, 0)) in if x = a \<and> y = a then p else if x = a \<and> y = b then q else if x = b \<and> y = a then u else if x = b \<and> y = b then v else if x = y then 1 else 0) \<in> carrier_mat (m + n) (m + n)
[PROOF STEP]
using A
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_row A) (\<lambda>(x, y). let (p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (b, 0)) in if x = a \<and> y = a then p else if x = a \<and> y = b then q else if x = b \<and> y = a then u else if x = b \<and> y = b then v else if x = y then 1 else 0) \<in> carrier_mat (m + n) (m + n)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
define xs where "xs = filter (\<lambda>i. abs (?A $$ (a,i)) > D) [0..<n]"
[PROOF STATE]
proof (state)
this:
xs = filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, i)\<bar>) [0..<n]

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
let ?reduce_a = "reduce_row_mod_D_abs ?A a xs D m"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
let ?A' = "mat_of_rows n [Matrix.row ?A i. i \<leftarrow> [0..<m]]"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have A_A'_D: "?A = ?A' @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) = mat_of_rows n (map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) [0..<m]) @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n
[PROOF STEP]
proof (rule matrix_append_rows_eq_if_preserves[OF A_carrier D], rule+)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
fix i j
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
assume i: "i \<in> {m..<m + n}" and j: "j < n"
[PROOF STATE]
proof (state)
this:
i \<in> {m..<m + n}
j < n

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have "?A $$ (i,j) = A $$ (i,j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = A $$ (i, j)
[PROOF STEP]
using i a b A j
[PROOF STATE]
proof (prove)
using this:
i \<in> {m..<m + n}
a < m
b < m
A \<in> carrier_mat (m + n) n
j < n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = A $$ (i, j)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = A $$ (i, j)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = A $$ (i, j)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have "... = (if i < dim_row A' then A' $$(i,j) else (D \<cdot>\<^sub>m (1\<^sub>m n))$$(i-m,j))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, j) = (if i < dim_row A' then A' $$ (i, j) else (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j))
[PROOF STEP]
by (unfold A_def, rule append_rows_nth[OF A' D _ j], insert i, auto)
[PROOF STATE]
proof (state)
this:
A $$ (i, j) = (if i < dim_row A' then A' $$ (i, j) else (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j))

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A $$ (i, j) = (if i < dim_row A' then A' $$ (i, j) else (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j))

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have "... = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if i < dim_row A' then A' $$ (i, j) else (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
using i A'
[PROOF STATE]
proof (prove)
using this:
i \<in> {m..<m + n}
A' \<in> carrier_mat m n

goal (1 subgoal):
 1. (if i < dim_row A' then A' $$ (i, j) else (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if i < dim_row A' then A' $$ (i, j) else (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
show "?A $$ (i,j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)"
[PROOF STATE]
proof (prove)
using this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) = mat_of_rows n (map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) [0..<m]) @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have reduce_a_eq: "?reduce_a = Matrix.mat (dim_row ?A) (dim_col ?A)
    (\<lambda>(i, k). if i = a \<and> k \<in> set xs then
      if k = 0 \<and> D dvd ?A$$(i,k) then D else ?A $$ (i, k) gmod D else ?A $$ (i, k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k))
[PROOF STEP]
by (rule reduce_row_mod_D_abs[OF A_A'_D _ a _], insert xs_def mn D_ge0, auto)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k))

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have reduce_a: "?reduce_a \<in> carrier_mat (m+n) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m \<in> carrier_mat (m + n) n
[PROOF STEP]
using reduce_a_eq A
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k))
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m \<in> carrier_mat (m + n) n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have "\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> ?reduce_a = P * ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))
[PROOF STEP]
by (rule reduce_row_mod_D_abs_invertible_mat[OF A_A'_D _ a], insert xs_def mn, auto)
[PROOF STATE]
proof (state)
this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))
[PROOF STEP]
obtain P where P: "P \<in> carrier_mat (m + n) (m + n)" and inv_P: "invertible_mat P"
    and reduce_a_PA: "?reduce_a = P * ?A"
[PROOF STATE]
proof (prove)
using this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))

goal (1 subgoal):
 1. (\<And>P. \<lbrakk>P \<in> carrier_mat (m + n) (m + n); invertible_mat P; reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
P \<in> carrier_mat (m + n) (m + n)
invertible_mat P
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
define ys where "ys = filter (\<lambda>i. abs (?A $$ (b,i)) > D) [0..<n]"
[PROOF STATE]
proof (state)
this:
ys = filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, i)\<bar>) [0..<n]

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
let ?reduce_b = "reduce_row_mod_D_abs ?reduce_a b ys D m"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
let ?B' = "mat_of_rows n [Matrix.row ?reduce_a i. i \<leftarrow> [0..<m]]"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have reduce_a_B'_D: "?reduce_a = ?B' @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = mat_of_rows n (map (row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) [0..<m]) @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n
[PROOF STEP]
proof (rule matrix_append_rows_eq_if_preserves[OF reduce_a D], rule+)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
fix i ja
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
assume i: "i \<in> {m..<m + n}" and ja: "ja < n"
[PROOF STATE]
proof (state)
this:
i \<in> {m..<m + n}
ja < n

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have i_not_a:"i\<noteq>a" and i_not_b: "i\<noteq>b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i \<noteq> a &&& i \<noteq> b
[PROOF STEP]
using i a b
[PROOF STATE]
proof (prove)
using this:
i \<in> {m..<m + n}
a < m
b < m

goal (1 subgoal):
 1. i \<noteq> a &&& i \<noteq> b
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i \<noteq> a
i \<noteq> b

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have "?reduce_a $$ (i,ja) = ?A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using i i_not_a i_not_b ja A
[PROOF STATE]
proof (prove)
using this:
i \<in> {m..<m + n}
i \<noteq> a
i \<noteq> b
ja < n
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have "... = A $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
using i i_not_a i_not_b ja A
[PROOF STATE]
proof (prove)
using this:
i \<in> {m..<m + n}
i \<noteq> a
i \<noteq> b
ja < n
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
have "... = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)
[PROOF STEP]
by (smt D append_rows_nth A' A_def atLeastLessThan_iff
          carrier_matD(1) i ja less_irrefl_nat nat_SN.compat)
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i \<in> {m..<m + n}; j < n\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, j) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, j)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)
[PROOF STEP]
show "?reduce_a $$ (i,ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)"
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = (D \<cdot>\<^sub>m 1\<^sub>m n) $$ (i - m, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = mat_of_rows n (map (row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) [0..<m]) @\<^sub>r D \<cdot>\<^sub>m 1\<^sub>m n

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have reduce_b_eq: "?reduce_b = Matrix.mat (dim_row ?reduce_a) (dim_col ?reduce_a)
    (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd ?reduce_a$$(i,k) then D
      else ?reduce_a $$ (i, k) gmod D else ?reduce_a $$ (i, k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k))
[PROOF STEP]
by (rule reduce_row_mod_D_abs[OF reduce_a_B'_D _ b _ _ mn], unfold ys_def, insert D_ge0, auto)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k))

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have "\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> ?reduce_b = P * ?reduce_a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = P * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m
[PROOF STEP]
by (rule reduce_row_mod_D_abs_invertible_mat[OF reduce_a_B'_D _ b _ mn], insert ys_def, auto)
[PROOF STATE]
proof (state)
this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = P * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = P * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m
[PROOF STEP]
obtain Q where Q: "Q \<in> carrier_mat (m + n) (m + n)" and inv_Q: "invertible_mat Q"
    and reduce_b_Q_reduce: "?reduce_b = Q * ?reduce_a"
[PROOF STATE]
proof (prove)
using this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = P * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m

goal (1 subgoal):
 1. (\<And>Q. \<lbrakk>Q \<in> carrier_mat (m + n) (m + n); invertible_mat Q; reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = Q * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
Q \<in> carrier_mat (m + n) (m + n)
invertible_mat Q
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = Q * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have reduce_b_eq_reduce: "?reduce_b = (reduce_abs a b D A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = reduce_abs a b D A
[PROOF STEP]
proof (rule eq_matI)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce_abs a b D A); j < dim_col (reduce_abs a b D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, j) = reduce_abs a b D A $$ (i, j)
 2. dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_row (reduce_abs a b D A)
 3. dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_col (reduce_abs a b D A)
[PROOF STEP]
show dr_eq: "dim_row ?reduce_b = dim_row (reduce_abs a b D A)"
      and dc_eq: "dim_col ?reduce_b = dim_col (reduce_abs a b D A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_row (reduce_abs a b D A) &&& dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_col (reduce_abs a b D A)
[PROOF STEP]
using reduce_preserves_dimensions
[PROOF STATE]
proof (prove)
using this:
dim_row (reduce ?a ?b ?D ?A) = dim_row ?A
dim_col (reduce ?a ?b ?D ?A) = dim_col ?A
dim_row (reduce_abs ?a ?b ?D ?A) = dim_row ?A
dim_col (reduce_abs ?a ?b ?D ?A) = dim_col ?A

goal (1 subgoal):
 1. dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_row (reduce_abs a b D A) &&& dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_col (reduce_abs a b D A)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_row (reduce_abs a b D A)
dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_col (reduce_abs a b D A)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce_abs a b D A); j < dim_col (reduce_abs a b D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, j) = reduce_abs a b D A $$ (i, j)
[PROOF STEP]
fix i ja
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce_abs a b D A); j < dim_col (reduce_abs a b D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, j) = reduce_abs a b D A $$ (i, j)
[PROOF STEP]
assume i: "i<dim_row (reduce_abs a b D A)" and ja: "ja< dim_col (reduce_abs a b D A)"
[PROOF STATE]
proof (state)
this:
i < dim_row (reduce_abs a b D A)
ja < dim_col (reduce_abs a b D A)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce_abs a b D A); j < dim_col (reduce_abs a b D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, j) = reduce_abs a b D A $$ (i, j)
[PROOF STEP]
have im: "i<m+n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i < m + n
[PROOF STEP]
using A i reduce_preserves_dimensions(3)
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
i < dim_row (reduce_abs a b D A)
dim_row (reduce_abs ?a ?b ?D ?A) = dim_row ?A

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

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce_abs a b D A); j < dim_col (reduce_abs a b D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, j) = reduce_abs a b D A $$ (i, j)
[PROOF STEP]
have ja_n: "ja<n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja < n
[PROOF STEP]
using A ja reduce_preserves_dimensions(4)
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
ja < dim_col (reduce_abs a b D A)
dim_col (reduce_abs ?a ?b ?D ?A) = dim_col ?A

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

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce_abs a b D A); j < dim_col (reduce_abs a b D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, j) = reduce_abs a b D A $$ (i, j)
[PROOF STEP]
show "?reduce_b $$ (i,ja) = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
proof (cases "(i\<noteq>a \<and> i\<noteq>b)")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
i \<noteq> a \<and> i \<noteq> b

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "?reduce_b $$ (i,ja) = ?reduce_a $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
unfolding reduce_b_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
by (smt True dr_eq dc_eq i index_mat(1) ja prod.simps(2) reduce_row_mod_D_preserves_dimensions_abs)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = ?A $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by (smt A True carrier_matD(2) dim_col_mat(1) dim_row_mat(1) i index_mat(1) ja_n
            reduce_a_eq reduce_preserves_dimensions(3) split_conv)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = A $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
using A True im ja_n
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
i \<noteq> a \<and> i \<noteq> b
i < m + n
ja < n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using im ja_n A True
[PROOF STATE]
proof (prove)
using this:
i < m + n
ja < n
A \<in> carrier_mat (m + n) n
i \<noteq> a \<and> i \<noteq> b

goal (1 subgoal):
 1. A $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> b \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> (i \<noteq> a \<and> i \<noteq> b)

goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
note a_or_b = False
[PROOF STATE]
proof (state)
this:
\<not> (i \<noteq> a \<and> i \<noteq> b)

goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> b) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
proof (cases "i=a")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
i = a

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
note ia = True
[PROOF STATE]
proof (state)
this:
i = a

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
hence i_not_b: "i\<noteq>b"
[PROOF STATE]
proof (prove)
using this:
i = a

goal (1 subgoal):
 1. i \<noteq> b
[PROOF STEP]
using ab
[PROOF STATE]
proof (prove)
using this:
i = a
a \<noteq> b

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

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
proof (cases "abs((p*A$$(a,ja) + q*A$$(b,ja))) > D")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>

goal (2 subgoals):
 1. D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
note ge_D = True
[PROOF STATE]
proof (state)
this:
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>

goal (2 subgoals):
 1. D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have ja_in_xs: "ja \<in> set xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<in> set xs
[PROOF STEP]
unfolding xs_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<in> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, i)\<bar>) [0..<n])
[PROOF STEP]
using True ja_n im a A
[PROOF STATE]
proof (prove)
using this:
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<in> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, i)\<bar>) [0..<n])
[PROOF STEP]
unfolding set_filter
[PROOF STATE]
proof (prove)
using this:
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<in> {x \<in> set [0..<n]. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, x)\<bar>}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ja \<in> set xs

goal (2 subgoals):
 1. D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have 1: "?reduce_b $$ (i,ja) = ?reduce_a $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
unfolding reduce_b_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
by (smt ab dc_eq dim_row_mat(1) dr_eq i ia index_mat(1) ja prod.simps(2)
                reduce_b_eq reduce_row_mod_D_preserves_dimensions_abs(2))
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (2 subgoals):
 1. D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
proof (cases "ja = 0 \<and> D dvd p*A$$(a,ja) + q*A$$(b,ja)")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)

goal (2 subgoals):
 1. ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "?reduce_a $$ (i,ja) = D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = D
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = D
[PROOF STEP]
using True ab a_or_b i_not_b ja_n im a A ja_in_xs False
[PROOF STATE]
proof (prove)
using this:
ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)
a \<noteq> b
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> b
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
ja \<in> set xs
\<not> (i \<noteq> a \<and> i \<noteq> b)

goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = D
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = D

goal (2 subgoals):
 1. ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = D

goal (2 subgoals):
 1. ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using True a_or_b i_not_b ja_n im A False ge_D
[PROOF STATE]
proof (prove)
using this:
ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> b
ja < n
i < m + n
A \<in> carrier_mat (m + n) n
\<not> (i \<noteq> a \<and> i \<noteq> b)
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>

goal (1 subgoal):
 1. D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
D = reduce_abs a b D A $$ (i, ja)

goal (2 subgoals):
 1. ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
using 1
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja))

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "?reduce_a $$ (i,ja) = ?A $$ (i, ja) gmod D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D
[PROOF STEP]
using True ab a_or_b i_not_b ja_n im a A ja_in_xs False
[PROOF STATE]
proof (prove)
using this:
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
a \<noteq> b
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> b
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
ja \<in> set xs
\<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja))

goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using True a_or_b i_not_b ja_n im A False
[PROOF STATE]
proof (prove)
using this:
D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> b
ja < n
i < m + n
A \<in> carrier_mat (m + n) n
\<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja))

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd p * A $$ (a, ja) + q * A $$ (b, ja)) \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
using 1
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have ja_in_xs: "ja \<notin> set xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<notin> set xs
[PROOF STEP]
unfolding xs_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<notin> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, i)\<bar>) [0..<n])
[PROOF STEP]
using False ja_n im a A
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<notin> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, i)\<bar>) [0..<n])
[PROOF STEP]
unfolding set_filter
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<notin> {x \<in> set [0..<n]. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (a, x)\<bar>}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ja \<notin> set xs

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "?reduce_b $$ (i,ja) = ?reduce_a $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
unfolding reduce_b_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
by (smt ab dc_eq dim_row_mat(1) dr_eq i ia index_mat(1) ja prod.simps(2)
                reduce_b_eq reduce_row_mod_D_preserves_dimensions_abs(2))
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = ?A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False ab a_or_b i_not_b ja_n im a A ja_in_xs
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
a \<noteq> b
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> b
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
ja \<notin> set xs

goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False a_or_b i_not_b ja_n im A
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar>
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> b
ja < n
i < m + n
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>p * A $$ (a, ja) + q * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
i \<noteq> a

goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
note i_not_a = False
[PROOF STATE]
proof (state)
this:
i \<noteq> a

goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have i_drb: "i<dim_row ?reduce_b"
          and i_dra: "i<dim_row ?reduce_a"
          and ja_drb: "ja < dim_col ?reduce_b"
          and ja_dra: "ja < dim_col ?reduce_a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (i < dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) &&& i < dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) &&& ja < dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) &&& ja < dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)
[PROOF STEP]
using reduce_carrier[OF A] i ja A dr_eq dc_eq
[PROOF STATE]
proof (prove)
using this:
reduce ?a ?b ?D A \<in> carrier_mat (m + n) n
reduce_abs ?a ?b ?D A \<in> carrier_mat (m + n) n
i < dim_row (reduce_abs a b D A)
ja < dim_col (reduce_abs a b D A)
A \<in> carrier_mat (m + n) n
dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_row (reduce_abs a b D A)
dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) = dim_col (reduce_abs a b D A)

goal (1 subgoal):
 1. (i < dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) &&& i < dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) &&& ja < dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m) &&& ja < dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
i < dim_row (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m)
i < dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)
ja < dim_col (reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m)
ja < dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)

goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have ib: "i=b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i = b
[PROOF STEP]
using False a_or_b
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
\<not> (i \<noteq> a \<and> i \<noteq> b)

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

goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
proof (cases "abs((u*A$$(a,ja) + v * A$$(b,ja))) > D")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
note ge_D = True
[PROOF STATE]
proof (state)
this:
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have ja_in_ys: "ja \<in> set ys"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<in> set ys
[PROOF STEP]
unfolding ys_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<in> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, i)\<bar>) [0..<n])
[PROOF STEP]
using True False ib ja_n im a b A
[PROOF STATE]
proof (prove)
using this:
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
i \<noteq> a
i = b
ja < n
i < m + n
a < m
b < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<in> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, i)\<bar>) [0..<n])
[PROOF STEP]
unfolding set_filter
[PROOF STATE]
proof (prove)
using this:
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
i \<noteq> a
i = b
ja < n
i < m + n
a < m
b < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<in> {x \<in> set [0..<n]. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, x)\<bar>}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ja \<in> set ys

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "?reduce_b $$ (i,ja) = (if ja = 0 \<and> D dvd ?reduce_a$$(i,ja) then D else ?reduce_a $$ (i, ja) gmod D)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)
[PROOF STEP]
unfolding reduce_b_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)
[PROOF STEP]
using i_not_a True  ja ja_in_ys
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
ja < dim_col (reduce_abs a b D A)
ja \<in> set ys

goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)
[PROOF STEP]
by (smt i_dra ja_dra a_or_b index_mat(1) prod.simps(2))
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (if ja = 0 \<and> D dvd ?reduce_a$$(i,ja) then D else ?A $$ (i, ja) gmod D)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D)
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) then D else Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) gmod D) = (if ja = 0 \<and> D dvd Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D)
[PROOF STEP]
using True ab a_or_b ib False ja_n im a A ja_in_ys
[PROOF STATE]
proof (prove)
using this:
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
a \<noteq> b
\<not> (i \<noteq> a \<and> i \<noteq> b)
i = b
i \<noteq> a
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
ja \<in> set ys

goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) then D else Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) gmod D) = (if ja = 0 \<and> D dvd Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D)

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D) = (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D)

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
proof (cases "ja = 0 \<and> D dvd ?reduce_a$$(i,ja)")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (2 subgoals):
 1. ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have ja0: "ja=0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja = 0
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

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

goal (2 subgoals):
 1. ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "u * A $$ (a, ja) + v * A $$ (b, ja) = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. u * A $$ (a, ja) + v * A $$ (b, ja) = 0
[PROOF STEP]
unfolding euclid_ext2_works[OF pquvd[symmetric]] ja0
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - A $$ (b, 0) div gcd (A $$ (a, 0)) (A $$ (b, 0)) * A $$ (a, 0) + A $$ (a, 0) div gcd (A $$ (a, 0)) (A $$ (b, 0)) * A $$ (b, 0) = 0
[PROOF STEP]
by (smt euclid_ext2_works[OF pquvd[symmetric]] more_arith_simps(11) mult.commute mult_minus_left)
[PROOF STATE]
proof (state)
this:
u * A $$ (a, ja) + v * A $$ (b, ja) = 0

goal (2 subgoals):
 1. ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
hence abs_0: "abs((u*A$$(a,ja) + v * A$$(b,ja))) = 0"
[PROOF STATE]
proof (prove)
using this:
u * A $$ (a, ja) + v * A $$ (b, ja) = 0

goal (1 subgoal):
 1. \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> = 0
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> = 0

goal (2 subgoals):
 1. ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
 2. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
using abs_0 D_ge0 ge_D
[PROOF STATE]
proof (prove)
using this:
\<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> = 0
0 < D
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>

goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
(if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))

goal (1 subgoal):
 1. \<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)) \<Longrightarrow> (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))

goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
using this:
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))

goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using True ge_D False a_or_b ib ja_n im A
[PROOF STATE]
proof (prove)
using this:
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))
\<not> (i \<noteq> a \<and> i \<noteq> b)
i = b
ja < n
i < m + n
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using i_not_a
[PROOF STATE]
proof (prove)
using this:
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
\<not> (ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja))
\<not> (i \<noteq> a \<and> i \<noteq> b)
i = b
ja < n
i < m + n
A \<in> carrier_mat (m + n) n
i \<noteq> a

goal (1 subgoal):
 1. (if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(if ja = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce_abs a b D A $$ (i, ja)

goal (2 subgoals):
 1. D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
 2. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have ja_in_ys: "ja \<notin> set ys"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<notin> set ys
[PROOF STEP]
unfolding ys_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<notin> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, i)\<bar>) [0..<n])
[PROOF STEP]
using i_not_a False ib ja_n im a b A
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
\<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
i = b
ja < n
i < m + n
a < m
b < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<notin> set (filter (\<lambda>i. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, i)\<bar>) [0..<n])
[PROOF STEP]
unfolding set_filter
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
\<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
i = b
ja < n
i < m + n
a < m
b < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<notin> {x \<in> set [0..<n]. D < \<bar>Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (b, x)\<bar>}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ja \<notin> set ys

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "?reduce_b $$ (i,ja) = ?reduce_a $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
unfolding reduce_b_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
using i_dra ja_dra ja_in_ys
[PROOF STATE]
proof (prove)
using this:
i < dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)
ja < dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)
ja \<notin> set ys

goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = b \<and> k \<in> set ys then if k = 0 \<and> D dvd reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = ?A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False ab a_or_b i_not_a ja_n im a A
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
a \<noteq> b
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> a
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. Matrix.mat (dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 \<and> D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) then D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k) gmod D else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = u * A $$ (a, ja) + v * A $$ (b, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (b, ja)
[PROOF STEP]
unfolding reduce_a_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (b, ja)
[PROOF STEP]
using False ab a_or_b i_not_a ja_n im a A ja_in_ys
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
a \<noteq> b
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> a
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
ja \<notin> set ys

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (b, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (b, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (b, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce_abs a b D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. u * A $$ (a, ja) + v * A $$ (b, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. u * A $$ (a, ja) + v * A $$ (b, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False a_or_b i_not_a ja_n im A
[PROOF STATE]
proof (prove)
using this:
\<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar>
\<not> (i \<noteq> a \<and> i \<noteq> b)
i \<noteq> a
ja < n
i < m + n
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. u * A $$ (a, ja) + v * A $$ (b, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (b, k) in if D < \<bar>r\<bar> then if k = 0 \<and> D dvd r then D else r gmod D else r else if i = b then let r = u * A $$ (a, k) + v * A $$ (b, k) in if D < \<bar>r\<bar> then r gmod D else r else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
u * A $$ (a, ja) + v * A $$ (b, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. \<not> D < \<bar>u * A $$ (a, ja) + v * A $$ (b, ja)\<bar> \<Longrightarrow> reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal (1 subgoal):
 1. reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m $$ (i, ja) = reduce_abs a b D A $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = reduce_abs a b D A

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have inv_QPBM: "invertible_mat (Q * P * ?BM)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. invertible_mat (Q * P * bezout_matrix_JNF A a b 0 euclid_ext2)
[PROOF STEP]
by (meson BM P Q inv_P inv_Q invertible_bezout invertible_mult_JNF mult_carrier_mat)
[PROOF STATE]
proof (state)
this:
invertible_mat (Q * P * bezout_matrix_JNF A a b 0 euclid_ext2)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
invertible_mat (Q * P * bezout_matrix_JNF A a b 0 euclid_ext2)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have "(Q*P*?BM) \<in> carrier_mat (m + n) (m + n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
[PROOF STEP]
using BM P Q
[PROOF STATE]
proof (prove)
using this:
bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
P \<in> carrier_mat (m + n) (m + n)
Q \<in> carrier_mat (m + n) (m + n)

goal (1 subgoal):
 1. Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
have "(reduce_abs a b D A) = (Q*P*?BM) * A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
have "?BM * A = ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bezout_matrix_JNF A a b 0 euclid_ext2 * A = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))
[PROOF STEP]
using A'_BZ_A
[PROOF STATE]
proof (prove)
using this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k)) = bezout_matrix_JNF A a b 0 euclid_ext2 * A

goal (1 subgoal):
 1. bezout_matrix_JNF A a b 0 euclid_ext2 * A = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
bezout_matrix_JNF A a b 0 euclid_ext2 * A = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))

goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
hence "P * (?BM * A) = ?reduce_a"
[PROOF STATE]
proof (prove)
using this:
bezout_matrix_JNF A a b 0 euclid_ext2 * A = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))

goal (1 subgoal):
 1. P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m
[PROOF STEP]
using reduce_a_PA
[PROOF STATE]
proof (prove)
using this:
bezout_matrix_JNF A a b 0 euclid_ext2 * A = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))
reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m = P * Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))

goal (1 subgoal):
 1. P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m

goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
hence "Q * (P * (?BM * A)) = ?reduce_b"
[PROOF STATE]
proof (prove)
using this:
P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m

goal (1 subgoal):
 1. Q * (P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A)) = reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m
[PROOF STEP]
using reduce_b_Q_reduce
[PROOF STATE]
proof (prove)
using this:
P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A) = reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = Q * reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m

goal (1 subgoal):
 1. Q * (P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A)) = reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Q * (P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A)) = reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m

goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
Q * (P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A)) = reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m

goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
using reduce_b_eq_reduce
[PROOF STATE]
proof (prove)
using this:
Q * (P * (bezout_matrix_JNF A a b 0 euclid_ext2 * A)) = reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m
reduce_row_mod_D_abs (reduce_row_mod_D_abs (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (b, k) else if i = b then u * A $$ (a, k) + v * A $$ (b, k) else A $$ (i, k))) a xs D m) b ys D m = reduce_abs a b D A

goal (1 subgoal):
 1. reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
by (smt A A'_BZ_A A_carrier BM P Q assoc_mult_mat mn mult_carrier_mat reduce_a_PA)
[PROOF STATE]
proof (state)
this:
reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
invertible_mat (Q * P * bezout_matrix_JNF A a b 0 euclid_ext2)
Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
invertible_mat (Q * P * bezout_matrix_JNF A a b 0 euclid_ext2)
Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
reduce_abs a b D A = Q * P * bezout_matrix_JNF A a b 0 euclid_ext2 * A

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce_abs a b D A = P * A

goal:
No subgoals!
[PROOF STEP]
qed