[STATEMENT]
lemma step_push_size_new_big [simp]: "\<lbrakk>
  invar (States dir big small);
  step (States dir (Big.push x big) small) = States dir' big' small'
\<rbrakk> \<Longrightarrow> size_new big' = Suc (size_new big)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>invar (States dir big small); step (States dir (Big.push x big) small) = States dir' big' small'\<rbrakk> \<Longrightarrow> size_new big' = Suc (size_new big)
[PROOF STEP]
using
    invar_push_big[of dir big small x]
    step_size_new_big[of dir "Big.push x big" small dir' big' small']
    Big_Proof.size_new_push[of big x]
[PROOF STATE]
proof (prove)
using this:
invar (States dir big small) \<Longrightarrow> invar (States dir (Big.push x big) small)
\<lbrakk>invar (States dir (Big.push x big) small); step (States dir (Big.push x big) small) = States dir' big' small'\<rbrakk> \<Longrightarrow> size_new big' = size_new (Big.push x big)
invar big \<Longrightarrow> size_new (Big.push x big) = Suc (size_new big)

goal (1 subgoal):
 1. \<lbrakk>invar (States dir big small); step (States dir (Big.push x big) small) = States dir' big' small'\<rbrakk> \<Longrightarrow> size_new big' = Suc (size_new big)
[PROOF STEP]
by simp


[STATEMENT]
lemma (in prob_space) nn_integral_stream_space:
  assumes [measurable]: "f \<in> borel_measurable (stream_space M)"
  shows "(\<integral>\<^sup>+X. f X \<partial>stream_space M) = (\<integral>\<^sup>+x. (\<integral>\<^sup>+X. f (x ## X) \<partial>stream_space M) \<partial>M)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
interpret S: sequence_space M
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sequence_space M
[PROOF STEP]
..
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
interpret P: pair_sigma_finite M "\<Pi>\<^sub>M i::nat\<in>UNIV. M"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pair_sigma_finite M (Pi\<^sub>M UNIV (\<lambda>i. M))
[PROOF STEP]
..
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
have "(\<integral>\<^sup>+X. f X \<partial>stream_space M) = (\<integral>\<^sup>+X. f (to_stream X) \<partial>S.S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ X. f (to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M)
[PROOF STEP]
by (subst stream_space_eq_distr) (simp add: nn_integral_distr)
[PROOF STATE]
proof (state)
this:
integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ X. f (to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M)

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ X. f (to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M)

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
have "\<dots> = (\<integral>\<^sup>+X. f (to_stream ((\<lambda>(s, \<omega>). case_nat s \<omega>) X)) \<partial>(M \<Otimes>\<^sub>M S.S))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+ X. f (to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) = \<integral>\<^sup>+ X. f (to_stream (case X of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>M \<Otimes>\<^sub>M Pi\<^sub>M UNIV (\<lambda>i. M)
[PROOF STEP]
by (subst S.PiM_iter[symmetric]) (simp add: nn_integral_distr)
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ X. f (to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) = \<integral>\<^sup>+ X. f (to_stream (case X of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>M \<Otimes>\<^sub>M Pi\<^sub>M UNIV (\<lambda>i. M)

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ X. f (to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) = \<integral>\<^sup>+ X. f (to_stream (case X of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>M \<Otimes>\<^sub>M Pi\<^sub>M UNIV (\<lambda>i. M)

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+X. f (to_stream ((\<lambda>(s, \<omega>). case_nat s \<omega>) (x, X))) \<partial>S.S \<partial>M)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+ X. f (to_stream (case X of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>M \<Otimes>\<^sub>M Pi\<^sub>M UNIV (\<lambda>i. M) = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (to_stream (case (x, X) of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M
[PROOF STEP]
by (subst S.nn_integral_fst) simp_all
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ X. f (to_stream (case X of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>M \<Otimes>\<^sub>M Pi\<^sub>M UNIV (\<lambda>i. M) = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (to_stream (case (x, X) of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ X. f (to_stream (case X of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>M \<Otimes>\<^sub>M Pi\<^sub>M UNIV (\<lambda>i. M) = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (to_stream (case (x, X) of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+X. f (x ## to_stream X) \<partial>S.S \<partial>M)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (to_stream (case (x, X) of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M
[PROOF STEP]
by (auto intro!: nn_integral_cong simp: to_stream_nat_case)
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (to_stream (case (x, X) of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (to_stream (case (x, X) of (s, \<omega>) \<Rightarrow> case_nat s \<omega>)) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+X. f (x ## X) \<partial>stream_space M \<partial>M)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
by (subst stream_space_eq_distr)
       (simp add: nn_integral_distr cong: nn_integral_cong)
[PROOF STATE]
proof (state)
this:
\<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## to_stream X) \<partial>Pi\<^sub>M UNIV (\<lambda>i. M) \<partial>M = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M

goal (1 subgoal):
 1. integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
integral\<^sup>N (stream_space M) f = \<integral>\<^sup>+ x. \<integral>\<^sup>+ X. f (x ## X) \<partial>stream_space M \<partial>M

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma quotient_of_split_asm:
  "P (Rat.quotient_of q) = (\<not>(\<exists>a b. b > 0 \<and> coprime a b \<and> q = Rat.Fract a b \<and> \<not>P (a, b)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. P (quotient_of q) = (\<nexists>a b. 0 < b \<and> coprime a b \<and> q = Rat.Fract a b \<and> \<not> P (a, b))
[PROOF STEP]
using quotient_of_split[of P q]
[PROOF STATE]
proof (prove)
using this:
P (quotient_of q) = (\<forall>a b. 0 < b \<longrightarrow> coprime a b \<longrightarrow> q = Rat.Fract a b \<longrightarrow> P (a, b))

goal (1 subgoal):
 1. P (quotient_of q) = (\<nexists>a b. 0 < b \<and> coprime a b \<and> q = Rat.Fract a b \<and> \<not> P (a, b))
[PROOF STEP]
by blast


[STATEMENT]
lemma sst_vars_disj_cons[simp]: "fv\<^sub>s\<^sub>s\<^sub>t (a#A) \<inter> bvars\<^sub>s\<^sub>s\<^sub>t (a#A) = {} \<Longrightarrow> fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. fv\<^sub>s\<^sub>s\<^sub>t (a # A) \<inter> bvars\<^sub>s\<^sub>s\<^sub>t (a # A) = {} \<Longrightarrow> fv\<^sub>s\<^sub>s\<^sub>t A \<inter> bvars\<^sub>s\<^sub>s\<^sub>t A = {}
[PROOF STEP]
unfolding fv\<^sub>s\<^sub>s\<^sub>t_def bvars\<^sub>s\<^sub>s\<^sub>t_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Union> (set (map fv\<^sub>s\<^sub>s\<^sub>t\<^sub>p (a # A))) \<inter> \<Union> (set (map (set \<circ> bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p) (a # A))) = {} \<Longrightarrow> \<Union> (set (map fv\<^sub>s\<^sub>s\<^sub>t\<^sub>p A)) \<inter> \<Union> (set (map (set \<circ> bvars\<^sub>s\<^sub>s\<^sub>t\<^sub>p) A)) = {}
[PROOF STEP]
by auto


[STATEMENT]
lemma tank_arith:
  assumes "0 \<le> (\<tau>::real)" and "0 < c\<^sub>o" and "c\<^sub>o < c\<^sub>i"
  shows "\<forall>\<tau>\<in>{0..\<tau>}. \<tau> \<le> - ((hmin - y) / c\<^sub>o) \<Longrightarrow>  hmin \<le> y - c\<^sub>o * \<tau>"
    and "\<forall>\<tau>\<in>{0..\<tau>}. \<tau> \<le> (hmax - y) / (c\<^sub>i - c\<^sub>o) \<Longrightarrow>  (c\<^sub>i - c\<^sub>o) * \<tau> + y \<le> hmax"
    and "hmin \<le> y \<Longrightarrow> hmin \<le> (c\<^sub>i - c\<^sub>o) \<cdot> \<tau> + y"
    and "y \<le> hmax \<Longrightarrow> y - c\<^sub>o \<cdot> \<tau> \<le> hmax"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<forall>\<tau>\<in>{0..\<tau>}. \<tau> \<le> - ((hmin - y) / c\<^sub>o) \<Longrightarrow> hmin \<le> y - c\<^sub>o \<cdot> \<tau>) &&& (\<forall>\<tau>\<in>{0..\<tau>}. \<tau> \<le> (hmax - y) / (c\<^sub>i - c\<^sub>o) \<Longrightarrow> (c\<^sub>i - c\<^sub>o) \<cdot> \<tau> + y \<le> hmax)) &&& (hmin \<le> y \<Longrightarrow> hmin \<le> (c\<^sub>i - c\<^sub>o) \<cdot> \<tau> + y) &&& (y \<le> hmax \<Longrightarrow> y - c\<^sub>o \<cdot> \<tau> \<le> hmax)
[PROOF STEP]
apply(simp_all add: field_simps le_divide_eq assms)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. hmin \<le> y \<Longrightarrow> hmin + \<tau> \<cdot> c\<^sub>o \<le> y + \<tau> \<cdot> c\<^sub>i
 2. y \<le> hmax \<Longrightarrow> y \<le> hmax + \<tau> \<cdot> c\<^sub>o
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
0 \<le> \<tau>
0 < c\<^sub>o
c\<^sub>o < c\<^sub>i

goal (2 subgoals):
 1. hmin \<le> y \<Longrightarrow> hmin + \<tau> \<cdot> c\<^sub>o \<le> y + \<tau> \<cdot> c\<^sub>i
 2. y \<le> hmax \<Longrightarrow> y \<le> hmax + \<tau> \<cdot> c\<^sub>o
[PROOF STEP]
apply (meson add_mono less_eq_real_def mult_left_mono)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. y \<le> hmax \<Longrightarrow> y \<le> hmax + \<tau> \<cdot> c\<^sub>o
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
0 \<le> \<tau>
0 < c\<^sub>o
c\<^sub>o < c\<^sub>i

goal (1 subgoal):
 1. y \<le> hmax \<Longrightarrow> y \<le> hmax + \<tau> \<cdot> c\<^sub>o
[PROOF STEP]
by (meson add_increasing2 less_eq_real_def mult_nonneg_nonneg)


[STATEMENT]
lemma product_binary_product:
 "\<exists>f g. f \<in> (\<Pi>\<^sub>Q i\<in>UNIV. if i then X else Y) \<rightarrow>\<^sub>Q X \<Otimes>\<^sub>Q Y \<and> g \<in> X \<Otimes>\<^sub>Q Y \<rightarrow>\<^sub>Q (\<Pi>\<^sub>Q i\<in>UNIV. if i then X else Y) \<and>
        g \<circ> f = id \<and> f \<circ> g = id"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>f g. f \<in> (\<Pi>\<^sub>Q i\<in>UNIV. if i then X else Y) \<rightarrow>\<^sub>Q X \<Otimes>\<^sub>Q Y \<and> g \<in> X \<Otimes>\<^sub>Q Y \<rightarrow>\<^sub>Q (\<Pi>\<^sub>Q i\<in>UNIV. if i then X else Y) \<and> g \<circ> f = id \<and> f \<circ> g = id
[PROOF STEP]
by(auto intro!: exI[where x="\<lambda>f. (f True, f False)"] exI[where x="\<lambda>xy b. if b then fst xy else snd xy"] qbs_morphismI
            simp: prod_qbs_Mx_def pair_qbs_Mx_def comp_def all_bool_eq ext)


[STATEMENT]
lemma weakMonoCoinduct: "\<And>x y xa xb P Q.
                         x \<le> y \<Longrightarrow>
                         (Q \<leadsto>\<^sup>^<{(xb, xa). x xb xa}> P) \<longrightarrow>
                        (Q \<leadsto>\<^sup>^<{(xb, xa). y xb xa}> P)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x y xa xb P Q. x \<le> y \<Longrightarrow> Q \<leadsto>\<^sup>^<{(xb, xa). x xb xa}> P \<longrightarrow> Q \<leadsto>\<^sup>^<{(xb, xa). y xb xa}> P
[PROOF STEP]
apply auto
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x y P Q. \<lbrakk>x \<le> y; Q \<leadsto>\<^sup>^<{(xa, y). x xa y}> P\<rbrakk> \<Longrightarrow> Q \<leadsto>\<^sup>^<{(x, ya). y x ya}> P
[PROOF STEP]
apply(rule weakMonotonic)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>x y P Q. \<lbrakk>x \<le> y; Q \<leadsto>\<^sup>^<{(xa, y). x xa y}> P\<rbrakk> \<Longrightarrow> Q \<leadsto>\<^sup>^<?A1 x y P Q> P
 2. \<And>x y P Q. \<lbrakk>x \<le> y; Q \<leadsto>\<^sup>^<{(xa, y). x xa y}> P\<rbrakk> \<Longrightarrow> ?A1 x y P Q \<subseteq> {(x, ya). y x ya}
[PROOF STEP]
by(auto dest: le_funE)


[STATEMENT]
lemma reduce_element_mod_D_case_m':
  assumes A_def: "A = A' @\<^sub>r  B" and B: "B\<in>carrier_mat n n"
  and A': "A' \<in> carrier_mat m n" and a: "a\<le>m" and j: "j<n"
  and mn: "m>=n" and B1: "B $$ (j, j) = D" and B2: "(\<forall>j'\<in>{0..<n}-{j}. B $$ (j, j') = 0)"
  and D0: "D > 0"
  shows "reduce_element_mod_D A a j D m = Matrix.mat (dim_row A) (dim_col A)
          (\<lambda>(i,k). if i = a \<and> k = j then if j = 0 then if D dvd A$$(i,k) then D
                   else A$$(i,k) else A$$(i,k) gmod D else A$$(i,k))" (is "_ = ?A")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_element_mod_D A a j D m = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
proof (rule eq_matI)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>i ja. \<lbrakk>i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))); ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))\<rbrakk> \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 3. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
have jm: "j<m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. j < m
[PROOF STEP]
using mn j
[PROOF STATE]
proof (prove)
using this:
n \<le> m
j < n

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

goal (3 subgoals):
 1. \<And>i ja. \<lbrakk>i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))); ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))\<rbrakk> \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 3. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 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 (3 subgoals):
 1. \<And>i ja. \<lbrakk>i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))); ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))\<rbrakk> \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 3. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
fix i ja
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. \<And>i ja. \<lbrakk>i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))); ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))\<rbrakk> \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 3. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
assume i: "i < dim_row ?A" and ja: "ja < dim_col ?A"
[PROOF STATE]
proof (state)
this:
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))

