[STATEMENT]
lemma reduce_invertible_mat_case_m:
  assumes A': "A' \<in> carrier_mat m n" and B: "B \<in> carrier_mat n n"
    and a: "a<m" and ab: "a \<noteq> m"
  and A_def: "A = A' @\<^sub>r B"
    and j: "\<forall>j\<in>set xs. j<n \<and> (B $$ (j, j) = D) \<and> (\<forall>j'\<in>{0..<n}-{j}. B $$ (j, j') = 0)"
  and Aaj: "A $$ (a,0) \<noteq> 0"
  and mn: "m\<ge>n"
  and n0: "0<n"
  and pquvd: "(p,q,u,v,d) = euclid_ext2 (A$$(a,0)) (A$$(m,0))"
  and A2_def: "A2 = Matrix.mat (dim_row A) (dim_col A)
          (\<lambda>(i,k). if i = a then (p*A$$(a,k) + q*A$$(m,k))
                   else if i = m then u * A$$(a,k) + v * A$$(m,k)
                   else A$$(i,k)
            )"
  and xs_def: "xs = [1..<n]"
  and ys_def: "ys = [1..<n]"
    and j_ys: "\<forall>j\<in>set ys. j<n \<and> (B $$ (j, j) = D) \<and> (\<forall>j'\<in>{0..<n}-{j}. B $$ (j, j') = 0)"
    and D0: "D > 0"
  and Am0_D: "A $$ (m, 0) \<in> {0,D}"
  and Am0_D2: "A $$ (m, 0) = 0 \<longrightarrow> A $$ (a, 0) = D"
shows "\<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m+n) (m+n) \<and> (reduce a m D A) = P * A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m 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 a m 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$$(m,k))
                   else if i = m then u * A$$(a,k) + v * A$$(m,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 a m 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]
using mn
[PROOF STATE]
proof (prove)
using this:
n \<le> m

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 a m 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' B mn
[PROOF STATE]
proof (prove)
using this:
A = A' @\<^sub>r B
A' \<in> carrier_mat m n
B \<in> carrier_mat n n
n \<le> m

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 a m 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m D A = P * A
[PROOF STEP]
let ?BM = "bezout_matrix_JNF A a m 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 a m 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) = bezout_matrix_JNF A a m 0 euclid_ext2 * A
[PROOF STEP]
by (rule bezout_matrix_JNF_mult_eq[OF A' _ _ ab A_def B pquvd], insert a, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) = bezout_matrix_JNF A a m 0 euclid_ext2 * A

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m 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 m 0 euclid_ext2)
[PROOF STEP]
by (rule invertible_bezout_matrix_JNF[OF A is_bezout_ext_euclid_ext2 a _ _ Aaj], insert a n0, auto)
[PROOF STATE]
proof (state)
this:
invertible_mat (bezout_matrix_JNF A a m 0 euclid_ext2)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m 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 m 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 $$ (m, 0)) in if x = a \<and> y = a then p else if x = a \<and> y = m then q else if x = m \<and> y = a then u else if x = m \<and> y = m 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 $$ (m, 0)) in if x = a \<and> y = a then p else if x = a \<and> y = m then q else if x = m \<and> y = a then u else if x = m \<and> y = m 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 m 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 a m D A = P * A
[PROOF STEP]
let ?reduce_a = "reduce_row_mod_D ?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 a m D A = P * A
[PROOF STEP]
define A'1 where "A'1 = mat_of_rows n [Matrix.row ?A i. i \<leftarrow> [0..<m]]"
[PROOF STATE]
proof (state)
this:
A'1 = 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [0..<m])

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
define A'2 where "A'2 = mat_of_rows n [Matrix.row ?A i. i \<leftarrow> [m..<dim_row A]]"
[PROOF STATE]
proof (state)
this:
A'2 = 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A])

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have A_A'_D: "?A = A'1 @\<^sub>r A'2"
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) = A'1 @\<^sub>r A'2
[PROOF STEP]
using append_rows_split A
[PROOF STATE]
proof (prove)
using this:
?k \<le> dim_row ?A \<Longrightarrow> ?A = mat_of_rows (dim_col ?A) (map (row ?A) [0..<?k]) @\<^sub>r mat_of_rows (dim_col ?A) (map (row ?A) [?k..<dim_row ?A])
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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) = A'1 @\<^sub>r A'2
[PROOF STEP]
by (metis (no_types, lifting) A'1_def A'2_def A_carrier carrier_matD le_add1)
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) = A'1 @\<^sub>r A'2

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have j_A'1_A'2: "\<forall>j\<in>set xs. j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>j\<in>set xs. j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
proof (rule ballI)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
fix ja
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
assume ja: "ja\<in>set xs"
[PROOF STATE]
proof (state)
this:
ja \<in> set xs

goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
have ja_n: "ja < n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja < n
[PROOF STEP]
using ja
[PROOF STATE]
proof (prove)
using this:
ja \<in> set xs