goal (3 subgoals):
 1. \<And>i ja. \<lbrakk>i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))); ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))\<rbrakk> \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 3. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
show "reduce_element_mod_D A a j D m $$ (i, ja) = ?A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
proof (cases "i=a")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
i \<noteq> a

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A$$(a,j)
        then addrow (-((A$$(a,j) gdiv D)) + 1) a (j + m) A else A
        else addrow (-((A$$(a,j) gdiv D))) a (j + m) A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)
[PROOF STEP]
unfolding reduce_element_mod_D_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... $$ (i,ja) = A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
unfolding mat_addrow_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja)) else A else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja))) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
using False ja i
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja)) else A else Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja))) $$ (i, ja) = A $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = A $$ (i, ja)

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = A $$ (i, ja)

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... = ?A $$ (i,ja)"
[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 \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a

goal (1 subgoal):
 1. A $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using i ja
[PROOF STATE]
proof (prove)
using this:
i \<noteq> a
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))

goal (1 subgoal):
 1. A $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (2 subgoals):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. i \<noteq> a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
i = a

goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
note ia = True
[PROOF STATE]
proof (state)
this:
i = a

goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "reduce_element_mod_D A a j D m
      = (if j = 0 then if D dvd A$$(a,j) then addrow (-((A$$(a,j) gdiv D)) + 1) a (j + m) A else A
        else addrow (-((A$$(a,j) gdiv D))) a (j + m) A)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)