goal (1 subgoal):
 1. ja < n
[PROOF STEP]
unfolding xs_def
[PROOF STATE]
proof (prove)
using this:
ja \<in> set [1..<n]

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

goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
have ja2: "ja < dim_row A - m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja < dim_row A - m
[PROOF STEP]
using A mn ja_n
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
n \<le> m
ja < n

goal (1 subgoal):
 1. ja < dim_row A - m
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
ja < dim_row A - m

goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
have ja_m: "ja < m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja < m
[PROOF STEP]
using ja_n mn
[PROOF STATE]
proof (prove)
using this:
ja < n
n \<le> m

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

goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
have ja_not_0: "ja \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja \<noteq> 0
[PROOF STEP]
using ja
[PROOF STATE]
proof (prove)
using this:
ja \<in> set xs

goal (1 subgoal):
 1. ja \<noteq> 0
[PROOF STEP]
unfolding xs_def
[PROOF STATE]
proof (prove)
using this:
ja \<in> set [1..<n]

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

goal (1 subgoal):
 1. \<And>j. j \<in> set xs \<Longrightarrow> j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)
[PROOF STEP]
show "ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "A'2 $$ (ja, ja) = [Matrix.row ?A i. i \<leftarrow> [m..<dim_row A]] ! ja $v ja"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A'2 $$ (ja, ja) = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v ja
[PROOF STEP]
by (metis (no_types, lifting) A A'2_def add_diff_cancel_left' carrier_matD(1)
              ja_n length_map length_upt mat_of_rows_index)
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, ja) = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v ja

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, ja) = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v ja

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "... = ?A $$ (m + ja, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v ja = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, ja)
[PROOF STEP]
using A mn ja_n
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
n \<le> m
ja < n

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

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v ja = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "... = A $$ (m+ja, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, ja) = A $$ (m + ja, ja)
[PROOF STEP]
using A a mn ja_n ja_not_0
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
a < m
n \<le> m
ja < n
ja \<noteq> 0

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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, ja) = A $$ (m + ja, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, ja) = A $$ (m + ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, ja) = A $$ (m + ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "... =  (A' @\<^sub>r B) $$ (m + ja, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (m + ja, ja) = (A' @\<^sub>r B) $$ (m + ja, ja)
[PROOF STEP]
unfolding A_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (A' @\<^sub>r B) $$ (m + ja, ja) = (A' @\<^sub>r B) $$ (m + ja, ja)
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
A $$ (m + ja, ja) = (A' @\<^sub>r B) $$ (m + ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A $$ (m + ja, ja) = (A' @\<^sub>r B) $$ (m + ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "... = B $$ (ja, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (A' @\<^sub>r B) $$ (m + ja, ja) = B $$ (ja, ja)
[PROOF STEP]
by (metis B Groups.add_ac(2) append_rows_nth2 assms(1) ja_n mn nat_SN.compat)
[PROOF STATE]
proof (state)
this:
(A' @\<^sub>r B) $$ (m + ja, ja) = B $$ (ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(A' @\<^sub>r B) $$ (m + ja, ja) = B $$ (ja, ja)

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "... = D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B $$ (ja, ja) = D
[PROOF STEP]
using j ja
[PROOF STATE]
proof (prove)
using this:
\<forall>j\<in>set xs. j < n \<and> B $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. B $$ (j, j') = 0)
ja \<in> set xs

goal (1 subgoal):
 1. B $$ (ja, ja) = D
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
B $$ (ja, ja) = D

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
A'2 $$ (ja, ja) = D
[PROOF STEP]
have A2_D: "A'2 $$ (ja, ja) = D"
[PROOF STATE]
proof (prove)
using this:
A'2 $$ (ja, ja) = D

goal (1 subgoal):
 1. A'2 $$ (ja, ja) = D
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, ja) = D

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, ja) = D

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
have "(\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0
[PROOF STEP]
proof (rule ballI)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
fix j'
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
assume j': "j': {0..<n} - {ja}"
[PROOF STATE]
proof (state)
this:
j' \<in> {0..<n} - {ja}

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
have "A'2 $$ (ja, j') = [Matrix.row ?A i. i \<leftarrow> [m..<dim_row A]] ! ja $v j'"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A'2 $$ (ja, j') = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v j'
[PROOF STEP]
unfolding A'2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A]) $$ (ja, j') = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v j'
[PROOF STEP]
by (rule mat_of_rows_index, insert j' ja_n ja2, auto)
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, j') = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v j'

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, j') = map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v j'

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
have "... = ?A $$ (m + ja, j')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v j' = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, j')
[PROOF STEP]
using A mn ja_n j'
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
n \<le> m
ja < n
j' \<in> {0..<n} - {ja}

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

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
map (row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A] ! ja $v j' = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
have "... = A $$ (m+ja, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, j') = A $$ (m + ja, j')
[PROOF STEP]
using A a mn ja_n ja_not_0 j'
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
a < m
n \<le> m
ja < n
ja \<noteq> 0
j' \<in> {0..<n} - {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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, j') = A $$ (m + ja, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, j') = A $$ (m + ja, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m + ja, j') = A $$ (m + ja, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
have "... =  (A' @\<^sub>r B) $$ (ja + m, j')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (m + ja, j') = (A' @\<^sub>r B) $$ (ja + m, j')
[PROOF STEP]
unfolding A_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (A' @\<^sub>r B) $$ (m + ja, j') = (A' @\<^sub>r B) $$ (ja + m, j')
[PROOF STEP]
by (simp add: add.commute)
[PROOF STATE]
proof (state)
this:
A $$ (m + ja, j') = (A' @\<^sub>r B) $$ (ja + m, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A $$ (m + ja, j') = (A' @\<^sub>r B) $$ (ja + m, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
have "... = B $$ (ja, j')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (A' @\<^sub>r B) $$ (ja + m, j') = B $$ (ja, j')
[PROOF STEP]
by (rule append_rows_nth2[OF A' B _ ja_m ja_n], insert j', auto)
[PROOF STATE]
proof (state)
this:
(A' @\<^sub>r B) $$ (ja + m, j') = B $$ (ja, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(A' @\<^sub>r B) $$ (ja + m, j') = B $$ (ja, j')

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
have "... = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B $$ (ja, j') = 0
[PROOF STEP]
using mn j' ja_n j ja
[PROOF STATE]
proof (prove)
using this:
n \<le> m
j' \<in> {0..<n} - {ja}
ja < n
\<forall>j\<in>set xs. j < n \<and> B $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. B $$ (j, j') = 0)
ja \<in> set xs

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

goal (1 subgoal):
 1. \<And>j'. j' \<in> {0..<n} - {ja} \<Longrightarrow> A'2 $$ (ja, j') = 0
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
A'2 $$ (ja, j') = 0
[PROOF STEP]
show "A'2 $$ (ja, j') = 0"
[PROOF STATE]
proof (prove)
using this:
A'2 $$ (ja, j') = 0

goal (1 subgoal):
 1. A'2 $$ (ja, j') = 0
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
A'2 $$ (ja, j') = 0

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
A'2 $$ (ja, ja) = D
\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
A'2 $$ (ja, ja) = D
\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
using ja_n
[PROOF STATE]
proof (prove)
using this:
A'2 $$ (ja, ja) = D
\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0
ja < n

goal (1 subgoal):
 1. ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
ja < n \<and> A'2 $$ (ja, ja) = D \<and> (\<forall>j'\<in>{0..<n} - {ja}. A'2 $$ (ja, j') = 0)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<forall>j\<in>set xs. j < n \<and> A'2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. A'2 $$ (j, j') = 0)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m 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 then if D dvd ?A $$ (i, k) then D
    else ?A $$ (i, k) else ?A $$ (i, k) gmod D else ?A $$ (i, k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k))