[PROOF STEP]
unfolding reduce_element_mod_D_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)

goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m = (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A)

goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... $$ (i,ja) = ?A $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
proof (cases "ja = j")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
ja = j

goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
note ja_j = True
[PROOF STATE]
proof (state)
this:
ja = j

goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "A $$ (j + m, ja) = B $$ (j,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (j + m, ja) = B $$ (j, ja)
[PROOF STEP]
by (rule append_rows_nth2[OF A' _ A_def ], insert j ja A B mn, auto)
[PROOF STATE]
proof (state)
this:
A $$ (j + m, ja) = B $$ (j, ja)

goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A $$ (j + m, ja) = B $$ (j, ja)

goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... = D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B $$ (j, ja) = D
[PROOF STEP]
using True j mn B1 B2 B
[PROOF STATE]
proof (prove)
using this:
ja = j
j < n
n \<le> m
B $$ (j, j) = D
\<forall>j'\<in>{0..<n} - {j}. B $$ (j, j') = 0
B \<in> carrier_mat n n

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

goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
A $$ (j + m, ja) = D
[PROOF STEP]
have A_ja_jaD: "A $$ (j + m, ja) = D"
[PROOF STATE]
proof (prove)
using this:
A $$ (j + m, ja) = D

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

goal (2 subgoals):
 1. ja = j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
proof (cases "j=0 \<and> D dvd A$$(a,j)")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
j = 0 \<and> D dvd A $$ (a, j)

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have 1: "reduce_element_mod_D A a j D m = addrow (-((A$$(a,j) gdiv D)) + 1) a (j + m) A "
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. reduce_element_mod_D A a j D m = addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A
[PROOF STEP]
using True ia ja_j
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
i = a
ja = j

goal (1 subgoal):
 1. reduce_element_mod_D A a j D m = addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A
[PROOF STEP]
unfolding reduce_element_mod_D_def
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
i = a
ja = j

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) = addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m = addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m = addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... $$(i,ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A $$ (i, ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)
[PROOF STEP]
unfolding mat_addrow_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja)) $$ (i, ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)
[PROOF STEP]
using True ja_j ia
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
ja = j
i = a

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja)) $$ (i, ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)
[PROOF STEP]
using A i j
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
ja = j
i = a
A \<in> carrier_mat (m + n) n
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
j < n

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, ja). if a = i then (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) else A $$ (i, ja)) $$ (i, ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A $$ (i, ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A $$ (i, ja) = (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja)

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... = D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D
[PROOF STEP]
have "A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0
[PROOF STEP]
using True ia ja_j
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
i = a
ja = j

goal (1 subgoal):
 1. A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0
[PROOF STEP]
using D0
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
i = a
ja = j
0 < D

goal (1 subgoal):
 1. A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0

goal (1 subgoal):
 1. (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
A $$ (i, ja) + D * - (A $$ (i, ja) gdiv D) = 0

goal (1 subgoal):
 1. (- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D
[PROOF STEP]
by (metis A_ja_jaD ab_semigroup_add_class.add_ac(1) add.commute add_right_imp_eq ia int_distrib(2)
                ja_j more_arith_simps(3) mult.commute mult_cancel_right1)
[PROOF STATE]
proof (state)
this:
(- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(- (A $$ (a, j) gdiv D) + 1) * A $$ (j + m, ja) + A $$ (i, ja) = D

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... = ?A $$ (i,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using True ia A i j ja_j
[PROOF STATE]
proof (prove)
using this:
j = 0 \<and> D dvd A $$ (a, j)
i = a
A \<in> carrier_mat (m + n) n
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
j < n
ja = j

goal (1 subgoal):
 1. D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
D = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (2 subgoals):
 1. j = 0 \<and> D dvd A $$ (a, j) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using True 1
[PROOF STATE]
proof (prove)
using this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
j = 0 \<and> D dvd A $$ (a, j)
reduce_element_mod_D A a j D m = addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> (j = 0 \<and> D dvd A $$ (a, j))

goal (1 subgoal):
 1. \<not> (j = 0 \<and> D dvd A $$ (a, j)) \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
proof (cases "j=0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. j = 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
j = 0

goal (2 subgoals):
 1. j = 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
 2. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
j = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
j = 0

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False i ja
[PROOF STATE]
proof (prove)
using this:
j = 0
\<not> (j = 0 \<and> D dvd A $$ (a, j))
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
j \<noteq> 0

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "?A $$ (i,ja) = A $$ (i, ja) gmod D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja) gmod D
[PROOF STEP]
using True ia A i j False
[PROOF STATE]
proof (prove)
using this:
ja = j
i = a
A \<in> carrier_mat (m + n) n
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
j < n
j \<noteq> 0

goal (1 subgoal):
 1. Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja) gmod D
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja) gmod D

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = A $$ (i, ja) gmod D

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... = A $$ (i, ja) - ((A $$ (i, ja) gdiv D) * D)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) gmod D = A $$ (i, ja) - A $$ (i, ja) gdiv D * D
[PROOF STEP]
by (subst gmod_gdiv[OF D0], auto)
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) gmod D = A $$ (i, ja) - A $$ (i, ja) gdiv D * D

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) gmod D = A $$ (i, ja) - A $$ (i, ja) gdiv D * D

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... =  - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) - A $$ (i, ja) gdiv D * D = - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja)
[PROOF STEP]
unfolding A_ja_jaD
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (i, ja) - A $$ (i, ja) gdiv D * D = - (A $$ (a, j) gdiv D) * D + A $$ (i, ja)
[PROOF STEP]
by (simp add: True ia)
[PROOF STATE]
proof (state)
this:
A $$ (i, ja) - A $$ (i, ja) gdiv D * D = - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja)

goal (1 subgoal):
 1. j \<noteq> 0 \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja)

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using A False True i ia j
[PROOF STATE]
proof (prove)
using this:
Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja) = - (A $$ (a, j) gdiv D) * A $$ (j + m, ja) + A $$ (i, ja)
A \<in> carrier_mat (m + n) n
j \<noteq> 0
ja = j
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
i = a
j < n

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
ja \<noteq> j

goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "A $$ (j + m, ja) = B $$ (j,ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A $$ (j + m, ja) = B $$ (j, ja)
[PROOF STEP]
by (rule append_rows_nth2[OF A' _ A_def ], insert j mn ja A B, auto)
[PROOF STATE]
proof (state)
this:
A $$ (j + m, ja) = B $$ (j, ja)

goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
A $$ (j + m, ja) = B $$ (j, ja)

goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
have "... = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. B $$ (j, ja) = 0
[PROOF STEP]
using False
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> j

goal (1 subgoal):
 1. B $$ (j, ja) = 0
[PROOF STEP]
using A a mn ja j B2
[PROOF STATE]
proof (prove)
using this:
ja \<noteq> j
A \<in> carrier_mat (m + n) n
a \<le> m
n \<le> m
ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
j < n
\<forall>j'\<in>{0..<n} - {j}. B $$ (j, j') = 0

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

goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
A $$ (j + m, ja) = 0
[PROOF STEP]
have A_am_ja0: "A $$ (j + m, ja) = 0"
[PROOF STATE]
proof (prove)
using this:
A $$ (j + m, ja) = 0

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

goal (1 subgoal):
 1. ja \<noteq> j \<Longrightarrow> (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
A $$ (j + m, ja) = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
A $$ (j + m, ja) = 0

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
using False i ja
[PROOF STATE]
proof (prove)
using this:
A $$ (j + m, ja) = 0
ja \<noteq> j
i < dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
ja < dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))