[PROOF STEP]
proof (rule reduce_row_mod_D_case_m'[OF A_A'_D _ _ a j_A'1_A'2 _ mn D0])
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. A'2 \<in> carrier_mat n n
 2. A'1 \<in> carrier_mat m n
 3. distinct xs
[PROOF STEP]
show "A'2 \<in> carrier_mat n n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A'2 \<in> carrier_mat n n
[PROOF STEP]
using A A'2_def
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
A'2 = 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) [m..<dim_row A])

goal (1 subgoal):
 1. A'2 \<in> carrier_mat n n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A'2 \<in> carrier_mat n n

goal (2 subgoals):
 1. A'1 \<in> carrier_mat m n
 2. distinct xs
[PROOF STEP]
show "A'1 \<in> carrier_mat m n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A'1 \<in> carrier_mat m n
[PROOF STEP]
by (simp add: A'1_def mat_of_rows_def)
[PROOF STATE]
proof (state)
this:
A'1 \<in> carrier_mat m n

goal (1 subgoal):
 1. distinct xs
[PROOF STEP]
show "distinct xs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. distinct xs
[PROOF STEP]
using distinct_filter distinct_upt xs_def
[PROOF STATE]
proof (prove)
using this:
distinct ?xs \<Longrightarrow> distinct (filter ?P ?xs)
distinct [?i..<?j]
xs = [1..<n]

goal (1 subgoal):
 1. distinct xs
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
distinct xs

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k))
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))
[PROOF STEP]
by (rule reduce_row_mod_D_invertible_mat_case_m[OF A_A'_D _ _ _ j_A'1_A'2 mn],
        insert a A A'2_def A'1_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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m D A = P * A
[PROOF STEP]
let ?reduce_b = "reduce_row_mod_D ?reduce_a m 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 a m 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 a m D A = P * A
[PROOF STEP]
define reduce_a1 where "reduce_a1 = mat_of_rows (dim_col ?reduce_a) [Matrix.row ?reduce_a i. i \<leftarrow> [0..<m]]"
[PROOF STATE]
proof (state)
this:
reduce_a1 = mat_of_rows (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (map (row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) [0..<m])

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
define reduce_a2 where "reduce_a2 = mat_of_rows (dim_col ?reduce_a) [Matrix.row ?reduce_a i. i \<leftarrow> [m..<dim_row ?reduce_a]]"
[PROOF STATE]
proof (state)
this:
reduce_a2 = mat_of_rows (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (map (row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) [m..<dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m D A = P * A
[PROOF STEP]
have reduce_a_split: "?reduce_a = reduce_a1 @\<^sub>r reduce_a2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m = reduce_a1 @\<^sub>r reduce_a2
[PROOF STEP]
by (unfold reduce_a1_def reduce_a2_def, rule append_rows_split, insert mn A, auto)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m = reduce_a1 @\<^sub>r reduce_a2

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have zero_notin_ys: "0 \<notin> set ys"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<notin> set ys
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. 0 \<notin> set ys
[PROOF STEP]
have m: "m<dim_row A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. m < dim_row A
[PROOF STEP]
using A n0
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
0 < n

goal (1 subgoal):
 1. m < dim_row A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
m < dim_row A

goal (1 subgoal):
 1. 0 \<notin> set ys
[PROOF STEP]
have "?A $$ (m,0) =  u * A $$ (a, 0) + v * A $$ (m, 0)"
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = u * A $$ (a, 0) + v * A $$ (m, 0)
[PROOF STEP]
using m n0 a A
[PROOF STATE]
proof (prove)
using this:
m < dim_row A
0 < n
a < m
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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = u * A $$ (a, 0) + v * A $$ (m, 0)
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = u * A $$ (a, 0) + v * A $$ (m, 0)

goal (1 subgoal):
 1. 0 \<notin> set ys
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = u * A $$ (a, 0) + v * A $$ (m, 0)

goal (1 subgoal):
 1. 0 \<notin> set ys
[PROOF STEP]
have "... = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. u * A $$ (a, 0) + v * A $$ (m, 0) = 0
[PROOF STEP]
using pquvd
[PROOF STATE]
proof (prove)
using this:
(p, q, u, v, d) = euclid_ext2 (A $$ (a, 0)) (A $$ (m, 0))

goal (1 subgoal):
 1. u * A $$ (a, 0) + v * A $$ (m, 0) = 0
[PROOF STEP]
by (smt dvd_mult_div_cancel euclid_ext2_def euclid_ext2_works(3) more_arith_simps(11)
          mult.commute mult_minus_left prod.sel(1) prod.sel(2) semiring_gcd_class.gcd_dvd1)
[PROOF STATE]
proof (state)
this:
u * A $$ (a, 0) + v * A $$ (m, 0) = 0

goal (1 subgoal):
 1. 0 \<notin> set ys
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = 0
[PROOF STEP]
show ?thesis
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = 0

goal (1 subgoal):
 1. 0 \<notin> set ys
[PROOF STEP]
using D0
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = 0
0 < D

goal (1 subgoal):
 1. 0 \<notin> set ys
[PROOF STEP]
unfolding ys_def
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (m, 0) = 0
0 < D

goal (1 subgoal):
 1. 0 \<notin> set [1..<n]
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
0 \<notin> set ys

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
0 \<notin> set ys

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have reduce_a2: "reduce_a2 \<in> carrier_mat n n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_a2 \<in> carrier_mat n n
[PROOF STEP]
unfolding reduce_a2_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat_of_rows (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (map (row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) [m..<dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)]) \<in> carrier_mat n n
[PROOF STEP]
using A
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. mat_of_rows (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (map (row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) [m..<dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)]) \<in> carrier_mat n n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_a2 \<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 a m D A = P * A
[PROOF STEP]
have reduce_a1: "reduce_a1 \<in> carrier_mat m n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_a1 \<in> carrier_mat m n
[PROOF STEP]
unfolding reduce_a1_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat_of_rows (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (map (row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) [0..<m]) \<in> carrier_mat m n
[PROOF STEP]
using A
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n

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

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have j2: "\<forall>j\<in>set ys. j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>j\<in>set ys. j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
fix j
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
assume j_in_ys: "j \<in> set ys"
[PROOF STATE]
proof (state)
this:
j \<in> set ys

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have a_jm: "a \<noteq> j+m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a \<noteq> j + m
[PROOF STEP]
using a
[PROOF STATE]
proof (prove)
using this:
a < m

goal (1 subgoal):
 1. a \<noteq> j + m
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
a \<noteq> j + m

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have m_not_jm: "m \<noteq> j + m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. m \<noteq> j + m
[PROOF STEP]
using zero_notin_ys j_in_ys
[PROOF STATE]
proof (prove)
using this:
0 \<notin> set ys
j \<in> set ys

goal (1 subgoal):
 1. m \<noteq> j + m
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
m \<noteq> j + m

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have jm: "j+m < dim_row ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j + m < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))
[PROOF STEP]
using A_carrier j_in_ys
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set ys

goal (1 subgoal):
 1. j + m < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))
[PROOF STEP]
unfolding ys_def
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set [1..<n]

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

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have jn: "j < dim_col ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))
[PROOF STEP]
using A_carrier j_in_ys
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set ys

goal (1 subgoal):
 1. j < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))
[PROOF STEP]
unfolding ys_def
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set [1..<n]

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

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have jm': "j+m < dim_row A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j + m < dim_row A
[PROOF STEP]
using A_carrier j_in_ys
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set ys

goal (1 subgoal):
 1. j + m < dim_row A
[PROOF STEP]
unfolding ys_def
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set [1..<n]

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

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have jn': "j < dim_col A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j < dim_col A
[PROOF STEP]
using A_carrier j_in_ys
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set ys

goal (1 subgoal):
 1. j < dim_col A
[PROOF STEP]
unfolding ys_def
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n
j \<in> set [1..<n]

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

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
have "reduce_a2 $$ (j, j') = B $$ (j,j')" if j': "j'<n" for j'
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
have "reduce_a2 $$ (j, j') = ?reduce_a $$ (j+m,j')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (j + m, j')
[PROOF STEP]
by (rule append_rows_nth2[symmetric, OF reduce_a1 reduce_a2 reduce_a_split],
            insert j_in_ys mn j', auto simp add: ys_def)
[PROOF STATE]
proof (state)
this:
reduce_a2 $$ (j, j') = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (j + m, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_a2 $$ (j, j') = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (j + m, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
have "... = ?A $$ (j+m, j')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (j + m, j') = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (j + m, j')
[PROOF STEP]
using reduce_a_eq jm jn a_jm j' A_carrier
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k))
j + m < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))
j < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))
a \<noteq> j + m
j' < n
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<in> carrier_mat (m + n) n

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

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (j + m, j') = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (j + m, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
have "... = A $$ (j+m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (j + m, j') = A $$ (j + m, j')
[PROOF STEP]
using a_jm m_not_jm jm' jn' j' A_carrier
[PROOF STATE]
proof (prove)
using this:
a \<noteq> j + m
m \<noteq> j + m
j + m < dim_row A
j < dim_col A
j' < n
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) \<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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (j + m, j') = A $$ (j + m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (j + m, j') = A $$ (j + m, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (j + m, j') = A $$ (j + m, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
have "... = B $$ (j,j')"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (j + m, j') = B $$ (j, j')
[PROOF STEP]
by (smt A append_rows_nth2 A' B A_def mn carrier_matD(2) jn' le_Suc_ex that trans_less_add1)
[PROOF STATE]
proof (state)
this:
A $$ (j + m, j') = B $$ (j, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_a2 $$ (j, j') = B $$ (j, j')

goal (1 subgoal):
 1. reduce_a2 $$ (j, j') = B $$ (j, j')
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_a2 $$ (j, j') = B $$ (j, j')

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?j' < n \<Longrightarrow> reduce_a2 $$ (j, ?j') = B $$ (j, ?j')

goal (1 subgoal):
 1. \<And>j. j \<in> set ys \<Longrightarrow> j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
thus "j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)"
[PROOF STATE]
proof (prove)
using this:
?j' < n \<Longrightarrow> reduce_a2 $$ (j, ?j') = B $$ (j, ?j')

goal (1 subgoal):
 1. j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
using j_ys j_in_ys
[PROOF STATE]
proof (prove)
using this:
?j' < n \<Longrightarrow> reduce_a2 $$ (j, ?j') = B $$ (j, ?j')
\<forall>j\<in>set ys. j < n \<and> B $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. B $$ (j, j') = 0)
j \<in> set ys

goal (1 subgoal):
 1. j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<forall>j\<in>set ys. j < n \<and> reduce_a2 $$ (j, j) = D \<and> (\<forall>j'\<in>{0..<n} - {j}. reduce_a2 $$ (j, j') = 0)

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m 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 = m \<and> k \<in> set ys then if k = 0 then if D dvd ?reduce_a $$ (i, k) then D
      else ?reduce_a $$ (i, k) else ?reduce_a $$ (i, k) gmod D else ?reduce_a $$ (i, k))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = Matrix.mat (dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = m \<and> k \<in> set ys then if k = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k))
[PROOF STEP]
by (rule reduce_row_mod_D_case_m''[OF reduce_a_split reduce_a2 reduce_a1 _ j2 _ mn zero_notin_ys],
        insert D0, auto simp add: ys_def)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = Matrix.mat (dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = m \<and> k \<in> set ys then if k = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = P * reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m
[PROOF STEP]
by (rule reduce_row_mod_D_invertible_mat_case_m'[OF reduce_a_split reduce_a2 reduce_a1 _ j2 _ mn zero_notin_ys],
        auto simp add: ys_def)
[PROOF STATE]
proof (state)
this:
\<exists>P. P \<in> carrier_mat (m + n) (m + n) \<and> invertible_mat P \<and> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = P * reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = P * reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = P * reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = Q * reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = Q * reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 a m D A = P * A
[PROOF STEP]
have reduce_b_eq_reduce: "?reduce_b = (reduce a m D A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = reduce a m D A
[PROOF STEP]
proof (rule eq_matI)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>i j. \<lbrakk>i < dim_row (reduce a m D A); j < dim_col (reduce a m D A)\<rbrakk> \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, j) = reduce a m D A $$ (i, j)
 2. dim_row (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_row (reduce a m D A)
 3. dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_col (reduce a m D A)
[PROOF STEP]
show dr_eq: "dim_row ?reduce_b = dim_row (reduce a m D A)"
      and dc_eq: "dim_col ?reduce_b = dim_col (reduce a m D A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. dim_row (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_row (reduce a m D A) &&& dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_col (reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_row (reduce a m D A) &&& dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_col (reduce a m D A)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
dim_row (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_row (reduce a m D A)
dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) = dim_col (reduce a m D A)

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

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

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> m \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = m \<and> k \<in> set ys then if k = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja)

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

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> m \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "... = ?A $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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(1) split_conv)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja)

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

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> m \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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> m
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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> m \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja)

goal (2 subgoals):
 1. i \<noteq> a \<and> i \<noteq> m \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce a m D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) = reduce a m 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 $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D 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> m

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 $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) = reduce a m D A $$ (i, ja)

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

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

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

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

goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have gcd_pq: "p * A $$ (a, 0) + q * A $$ (m, 0) = gcd (A $$ (a, 0)) (A $$ (m, 0))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. p * A $$ (a, 0) + q * A $$ (m, 0) = gcd (A $$ (a, 0)) (A $$ (m, 0))
[PROOF STEP]
by (metis assms(10) euclid_ext2_works(1) euclid_ext2_works(2))
[PROOF STATE]
proof (state)
this:
p * A $$ (a, 0) + q * A $$ (m, 0) = gcd (A $$ (a, 0)) (A $$ (m, 0))

goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have gcd_le_D: "gcd (A $$ (a, 0)) (A $$ (m, 0)) \<le> D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. gcd (A $$ (a, 0)) (A $$ (m, 0)) \<le> D
[PROOF STEP]
by (metis Am0_D D0 assms(17) empty_iff gcd_le1_int gcd_le2_int insert_iff)
[PROOF STATE]
proof (state)
this:
gcd (A $$ (a, 0)) (A $$ (m, 0)) \<le> D

goal (1 subgoal):
 1. \<not> (i \<noteq> a \<and> i \<noteq> m) \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