goal (1 subgoal):
 1. (if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(if j = 0 then if D dvd A $$ (a, j) then addrow (- (A $$ (a, j) gdiv D) + 1) a (j + m) A else A else addrow (- (A $$ (a, j) gdiv D)) a (j + m) A) $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. i = a \<Longrightarrow> reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>b. case b of (i, k) \<Rightarrow> if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>b. case b of (i, k) \<Rightarrow> if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (1 subgoal):
 1. reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
reduce_element_mod_D A a j D m $$ (i, ja) = Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)) $$ (i, ja)

goal (2 subgoals):
 1. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 2. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
next
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
 2. dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
show "dim_row (reduce_element_mod_D A a j D m) = dim_row ?A"
    and "dim_col (reduce_element_mod_D A a j D m) = dim_col ?A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))) &&& dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
using reduce_element_mod_D_def
[PROOF STATE]
proof (prove)
using this:
reduce_element_mod_D ?A ?a ?j ?D ?m = (if ?j = 0 then if ?D dvd ?A $$ (?a, ?j) then addrow (- (?A $$ (?a, ?j) gdiv ?D) + 1) ?a (?j + ?m) ?A else ?A else addrow (- (?A $$ (?a, ?j) gdiv ?D)) ?a (?j + ?m) ?A)

goal (1 subgoal):
 1. dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k))) &&& dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 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 STEP]