hence i_not_b: "i\<noteq>m"
[PROOF STATE]
proof (prove)
using this:
i = a

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

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

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = m \<and> k \<in> set ys then if k = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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(2))
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja)

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

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

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

goal (1 subgoal):
 1. ja \<notin> set xs
[PROOF STEP]
unfolding xs_def
[PROOF STATE]
proof (prove)
using this:
ja = 0

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

goal (2 subgoals):
 1. ja = 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "?reduce_a $$ (i,ja) = p * A $$ (a, 0) + q * A $$ (m, 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) = p * A $$ (a, 0) + q * A $$ (m, 0)
[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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = p * A $$ (a, 0) + q * A $$ (m, 0)
[PROOF STEP]
using True ja0 ab a_or_b i_not_b ja_n im a A False ja_notin_xs
[PROOF STATE]
proof (prove)
using this:
ja = 0
ja = 0
a \<noteq> m
\<not> (i \<noteq> a \<and> i \<noteq> m)
i \<noteq> m
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
\<not> (i \<noteq> a \<and> i \<noteq> m)
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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) = p * A $$ (a, 0) + q * A $$ (m, 0)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) = p * A $$ (a, 0) + q * A $$ (m, 0)

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

goal (2 subgoals):
 1. ja = 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce a m D A) $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. p * A $$ (a, 0) + q * A $$ (m, 0) = reduce a m D A $$ (i, ja)
[PROOF STEP]
unfolding reduce_alt_def_not0[OF Aaj pquvd]
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. p * A $$ (a, 0) + q * A $$ (m, 0) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D 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:
ja = 0
\<not> (i \<noteq> a \<and> i \<noteq> m)
i \<noteq> m
ja < n
i < m + n
A \<in> carrier_mat (m + n) n
\<not> (i \<noteq> a \<and> i \<noteq> m)

goal (1 subgoal):
 1. p * A $$ (a, 0) + q * A $$ (m, 0) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then let r = p * A $$ (a, k) + q * A $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using gcd_le_D gcd_pq Am0_D Am0_D2
[PROOF STATE]
proof (prove)
using this:
ja = 0
\<not> (i \<noteq> a \<and> i \<noteq> m)
i \<noteq> m
ja < n
i < m + n
A \<in> carrier_mat (m + n) n
\<not> (i \<noteq> a \<and> i \<noteq> m)
gcd (A $$ (a, 0)) (A $$ (m, 0)) \<le> D
p * A $$ (a, 0) + q * A $$ (m, 0) = gcd (A $$ (a, 0)) (A $$ (m, 0))
A $$ (m, 0) \<in> {0, D}
A $$ (m, 0) = 0 \<longrightarrow> A $$ (a, 0) = D

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

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

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

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

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

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
hence ja_in_xs: "ja \<in> set xs"
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> 0