by auto
[PROOF STATE]
proof (state)
this:
dim_row (reduce_element_mod_D A a j D m) = dim_row (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))
dim_col (reduce_element_mod_D A a j D m) = dim_col (Matrix.mat (dim_row A) (dim_col A) (\<lambda>(i, k). if i = a \<and> k = j then if j = 0 then if D dvd A $$ (i, k) then D else A $$ (i, k) else A $$ (i, k) gmod D else A $$ (i, k)))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma "0 \<le> (x::real) \<and> 0 \<le> y \<and> x * y = 1 \<longrightarrow> x + y \<le> x\<^sup>2 + y\<^sup>2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> x \<and> 0 \<le> y \<and> x * y = 1 \<longrightarrow> x + y \<le> x\<^sup>2 + y\<^sup>2
[PROOF STEP]
by (sos "(((A<0 * R<1) + (([1] * A=0) + (R<1 * ((R<1 * [~1/2*x + ~1/2*y + 1]^2) + (R<3/4 * [~1*x + y]^2))))))")


[STATEMENT]
lemma numeral_eqs_upto_12:
  shows "2 = Suc 1"
    and "3 = Suc 2"
    and "4 = Suc 3"
    and "5 = Suc 4"
    and "6 = Suc 5"
    and "7 = Suc 6"
    and "8 = Suc 7"
    and "9 = Suc 8"
    and "10 = Suc 9"
    and "11 = Suc 10"
    and "12 = Suc 11"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((2 = Suc 1 &&& 3 = Suc 2) &&& 4 = Suc 3 &&& 5 = Suc 4 &&& 6 = Suc 5) &&& (7 = Suc 6 &&& 8 = Suc 7 &&& 9 = Suc 8) &&& 10 = Suc 9 &&& 11 = Suc 10 &&& 12 = Suc 11
[PROOF STEP]
by simp_all


[STATEMENT]
lemma append_take_drop:
  "w = xs @ ys \<longleftrightarrow> xs = take (length xs) w \<and> ys = drop (length xs) w"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (w = xs @ ys) = (xs = take (length xs) w \<and> ys = drop (length xs) w)
[PROOF STEP]
by (metis append_eq_conv_conj)


[STATEMENT]
lemma list_lcm_mult_int [simp]:
  fixes xs :: "int list"
  shows "list_lcm (map (times a) xs) = (if xs = [] then 1 else \<bar>a\<bar> * list_lcm xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. lcm_list (map ((*) a) xs) = (if xs = [] then 1 else \<bar>a\<bar> * lcm_list xs)
[PROOF STEP]
by (simp add: Lcm_mult abs_mult)