goal (1 subgoal):
 1. ja \<in> set xs
[PROOF STEP]
unfolding xs_def
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> 0

goal (1 subgoal):
 1. ja \<in> set [1..<n]
[PROOF STEP]
using True ja_n im a A
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> 0
i = a
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<in> set [1..<n]
[PROOF STEP]
unfolding set_filter
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> 0
i = a
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

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

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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:
i = a
a \<noteq> m
\<not> (i \<noteq> a \<and> i \<noteq> m)
i \<noteq> m
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n
ja \<in> set xs
ja \<noteq> 0

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

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "... = (reduce a m 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D = reduce a m 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D 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:
i = a
\<not> (i \<noteq> a \<and> i \<noteq> m)
i \<noteq> m
ja < n
i < m + n
A \<in> carrier_mat (m + n) n
ja \<noteq> 0

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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D = reduce a m D A $$ (i, ja)

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

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

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

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

goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i \<noteq> a \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) &&& i < dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) &&& ja < dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) &&& ja < dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)
[PROOF STEP]
using i ja reduce_carrier[OF A] A ja_n im
[PROOF STATE]
proof (prove)
using this:
i < dim_row (reduce a m D A)
ja < dim_col (reduce a m D A)
reduce ?a ?b ?D A \<in> carrier_mat (m + n) n
reduce_abs ?a ?b ?D A \<in> carrier_mat (m + n) n
A \<in> carrier_mat (m + n) n
ja < n
i < m + n

goal (1 subgoal):
 1. (i < dim_row (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) &&& i < dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) &&& ja < dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m) &&& ja < dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m)
i < dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)
ja < dim_col (reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m)
ja < dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)

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

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

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

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

goal (2 subgoals):
 1. ja = 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have uv: "u * A $$ (a, ja) + v * A $$ (m, ja) = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. u * A $$ (a, ja) + v * A $$ (m, ja) = 0
[PROOF STEP]
unfolding euclid_ext2_works[OF pquvd[symmetric]] True
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. - A $$ (m, 0) div gcd (A $$ (a, 0)) (A $$ (m, 0)) * A $$ (a, 0) + A $$ (a, 0) div gcd (A $$ (a, 0)) (A $$ (m, 0)) * A $$ (m, 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 $$ (m, ja) = 0

goal (2 subgoals):
 1. ja = 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
 2. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "?reduce_b $$ (i,ja) = u * A $$ (a, ja) + v * A $$ (m, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (m, ja)
[PROOF STEP]
by (smt (z3) A A_carrier True assms(4) carrier_matD i ib index_mat(1) reduce_a_eq
                ja_dra old.prod.case reduce_preserves_dimensions(1) zero_notin_ys reduce_b_eq
                reduce_row_mod_D_preserves_dimensions)
[PROOF STATE]
proof (state)
this:
reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = u * A $$ (a, ja) + v * A $$ (m, ja)

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

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

goal (1 subgoal):
 1. u * A $$ (a, ja) + v * A $$ (m, ja) = 0
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
u * A $$ (a, ja) + v * A $$ (m, ja) = 0

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

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

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

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

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

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

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

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m 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 [1..<n]
[PROOF STEP]
using False ib ja_n im a  A
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> 0
i = m
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

goal (1 subgoal):
 1. ja \<in> set [1..<n]
[PROOF STEP]
unfolding set_filter
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> 0
i = m
ja < n
i < m + n
a < m
A \<in> carrier_mat (m + n) n

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

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "?reduce_b $$ (i,ja) = (if ja = 0 then if D dvd ?reduce_a$$(i,ja) then D
                                  else ?reduce_a $$ (i, ja) else ?reduce_a $$ (i, ja) gmod D)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = m \<and> k \<in> set ys then if k = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)
[PROOF STEP]
using i_not_a  ja ja_in_ys
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
ja < dim_col (reduce a m D A)
ja \<in> set ys

goal (1 subgoal):
 1. Matrix.mat (dim_row (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (dim_col (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m)) (\<lambda>(i, k). if i = m \<and> k \<in> set ys then if k = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k) gmod D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, k)) $$ (i, ja) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D)

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

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
have "... = (if ja = 0 then if D dvd ?reduce_a$$(i,ja) then D
                            else ?A $$ (i, ja) else ?A $$ (i, ja) gmod D)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 then if 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) gmod D) = (if ja = 0 then if 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D)
[PROOF STEP]
using ab a_or_b ib False ja_n im a A ja_in_ys
[PROOF STATE]
proof (prove)
using this:
a \<noteq> m
\<not> (i \<noteq> a \<and> i \<noteq> m)
i = m
ja \<noteq> 0
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 then if 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k)) $$ (i, ja) gmod D) = (if ja = 0 then if 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D)

goal (1 subgoal):
 1. ja \<noteq> 0 \<Longrightarrow> reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m $$ (i, ja) = reduce a m D A $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) then D else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) else reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m $$ (i, ja) gmod D) = (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D)

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

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

goal (1 subgoal):
 1. (if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) in if k = 0 then if D dvd r then D else r else r gmod D else if i = m then let r = u * A $$ (a, k) + v * A $$ (m, k) in if k = 0 then r else r gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if ja = 0 then if D dvd reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, ja) gmod D) = reduce a m D A $$ (i, ja)

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

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

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

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

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

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

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have r: "?reduce_a = (P*?BM) * A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m = P * bezout_matrix_JNF A a m 0 euclid_ext2 * A
[PROOF STEP]
using A A'_BZ_A BM P reduce_a_PA
[PROOF STATE]
proof (prove)
using this:
A \<in> carrier_mat (m + n) n
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) = bezout_matrix_JNF A a m 0 euclid_ext2 * A
bezout_matrix_JNF A a m 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
P \<in> carrier_mat (m + n) (m + n)
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))

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

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have "Q * P * ?BM : carrier_mat (m+n) (m+n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Q * P * bezout_matrix_JNF A a m 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
[PROOF STEP]
using P BM Q
[PROOF STATE]
proof (prove)
using this:
P \<in> carrier_mat (m + n) (m + n)
bezout_matrix_JNF A a m 0 euclid_ext2 \<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 m 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 m 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 a m D A = P * A
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
Q * P * bezout_matrix_JNF A a m 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 a m D A = P * A
[PROOF STEP]
have "invertible_mat (Q * P*?BM)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. invertible_mat (Q * P * bezout_matrix_JNF A a m 0 euclid_ext2)
[PROOF STEP]
using inv_P invertible_bezout BM P invertible_mult_JNF inv_Q Q
[PROOF STATE]
proof (prove)
using this:
invertible_mat P
invertible_mat (bezout_matrix_JNF A a m 0 euclid_ext2)
bezout_matrix_JNF A a m 0 euclid_ext2 \<in> carrier_mat (m + n) (m + n)
P \<in> carrier_mat (m + n) (m + n)
\<lbrakk>?A \<in> carrier_mat ?n ?n; ?B \<in> carrier_mat ?n ?n; invertible_mat ?A; invertible_mat ?B\<rbrakk> \<Longrightarrow> invertible_mat (?A * ?B)
invertible_mat Q
Q \<in> carrier_mat (m + n) (m + n)

goal (1 subgoal):
 1. invertible_mat (Q * P * bezout_matrix_JNF A a m 0 euclid_ext2)
[PROOF STEP]
by (metis mult_carrier_mat)
[PROOF STATE]
proof (state)
this:
invertible_mat (Q * P * bezout_matrix_JNF A a m 0 euclid_ext2)

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

goal (1 subgoal):
 1. \<exists>P. invertible_mat P \<and> P \<in> carrier_mat (m + n) (m + n) \<and> reduce a m D A = P * A
[PROOF STEP]
have "(reduce a m D A) = (Q * P * ?BM) * A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce a m D A = Q * P * bezout_matrix_JNF A a m 0 euclid_ext2 * A
[PROOF STEP]
using reduce_a_eq r reduce_b_eq_reduce
[PROOF STATE]
proof (prove)
using this:
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)))) (\<lambda>(i, k). if i = a \<and> k \<in> set xs then if k = 0 then if D dvd Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k) else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, 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 $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k)) $$ (i, k))
reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m = P * bezout_matrix_JNF A a m 0 euclid_ext2 * A
reduce_row_mod_D (reduce_row_mod_D (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a then p * A $$ (a, k) + q * A $$ (m, k) else if i = m then u * A $$ (a, k) + v * A $$ (m, k) else A $$ (i, k))) a xs D m) m ys D m = reduce a m D A

goal (1 subgoal):
 1. reduce a m D A = Q * P * bezout_matrix_JNF A a m 0 euclid_ext2 * A
[PROOF STEP]
by (smt BM P Q assoc_mult_mat carrier_matD carrier_mat_triv
        dim_row_mat(1) index_mult_mat(2,3) reduce_b_Q_reduce)
[PROOF STATE]
proof (state)
this:
reduce a m D A = Q * P * bezout_matrix_JNF A a m 0 euclid_ext2 * A

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

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

goal:
No subgoals!
[PROOF STEP]
qed