[STATEMENT]
lemma bounded_has_Sup:
  fixes S :: "real set"
  assumes "bounded S"
    and "S \<noteq> {}"
  shows "\<forall>x\<in>S. x \<le> Sup S"
    and "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>x\<in>S. x \<le> Sup S &&& \<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>x. x \<in> S \<Longrightarrow> x \<le> Sup S
 2. \<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b
[PROOF STEP]
show "\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
bounded S
S \<noteq> {}

goal (1 subgoal):
 1. \<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b
[PROOF STEP]
by (metis cSup_least)
[PROOF STATE]
proof (state)
this:
\<forall>b. (\<forall>x\<in>S. x \<le> b) \<longrightarrow> Sup S \<le> b

goal (1 subgoal):
 1. \<And>x. x \<in> S \<Longrightarrow> x \<le> Sup S
[PROOF STEP]
qed (metis cSup_upper assms(1) bounded_imp_bdd_above)


[STATEMENT]
lemma of_real_erfc_numeral [simp]: "of_real (erfc (numeral n)) = erfc (numeral n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_real (erfc (numeral n)) = erfc (numeral n)
[PROOF STEP]
by (simp add: erfc_def)


[STATEMENT]
lemma eval_tm_CONS[simp]:
  "\<lbrakk>length is \<le> #\<^sub>V \<AA>; #\<^sub>V \<AA> = length x\<rbrakk> \<Longrightarrow>
   eval_tm (CONS x \<AA>) is = scalar_product x is + 2 * eval_tm \<AA> is"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>length is \<le> #\<^sub>V \<AA>; #\<^sub>V \<AA> = length x\<rbrakk> \<Longrightarrow> eval_tm (CONS x \<AA>) is = scalar_product (map of_bool x) is + 2 * eval_tm \<AA> is
[PROOF STEP]
by transfer (auto simp: scalar_product_CONS[symmetric]
    intro!: arg_cong2[of _ _ _ _ scalar_product] nth_equalityI)


[STATEMENT]
lemma mult_le_mono2_hmset: "i \<le> j \<Longrightarrow> k * i \<le> k * j" for i j k :: hmultiset
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. i \<le> j \<Longrightarrow> k * i \<le> k * j
[PROOF STEP]
by (simp add: mult_left_mono)


[STATEMENT]
lemma Norm_triangular_ineq_diff:
  assumes "x \<in> space\<^sub>N N"
  shows "Norm N (x - y) \<le> defect N * Norm N x + defect N * Norm N y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Norm N (x - y) \<le> defect N * Norm N x + defect N * Norm N y
[PROOF STEP]
using Norm_triangular_ineq[OF assms, of "-y"]
[PROOF STATE]
proof (prove)
using this:
Norm N (x + - y) \<le> defect N * Norm N x + defect N * Norm N (- y)

goal (1 subgoal):
 1. Norm N (x - y) \<le> defect N * Norm N x + defect N * Norm N y
[PROOF STEP]
by auto


[STATEMENT]
lemma sorted_merge: "sorted (merge xs ys) \<longleftrightarrow> (sorted xs \<and> sorted ys)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sorted (merge xs ys) = (sorted xs \<and> sorted ys)
[PROOF STEP]
by(induction xs ys rule: merge.induct) (auto simp: set_merge)


[STATEMENT]
lemma prv_imp_eqv_transi:
assumes "\<phi> \<in> fmla" and "\<chi>1 \<in> fmla" and "\<chi>2 \<in> fmla"
assumes "prv (imp \<phi> \<chi>1)" and "prv (eqv \<chi>1 \<chi>2)"
shows "prv (imp \<phi> \<chi>2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. prv (imp \<phi> \<chi>2)
[PROOF STEP]
by (meson assms imp imp_compat_eqvR prv_eqv_prv)


[STATEMENT]
lemma hom_prod_list: "hom (prod_list xs) = prod_list (map hom xs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. hom (prod_list xs) = prod_list (map hom xs)
[PROOF STEP]
by (induct xs, auto simp: hom_distribs)


[STATEMENT]
lemma ord_divides': "[a ^ d = Suc 0] (mod n) = (ord n a dvd d)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. [a ^ d = Suc 0] (mod n) = (ord n a dvd d)
[PROOF STEP]
using ord_divides[of a d n]
[PROOF STATE]
proof (prove)
using this:
[a ^ d = 1] (mod n) = (ord n a dvd d)

goal (1 subgoal):
 1. [a ^ d = Suc 0] (mod n) = (ord n a dvd d)
[PROOF STEP]
by simp


[STATEMENT]
lemma picard_lindeloef_autonomous_affine:
  fixes A :: "'a::{banach,real_normed_field,heine_borel}^'n^'n"
  shows "picard_lindeloef (\<lambda> t s. A *v s + B) UNIV UNIV t\<^sub>0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. picard_lindeloef (\<lambda>t s. A *v s + B) UNIV UNIV t\<^sub>0
[PROOF STEP]
using picard_lindeloef_affine[of _ "\<lambda>t. A" "\<lambda>t. B"]
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>matrix_continuous_on ?T (\<lambda>t. A); \<And>\<tau> \<epsilon>. \<lbrakk>\<tau> \<in> ?T; 0 < \<epsilon>\<rbrakk> \<Longrightarrow> bdd_above {uu_. \<exists>t. uu_ = \<parallel>A\<parallel>\<^sub>o\<^sub>p \<and> dist \<tau> t \<le> \<epsilon>}; continuous_on ?T (\<lambda>t. B); open ?S; ?t\<^sub>0 \<in> ?T; open ?T; is_interval ?T\<rbrakk> \<Longrightarrow> picard_lindeloef (\<lambda>t s. A *v s + B) ?T ?S ?t\<^sub>0

goal (1 subgoal):
 1. picard_lindeloef (\<lambda>t s. A *v s + B) UNIV UNIV t\<^sub>0
[PROOF STEP]
unfolding matrix_continuous_on_def
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>\<forall>t\<in>?T. \<forall>\<epsilon>>0. \<exists>\<delta>>0. \<forall>\<tau>\<in>?T. \<bar>\<tau> - t\<bar> < \<delta> \<longrightarrow> \<parallel>A - A\<parallel>\<^sub>o\<^sub>p \<le> \<epsilon>; \<And>\<tau> \<epsilon>. \<lbrakk>\<tau> \<in> ?T; 0 < \<epsilon>\<rbrakk> \<Longrightarrow> bdd_above {uu_. \<exists>t. uu_ = \<parallel>A\<parallel>\<^sub>o\<^sub>p \<and> dist \<tau> t \<le> \<epsilon>}; continuous_on ?T (\<lambda>t. B); open ?S; ?t\<^sub>0 \<in> ?T; open ?T; is_interval ?T\<rbrakk> \<Longrightarrow> picard_lindeloef (\<lambda>t s. A *v s + B) ?T ?S ?t\<^sub>0

goal (1 subgoal):
 1. picard_lindeloef (\<lambda>t s. A *v s + B) UNIV UNIV t\<^sub>0
[PROOF STEP]
by (simp only: diff_self op_norm0, auto)


[STATEMENT]
lemma dist_self [simp]: "dist x x = 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. dist x x = 0
[PROOF STEP]
by simp


[STATEMENT]
lemma div_less_dividend_word:"\<lbrakk>x \<noteq> 0; n \<noteq> 1\<rbrakk> \<Longrightarrow> (x::('a::len) word) div n < x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1\<rbrakk> \<Longrightarrow> x div n < x
[PROOF STEP]
apply (cases \<open>n = 0\<close>)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n = 0\<rbrakk> \<Longrightarrow> x div n < x
 2. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> x div n < x
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>x \<noteq> 0; n = 0\<rbrakk> \<Longrightarrow> 0 < x
 2. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> x div n < x
[PROOF STEP]
apply (simp add:word_neq_0_conv)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> x div n < x
[PROOF STEP]
apply (subst word_arith_nat_div)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> word_of_nat (unat x div unat n) < x
[PROOF STEP]
apply (rule word_of_nat_less)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> unat x div unat n < unat x
[PROOF STEP]
apply (rule div_less_dividend)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> 1 < unat n
 2. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> 0 < unat x
[PROOF STEP]
using unat_eq_zero word_unat_Rep_inject1
[PROOF STATE]
proof (prove)
using this:
(unat ?x = 0) = (?x = 0)
(unat ?x = unat 1) = (?x = 1)

goal (2 subgoals):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> 1 < unat n
 2. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> 0 < unat x
[PROOF STEP]
apply force
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>x \<noteq> 0; n \<noteq> 1; n \<noteq> 0\<rbrakk> \<Longrightarrow> 0 < unat x
[PROOF STEP]
apply (simp add:unat_gt_0)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma reflp_onI [Pure.intro]:
  "(\<And>a. a \<in> A \<Longrightarrow> P a a) \<Longrightarrow> reflp_on P A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>a. a \<in> A \<Longrightarrow> P a a) \<Longrightarrow> Restricted_Predicates.reflp_on P A
[PROOF STEP]
unfolding reflp_on_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>a. a \<in> A \<Longrightarrow> P a a) \<Longrightarrow> \<forall>a\<in>A. P a a
[PROOF STEP]
by blast