[STATEMENT]
lemma lattice_of_kId_subset_fs_init:
  assumes k_det: "k = Determinant.det (mat_of_rows n fs_init)"
  and mn: "m=n"
  shows "lattice_of (Matrix.rows (k \<cdot>\<^sub>m (1\<^sub>m m))) \<subseteq> lattice_of fs_init"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
let ?Z = "(mat_of_rows n fs_init)"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
let ?RAT = "of_int_hom.mat_hom :: int mat \<Rightarrow> rat mat"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have RAT_fs_init: "?RAT (mat_of_rows n fs_init) \<in> carrier_mat n n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (mat_of_rows n fs_init) \<in> carrier_mat n n
[PROOF STEP]
using len map_carrier_mat mat_of_rows_carrier(1) mn
[PROOF STATE]
proof (prove)
using this:
length fs_init = m
(map_mat ?f ?A \<in> carrier_mat ?nr ?nc) = (?A \<in> carrier_mat ?nr ?nc)
mat_of_rows ?n ?vs \<in> carrier_mat (length ?vs) ?n
m = n

goal (1 subgoal):
 1. of_int_hom.mat_hom (mat_of_rows n fs_init) \<in> carrier_mat n n
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (mat_of_rows n fs_init) \<in> carrier_mat n n

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have det_RAT_fs_init: "Determinant.det (?RAT ?Z) \<noteq> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<noteq> 0
[PROOF STEP]
proof (rule gs.lin_indpt_rows_imp_det_not_0[OF RAT_fs_init])
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. gs.lin_indpt (set (rows (of_int_hom.mat_hom (mat_of_rows n fs_init))))
 2. distinct (rows (of_int_hom.mat_hom (mat_of_rows n fs_init)))
[PROOF STEP]
have rw: "Matrix.rows (?RAT (mat_of_rows n fs_init)) = RAT fs_init"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rows (of_int_hom.mat_hom (mat_of_rows n fs_init)) = map of_int_hom.vec_hom fs_init
[PROOF STEP]
by (metis cof_vec_space.lin_indpt_list_def fs_init lin_dep mat_of_rows_map rows_mat_of_rows)
[PROOF STATE]
proof (state)
this:
rows (of_int_hom.mat_hom (mat_of_rows n fs_init)) = map of_int_hom.vec_hom fs_init

goal (2 subgoals):
 1. gs.lin_indpt (set (rows (of_int_hom.mat_hom (mat_of_rows n fs_init))))
 2. distinct (rows (of_int_hom.mat_hom (mat_of_rows n fs_init)))
[PROOF STEP]
thus "gs.lin_indpt (set (Matrix.rows (?RAT (mat_of_rows n fs_init))))"
[PROOF STATE]
proof (prove)
using this:
rows (of_int_hom.mat_hom (mat_of_rows n fs_init)) = map of_int_hom.vec_hom fs_init

goal (1 subgoal):
 1. gs.lin_indpt (set (rows (of_int_hom.mat_hom (mat_of_rows n fs_init))))
[PROOF STEP]
by (insert lin_dep, simp add: cof_vec_space.lin_indpt_list_def)
[PROOF STATE]
proof (state)
this:
gs.lin_indpt (set (rows (of_int_hom.mat_hom (mat_of_rows n fs_init))))

goal (1 subgoal):
 1. distinct (rows (of_int_hom.mat_hom (mat_of_rows n fs_init)))
[PROOF STEP]
show "distinct (Matrix.rows (?RAT (mat_of_rows n fs_init)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. distinct (rows (of_int_hom.mat_hom (mat_of_rows n fs_init)))
[PROOF STEP]
using rw cof_vec_space.lin_indpt_list_def lin_dep
[PROOF STATE]
proof (prove)
using this:
rows (of_int_hom.mat_hom (mat_of_rows n fs_init)) = map of_int_hom.vec_hom fs_init
cof_vec_space.lin_indpt_list ?n ?fs = (set ?fs \<subseteq> carrier_vec ?n \<and> distinct ?fs \<and> \<not> module.lin_dep class_ring (module_vec TYPE(?'a) ?n) (set ?fs))
gs.lin_indpt_list (map of_int_hom.vec_hom fs_init)

goal (1 subgoal):
 1. distinct (rows (of_int_hom.mat_hom (mat_of_rows n fs_init)))
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
distinct (rows (of_int_hom.mat_hom (mat_of_rows n fs_init)))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<noteq> 0

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
obtain inv_Z where inverts_Z: "inverts_mat (?RAT ?Z) inv_Z" and inv_Z: "inv_Z \<in> carrier_mat m m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>inv_Z. \<lbrakk>inverts_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) inv_Z; inv_Z \<in> carrier_mat m m\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis mn det_RAT_fs_init dvd_field_iff invertible_iff_is_unit_JNF
        len map_carrier_mat mat_of_rows_carrier(1) obtain_inverse_matrix)
[PROOF STATE]
proof (state)
this:
inverts_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) inv_Z
inv_Z \<in> carrier_mat m m

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have det_rat_Z_k: "Determinant.det (?RAT ?Z) = rat_of_int k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k
[PROOF STEP]
using k_det of_int_hom.hom_det
[PROOF STATE]
proof (prove)
using this:
k = det (mat_of_rows n fs_init)
det (of_int_hom.mat_hom ?A) = of_int (det ?A)

goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have "?RAT ?Z *  adj_mat (?RAT ?Z) = Determinant.det (?RAT ?Z) \<cdot>\<^sub>m 1\<^sub>m n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (mat_of_rows n fs_init) * adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m 1\<^sub>m n
[PROOF STEP]
by (rule adj_mat[OF RAT_fs_init])
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (mat_of_rows n fs_init) * adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m 1\<^sub>m n

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
hence "inv_Z * (?RAT ?Z *  adj_mat (?RAT ?Z)) = inv_Z * (Determinant.det (?RAT ?Z) \<cdot>\<^sub>m 1\<^sub>m n)"
[PROOF STATE]
proof (prove)
using this:
of_int_hom.mat_hom (mat_of_rows n fs_init) * adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m 1\<^sub>m n

goal (1 subgoal):
 1. inv_Z * (of_int_hom.mat_hom (mat_of_rows n fs_init) * adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init))) = inv_Z * (det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m 1\<^sub>m n)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
inv_Z * (of_int_hom.mat_hom (mat_of_rows n fs_init) * adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init))) = inv_Z * (det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m 1\<^sub>m n)

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
hence k_inv_Z_eq_adj: "(rat_of_int k) \<cdot>\<^sub>m inv_Z = adj_mat (?RAT ?Z)"
[PROOF STATE]
proof (prove)
using this:
inv_Z * (of_int_hom.mat_hom (mat_of_rows n fs_init) * adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init))) = inv_Z * (det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m 1\<^sub>m n)

goal (1 subgoal):
 1. rat_of_int k \<cdot>\<^sub>m inv_Z = adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
by (smt Determinant.mat_mult_left_right_inverse RAT_fs_init adj_mat(1,3) mn
        carrier_matD det_RAT_fs_init det_rat_Z_k gs.det_nonzero_congruence inv_Z inverts_Z
        inverts_mat_def mult_smult_assoc_mat smult_carrier_mat)
[PROOF STATE]
proof (state)
this:
rat_of_int k \<cdot>\<^sub>m inv_Z = adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init))

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have adj_mat_Z: "adj_mat (?RAT ?Z) $$ (i,j) \<in> \<int>" if i: "i<m" and j: "j<n" for i j
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
have det_mat_delete_Z: "Determinant.det (mat_delete (?RAT ?Z) j i) \<in> \<int>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) \<in> \<int>
[PROOF STEP]
proof (rule Ints_det)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
fix ia ja
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
assume ia: "ia < dim_row  (mat_delete (?RAT ?Z) j i)"
        and ja: "ja < dim_col  (mat_delete (?RAT ?Z) j i)"
[PROOF STATE]
proof (state)
this:
ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)
ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)

goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
have "(mat_delete (?RAT ?Z) j i) $$ (ia, ja) =  (?RAT ?Z) $$ (insert_index j ia, insert_index i ja)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) = of_int_hom.mat_hom (mat_of_rows n fs_init) $$ (insert_index j ia, insert_index i ja)
[PROOF STEP]
by (rule mat_delete_index[symmetric], insert i j mn len ia ja RAT_fs_init, auto)
[PROOF STATE]
proof (state)
this:
mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) = of_int_hom.mat_hom (mat_of_rows n fs_init) $$ (insert_index j ia, insert_index i ja)

goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) = of_int_hom.mat_hom (mat_of_rows n fs_init) $$ (insert_index j ia, insert_index i ja)

goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
have "... = rat_of_int (?Z $$ (insert_index j ia, insert_index i ja))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (mat_of_rows n fs_init) $$ (insert_index j ia, insert_index i ja) = rat_of_int (mat_of_rows n fs_init $$ (insert_index j ia, insert_index i ja))
[PROOF STEP]
by (rule index_map_mat, insert i j ia ja, auto simp add: insert_index_def)
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (mat_of_rows n fs_init) $$ (insert_index j ia, insert_index i ja) = rat_of_int (mat_of_rows n fs_init $$ (insert_index j ia, insert_index i ja))

goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (mat_of_rows n fs_init) $$ (insert_index j ia, insert_index i ja) = rat_of_int (mat_of_rows n fs_init $$ (insert_index j ia, insert_index i ja))

goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
have "... \<in> \<int>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rat_of_int (mat_of_rows n fs_init $$ (insert_index j ia, insert_index i ja)) \<in> \<int>
[PROOF STEP]
using Ints_of_int
[PROOF STATE]
proof (prove)
using this:
of_int ?z \<in> \<int>

goal (1 subgoal):
 1. rat_of_int (mat_of_rows n fs_init $$ (insert_index j ia, insert_index i ja)) \<in> \<int>
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
rat_of_int (mat_of_rows n fs_init $$ (insert_index j ia, insert_index i ja)) \<in> \<int>

goal (1 subgoal):
 1. \<And>ia ja. \<lbrakk>ia < dim_row (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i); ja < dim_col (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)\<rbrakk> \<Longrightarrow> mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
show "(mat_delete (?RAT ?Z) j i) $$ (ia, ja) \<in> \<int>"
[PROOF STATE]
proof (prove)
using this:
mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>

goal (1 subgoal):
 1. mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i $$ (ia, ja) \<in> \<int>

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) \<in> \<int>

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
have "adj_mat (?RAT ?Z) $$ (i,j) = Determinant.cofactor (?RAT ?Z) j i"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) = Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i
[PROOF STEP]
unfolding adj_mat_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Matrix.mat (dim_row (of_int_hom.mat_hom (mat_of_rows n fs_init))) (dim_col (of_int_hom.mat_hom (mat_of_rows n fs_init))) (\<lambda>(i, j). Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) $$ (i, j) = Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i
[PROOF STEP]
by (simp add: len i j)
[PROOF STATE]
proof (state)
this:
adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) = Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) = Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
have "... =  (- 1) ^ (j + i) * Determinant.det (mat_delete (?RAT ?Z) j i)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i = (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)
[PROOF STEP]
unfolding Determinant.cofactor_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) = (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i = (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
Determinant.cofactor (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i = (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i)

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
have "... \<in> \<int>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) \<in> \<int>
[PROOF STEP]
using det_mat_delete_Z
[PROOF STATE]
proof (prove)
using this:
det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) \<in> \<int>

goal (1 subgoal):
 1. (- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) \<in> \<int>
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(- 1) ^ (j + i) * det (mat_delete (of_int_hom.mat_hom (mat_of_rows n fs_init)) j i) \<in> \<int>

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>

goal (1 subgoal):
 1. adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (i, j) \<in> \<int>

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?i1 < m; ?j1 < n\<rbrakk> \<Longrightarrow> adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init)) $$ (?i1, ?j1) \<in> \<int>

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have kinvZ_in_Z: "((rat_of_int k) \<cdot>\<^sub>m inv_Z) $$ (i,j) \<in> \<int>" if i: "i<m" and j: "j<n" for i j
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) \<in> \<int>
[PROOF STEP]
using k_inv_Z_eq_adj
[PROOF STATE]
proof (prove)
using this:
rat_of_int k \<cdot>\<^sub>m inv_Z = adj_mat (of_int_hom.mat_hom (mat_of_rows n fs_init))

goal (1 subgoal):
 1. (rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) \<in> \<int>
[PROOF STEP]
by (simp add: adj_mat_Z i j)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?i1 < m; ?j1 < n\<rbrakk> \<Longrightarrow> (rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (?i1, ?j1) \<in> \<int>

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have "?RAT (k \<cdot>\<^sub>m (1\<^sub>m m)) = Determinant.det (?RAT ?Z) \<cdot>\<^sub>m (inv_Z * ?RAT ?Z)" (is "?lhs = ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
have "(inv_Z * ?RAT ?Z) = (1\<^sub>m m)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = 1\<^sub>m m
[PROOF STEP]
by (metis Determinant.mat_mult_left_right_inverse RAT_fs_init mn carrier_matD(1)
          inv_Z inverts_Z inverts_mat_def)
[PROOF STATE]
proof (state)
this:
inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = 1\<^sub>m m

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
from this
[PROOF STATE]
proof (chain)
picking this:
inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = 1\<^sub>m m
[PROOF STEP]
have "?rhs = rat_of_int k \<cdot>\<^sub>m (1\<^sub>m m)"
[PROOF STATE]
proof (prove)
using this:
inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = 1\<^sub>m m

goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k \<cdot>\<^sub>m 1\<^sub>m m
[PROOF STEP]
using det_rat_Z_k
[PROOF STATE]
proof (prove)
using this:
inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = 1\<^sub>m m
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k

goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k \<cdot>\<^sub>m 1\<^sub>m m
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k \<cdot>\<^sub>m 1\<^sub>m m

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = rat_of_int k \<cdot>\<^sub>m 1\<^sub>m m

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
have "... = ?lhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rat_of_int k \<cdot>\<^sub>m 1\<^sub>m m = of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
rat_of_int k \<cdot>\<^sub>m 1\<^sub>m m = of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m)

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m)

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))
[PROOF STEP]
..
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init))

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have "... = (Determinant.det (?RAT ?Z) \<cdot>\<^sub>m inv_Z) * ?RAT ?Z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)
[PROOF STEP]
by (metis RAT_fs_init mn inv_Z mult_smult_assoc_mat)
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m (inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)) = det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have "... = ((rat_of_int k) \<cdot>\<^sub>m inv_Z) * ?RAT ?Z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)
[PROOF STEP]
by (simp add: k_det)
[PROOF STATE]
proof (state)
this:
det (of_int_hom.mat_hom (mat_of_rows n fs_init)) \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)
[PROOF STEP]
have r': "?RAT (k \<cdot>\<^sub>m (1\<^sub>m m)) = ((rat_of_int k) \<cdot>\<^sub>m inv_Z) * ?RAT ?Z"
[PROOF STATE]
proof (prove)
using this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
have r: "(k \<cdot>\<^sub>m (1\<^sub>m m)) = ((map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z))) * ?Z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
have "?RAT ((map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z))) = ((rat_of_int k) \<cdot>\<^sub>m inv_Z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = rat_of_int k \<cdot>\<^sub>m inv_Z
[PROOF STEP]
proof (rule eq_matI, auto)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row inv_Z; j < dim_col inv_Z\<rbrakk> \<Longrightarrow> rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
fix i j
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row inv_Z; j < dim_col inv_Z\<rbrakk> \<Longrightarrow> rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
assume i: "i < dim_row inv_Z" and j: "j < dim_col inv_Z"
[PROOF STATE]
proof (state)
this:
i < dim_row inv_Z
j < dim_col inv_Z

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row inv_Z; j < dim_col inv_Z\<rbrakk> \<Longrightarrow> rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
have "((rat_of_int k) \<cdot>\<^sub>m inv_Z) $$ (i,j) =  (rat_of_int k * inv_Z $$ (i, j))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
using index_smult_mat i j
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?i < dim_row ?A; ?j < dim_col ?A\<rbrakk> \<Longrightarrow> (?a \<cdot>\<^sub>m ?A) $$ (?i, ?j) = ?a * ?A $$ (?i, ?j)
dim_row (?a \<cdot>\<^sub>m ?A) = dim_row ?A
dim_col (?a \<cdot>\<^sub>m ?A) = dim_col ?A
i < dim_row inv_Z
j < dim_col inv_Z

goal (1 subgoal):
 1. (rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) = rat_of_int k * inv_Z $$ (i, j)

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row inv_Z; j < dim_col inv_Z\<rbrakk> \<Longrightarrow> rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
hence kinvZ_in_Z': "... \<in> \<int>"
[PROOF STATE]
proof (prove)
using this:
(rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) = rat_of_int k * inv_Z $$ (i, j)

goal (1 subgoal):
 1. rat_of_int k * inv_Z $$ (i, j) \<in> \<int>
[PROOF STEP]
using kinvZ_in_Z i j inv_Z mn
[PROOF STATE]
proof (prove)
using this:
(rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (i, j) = rat_of_int k * inv_Z $$ (i, j)
\<lbrakk>?i1 < m; ?j1 < n\<rbrakk> \<Longrightarrow> (rat_of_int k \<cdot>\<^sub>m inv_Z) $$ (?i1, ?j1) \<in> \<int>
i < dim_row inv_Z
j < dim_col inv_Z
inv_Z \<in> carrier_mat m m
m = n

goal (1 subgoal):
 1. rat_of_int k * inv_Z $$ (i, j) \<in> \<int>
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
rat_of_int k * inv_Z $$ (i, j) \<in> \<int>

goal (1 subgoal):
 1. \<And>i j. \<lbrakk>i < dim_row inv_Z; j < dim_col inv_Z\<rbrakk> \<Longrightarrow> rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
show "rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)
[PROOF STEP]
by (rule int_of_rat, insert kinvZ_in_Z', auto)
[PROOF STATE]
proof (state)
this:
rat_of_int (int_of_rat (rat_of_int k * inv_Z $$ (i, j))) = rat_of_int k * inv_Z $$ (i, j)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = rat_of_int k \<cdot>\<^sub>m inv_Z

goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
hence "?RAT (k \<cdot>\<^sub>m (1\<^sub>m m)) = ?RAT ((map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z))) * ?RAT ?Z"
[PROOF STATE]
proof (prove)
using this:
of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = rat_of_int k \<cdot>\<^sub>m inv_Z

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * of_int_hom.mat_hom (mat_of_rows n fs_init)
[PROOF STEP]
using r'
[PROOF STATE]
proof (prove)
using this:
of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = rat_of_int k \<cdot>\<^sub>m inv_Z
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = rat_of_int k \<cdot>\<^sub>m inv_Z * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * of_int_hom.mat_hom (mat_of_rows n fs_init)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * of_int_hom.mat_hom (mat_of_rows n fs_init)

goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
have "... = ?RAT ((map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z)) * ?Z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * of_int_hom.mat_hom (mat_of_rows n fs_init) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init)
[PROOF STEP]
by (metis RAT_fs_init adj_mat(1) k_inv_Z_eq_adj map_carrier_mat of_int_hom.mat_hom_mult)
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * of_int_hom.mat_hom (mat_of_rows n fs_init) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init)

goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
of_int_hom.mat_hom (k \<cdot>\<^sub>m 1\<^sub>m m) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init)

goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
[PROOF STEP]
by (rule of_int_hom.mat_hom_inj)
[PROOF STATE]
proof (state)
this:
k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init

goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init
[PROOF STEP]
proof (rule mat_mult_sub_lattice[OF _ fs_init])
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
 2. ?A \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
 3. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom ?A * mat_of_rows n fs_init
[PROOF STEP]
have rw: "of_int_hom.mat_hom (map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z))
      = map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)

goal (3 subgoals):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
 2. ?A \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
 3. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom ?A * mat_of_rows n fs_init
[PROOF STEP]
have "mat_of_rows n (Matrix.rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = (k \<cdot>\<^sub>m (1\<^sub>m m))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = k \<cdot>\<^sub>m 1\<^sub>m m
[PROOF STEP]
by (metis mn index_one_mat(3) index_smult_mat(3) mat_of_rows_rows)
[PROOF STATE]
proof (state)
this:
mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = k \<cdot>\<^sub>m 1\<^sub>m m

goal (3 subgoals):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
 2. ?A \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
 3. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom ?A * mat_of_rows n fs_init
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = k \<cdot>\<^sub>m 1\<^sub>m m

goal (3 subgoals):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
 2. ?A \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
 3. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom ?A * mat_of_rows n fs_init
[PROOF STEP]
have "... = of_int_hom.mat_hom (map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init
[PROOF STEP]
using r rw
[PROOF STATE]
proof (prove)
using this:
k \<cdot>\<^sub>m 1\<^sub>m m = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) * mat_of_rows n fs_init
of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) = map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)

goal (1 subgoal):
 1. k \<cdot>\<^sub>m 1\<^sub>m m = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
k \<cdot>\<^sub>m 1\<^sub>m m = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init

goal (3 subgoals):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
 2. ?A \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
 3. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom ?A * mat_of_rows n fs_init
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init
[PROOF STEP]
show "mat_of_rows n (Matrix.rows (k \<cdot>\<^sub>m 1\<^sub>m m))
      = of_int_hom.mat_hom (map_mat int_of_rat ((rat_of_int k) \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init"
[PROOF STATE]
proof (prove)
using this:
mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init

goal (1 subgoal):
 1. mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
mat_of_rows n (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) = of_int_hom.mat_hom (map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z)) * mat_of_rows n fs_init

goal (2 subgoals):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
 2. map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
[PROOF STEP]
show "set (Matrix.rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
[PROOF STEP]
using mn
[PROOF STATE]
proof (prove)
using this:
m = n

goal (1 subgoal):
 1. set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n
[PROOF STEP]
unfolding Matrix.rows_def
[PROOF STATE]
proof (prove)
using this:
m = n

goal (1 subgoal):
 1. set (map (row (k \<cdot>\<^sub>m 1\<^sub>m m)) [0..<dim_row (k \<cdot>\<^sub>m 1\<^sub>m m)]) \<subseteq> carrier_vec n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
set (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> carrier_vec n

goal (1 subgoal):
 1. map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
[PROOF STEP]
show "map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) \<in> carrier_mat (length (Matrix.rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
[PROOF STEP]
using len fs_init
[PROOF STATE]
proof (prove)
using this:
length fs_init = m
set fs_init \<subseteq> carrier_vec n

goal (1 subgoal):
 1. map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)
[PROOF STEP]
by (simp add: inv_Z)
[PROOF STATE]
proof (state)
this:
map_mat int_of_rat (rat_of_int k \<cdot>\<^sub>m inv_Z) \<in> carrier_mat (length (rows (k \<cdot>\<^sub>m 1\<^sub>m m))) (length fs_init)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
lattice_of (rows (k \<cdot>\<^sub>m 1\<^sub>m m)) \<subseteq> lattice_of fs_init

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma ord_nat_code [code_unfold]:
  "ord n a =
     (if n = 0 then if a = 1 then 1 else 0 else
        if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
proof (cases "coprime n a \<and> n > 0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
coprime n a \<and> 0 < n

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
define A where "A = {k\<in>{0<..n}. [a ^ k = 1] (mod n)}"
[PROOF STATE]
proof (state)
this:
A = {k \<in> {0<..n}. [a ^ k = 1] (mod n)}

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
define k where "k = (LEAST k. k > 0 \<and> [a ^ k = 1] (mod n))"
[PROOF STATE]
proof (state)
this:
k = (LEAST k. 0 < k \<and> [a ^ k = 1] (mod n))

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
have totient: "totient n \<in> A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. totient n \<in> A
[PROOF STEP]
using euler_theorem[of a n] True
[PROOF STATE]
proof (prove)
using this:
coprime a n \<Longrightarrow> [a ^ totient n = 1] (mod n)
coprime n a \<and> 0 < n

goal (1 subgoal):
 1. totient n \<in> A
[PROOF STEP]
by (auto simp: A_def coprime_commute intro!: Nat.gr0I totient_le)
[PROOF STATE]
proof (state)
this:
totient n \<in> A

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
totient n \<in> A

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
have "finite A"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite A
[PROOF STEP]
by (auto simp: A_def)
[PROOF STATE]
proof (state)
this:
finite A

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
totient n \<in> A
finite A
[PROOF STEP]
have *: "Min A \<in> A" and "\<forall>y. y \<in> A \<longrightarrow> Min A \<le> y"
[PROOF STATE]
proof (prove)
using this:
totient n \<in> A
finite A

goal (1 subgoal):
 1. Min A \<in> A &&& \<forall>y. y \<in> A \<longrightarrow> Min A \<le> y
[PROOF STEP]
by (auto intro: Min_in)
[PROOF STATE]
proof (state)
this:
Min A \<in> A
\<forall>y. y \<in> A \<longrightarrow> Min A \<le> y

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
have "k > 0 \<and> [a ^ k = 1] (mod n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < k \<and> [a ^ k = 1] (mod n)
[PROOF STEP]
unfolding k_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < (LEAST k. 0 < k \<and> [a ^ k = 1] (mod n)) \<and> [a ^ (LEAST k. 0 < k \<and> [a ^ k = 1] (mod n)) = 1] (mod n)
[PROOF STEP]
by (rule LeastI[of _ "totient n"]) (use totient in \<open>auto simp: A_def\<close>)
[PROOF STATE]
proof (state)
this:
0 < k \<and> [a ^ k = 1] (mod n)

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
0 < k \<and> [a ^ k = 1] (mod n)

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
have "k \<le> totient n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. k \<le> totient n
[PROOF STEP]
unfolding k_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (LEAST k. 0 < k \<and> [a ^ k = 1] (mod n)) \<le> totient n
[PROOF STEP]
by (intro Least_le) (use totient in \<open>auto simp: A_def\<close>)
[PROOF STATE]
proof (state)
this:
k \<le> totient n

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
0 < k \<and> [a ^ k = 1] (mod n)
k \<le> totient n
[PROOF STEP]
have "k \<in> A"
[PROOF STATE]
proof (prove)
using this:
0 < k \<and> [a ^ k = 1] (mod n)
k \<le> totient n

goal (1 subgoal):
 1. k \<in> A
[PROOF STEP]
using totient_le[of n]
[PROOF STATE]
proof (prove)
using this:
0 < k \<and> [a ^ k = 1] (mod n)
k \<le> totient n
totient n \<le> n

goal (1 subgoal):
 1. k \<in> A
[PROOF STEP]
by (auto simp: A_def)
[PROOF STATE]
proof (state)
this:
k \<in> A

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
hence "Min A \<le> k"
[PROOF STATE]
proof (prove)
using this:
k \<in> A

goal (1 subgoal):
 1. Min A \<le> k
[PROOF STEP]
by (intro Min_le) (auto simp: \<open>finite A\<close>)
[PROOF STATE]
proof (state)
this:
Min A \<le> k

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
Min A \<le> k

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
from *
[PROOF STATE]
proof (chain)
picking this:
Min A \<in> A
[PROOF STEP]
have "k \<le> Min A"
[PROOF STATE]
proof (prove)
using this:
Min A \<in> A

goal (1 subgoal):
 1. k \<le> Min A
[PROOF STEP]
unfolding k_def
[PROOF STATE]
proof (prove)
using this:
Min A \<in> A

goal (1 subgoal):
 1. (LEAST k. 0 < k \<and> [a ^ k = 1] (mod n)) \<le> Min A
[PROOF STEP]
by (intro Least_le) (auto simp: A_def)
[PROOF STATE]
proof (state)
this:
k \<le> Min A

goal (2 subgoals):
 1. coprime n a \<and> 0 < n \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
 2. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
Min A \<le> k
k \<le> Min A
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
Min A \<le> k
k \<le> Min A

goal (1 subgoal):
 1. ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
using True
[PROOF STATE]
proof (prove)
using this:
Min A \<le> k
k \<le> Min A
coprime n a \<and> 0 < n

goal (1 subgoal):
 1. ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
by (simp add: ord_def k_def A_def Set.filter_def)
[PROOF STATE]
proof (state)
this:
ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)

goal (1 subgoal):
 1. \<not> (coprime n a \<and> 0 < n) \<Longrightarrow> ord n a = (if n = 0 then if a = 1 then 1 else 0 else if coprime n a then Min (Set.filter (\<lambda>k. [a ^ k = 1] (mod n)) {0<..n}) else 0)
[PROOF STEP]
qed auto


[STATEMENT]
lemma sin_arg:
  assumes "z \<noteq> 0"
  shows "sin (Arg z) = Im z / cmod z"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sin (Arg z) = Im z / cmod z
[PROOF STEP]
by (metis Complex.Im_sgn cis.simps(2) assms cis_Arg)


[STATEMENT]
lemma signs_smash_property:
  fixes signs1 signs2 :: "'a list list"
  fixes a b:: "nat"
  shows "\<forall> (elem :: 'a list). (elem \<in> (set (signs_smash signs1 signs2)) \<longrightarrow>
    (\<exists> n m :: nat.
      elem = ((nth signs1 n)@(nth signs2 m))))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>elem. elem \<in> set (signs_smash signs1 signs2) \<longrightarrow> (\<exists>n m. elem = signs1 ! n @ signs2 ! m)
[PROOF STEP]
proof clarsimp
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>elem. elem \<in> set (signs_smash signs1 signs2) \<Longrightarrow> \<exists>n m. elem = signs1 ! n @ signs2 ! m
[PROOF STEP]
fix elem
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>elem. elem \<in> set (signs_smash signs1 signs2) \<Longrightarrow> \<exists>n m. elem = signs1 ! n @ signs2 ! m
[PROOF STEP]
assume assum: "elem \<in> set (signs_smash signs1 signs2)"
[PROOF STATE]
proof (state)
this:
elem \<in> set (signs_smash signs1 signs2)

goal (1 subgoal):
 1. \<And>elem. elem \<in> set (signs_smash signs1 signs2) \<Longrightarrow> \<exists>n m. elem = signs1 ! n @ signs2 ! m
[PROOF STEP]
show "\<exists>n m. elem = signs1 ! n @ signs2 ! m"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>n m. elem = signs1 ! n @ signs2 ! m
[PROOF STEP]
using assum
[PROOF STATE]
proof (prove)
using this:
elem \<in> set (signs_smash signs1 signs2)

goal (1 subgoal):
 1. \<exists>n m. elem = signs1 ! n @ signs2 ! m
[PROOF STEP]
unfolding signs_smash_def
[PROOF STATE]
proof (prove)
using this:
elem \<in> set (concat (map (\<lambda>l1. map ((@) l1) signs2) signs1))

goal (1 subgoal):
 1. \<exists>n m. elem = signs1 ! n @ signs2 ! m
[PROOF STEP]
apply (auto)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x xa. \<lbrakk>x \<in> set signs1; xa \<in> set signs2; elem = x @ xa\<rbrakk> \<Longrightarrow> \<exists>n m. x @ xa = signs1 ! n @ signs2 ! m
[PROOF STEP]
by (metis in_set_conv_nth)
[PROOF STATE]
proof (state)
this:
\<exists>n m. elem = signs1 ! n @ signs2 ! m

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma rk_split_card_takeWhile:
  assumes "x \<in> set xs"
  assumes "distinct xs"
  shows "rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
obtain ys zs where "xs = ys @ x # zs" and "x \<notin> set ys"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>ys zs. \<lbrakk>xs = ys @ x # zs; x \<notin> set ys\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
x \<in> set xs
distinct xs

goal (1 subgoal):
 1. (\<And>ys zs. \<lbrakk>xs = ys @ x # zs; x \<notin> set ys\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (blast dest: split_list_first)
[PROOF STATE]
proof (state)
this:
xs = ys @ x # zs
x \<notin> set ys

goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
xs = ys @ x # zs
x \<notin> set ys

goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
hence "distinct ys" and "ys = takeWhile (\<lambda>y. y \<noteq> x) xs"
[PROOF STATE]
proof (prove)
using this:
xs = ys @ x # zs
x \<notin> set ys

goal (1 subgoal):
 1. distinct ys &&& ys = takeWhile (\<lambda>y. y \<noteq> x) xs
[PROOF STEP]
using takeWhile_foo assms
[PROOF STATE]
proof (prove)
using this:
xs = ys @ x # zs
x \<notin> set ys
?x \<notin> set ?ys \<Longrightarrow> ?ys = takeWhile (\<lambda>y. y \<noteq> ?x) (?ys @ ?x # ?zs)
x \<in> set xs
distinct xs

goal (1 subgoal):
 1. distinct ys &&& ys = takeWhile (\<lambda>y. y \<noteq> x) xs
[PROOF STEP]
by (simp, fast)
[PROOF STATE]
proof (state)
this:
distinct ys
ys = takeWhile (\<lambda>y. y \<noteq> x) xs

goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
xs = ys @ x # zs
x \<notin> set ys
distinct ys
ys = takeWhile (\<lambda>y. y \<noteq> x) xs
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
xs = ys @ x # zs
x \<notin> set ys
distinct ys
ys = takeWhile (\<lambda>y. y \<noteq> x) xs

goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
using rk_split_card
[PROOF STATE]
proof (prove)
using this:
xs = ys @ x # zs
x \<notin> set ys
distinct ys
ys = takeWhile (\<lambda>y. y \<noteq> x) xs
\<lbrakk>?y \<notin> set ?xs; distinct ?xs\<rbrakk> \<Longrightarrow> rk (?xs @ ?y # ?zs) ?y = Some (card (set ?xs))

goal (1 subgoal):
 1. rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
rk xs x = Some (card (set (takeWhile (\<lambda>y. y \<noteq> x) xs)))

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma nth_least_nth_least[simp]:
    assumes "enat n < esize A" "\<And> i. i \<in> A \<Longrightarrow> enat i < esize B"
    shows "nth_least B (nth_least A n) = nth_least (nth_least B ` A) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least B (nth_least A n) = nth_least (nth_least B ` A) n
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
enat n < esize A
?i \<in> A \<Longrightarrow> enat ?i < esize B

goal (1 subgoal):
 1. nth_least B (nth_least A n) = nth_least (nth_least B ` A) n
[PROOF STEP]
proof (induct n arbitrary: A)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<And>A. \<lbrakk>enat 0 < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A 0) = nth_least (nth_least B ` A) 0
 2. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
case 0
[PROOF STATE]
proof (state)
this:
enat 0 < esize A
?i \<in> A \<Longrightarrow> enat ?i < esize B

goal (2 subgoals):
 1. \<And>A. \<lbrakk>enat 0 < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A 0) = nth_least (nth_least B ` A) 0
 2. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least B (nth_least A 0) = nth_least (nth_least B ` A) 0
[PROOF STEP]
using 0
[PROOF STATE]
proof (prove)
using this:
enat 0 < esize A
?i \<in> A \<Longrightarrow> enat ?i < esize B

goal (1 subgoal):
 1. nth_least B (nth_least A 0) = nth_least (nth_least B ` A) 0
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
nth_least B (nth_least A 0) = nth_least (nth_least B ` A) 0

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
case (Suc n)
[PROOF STATE]
proof (state)
this:
\<lbrakk>enat n < esize ?A; \<And>i. i \<in> ?A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least ?A n) = nth_least (nth_least B ` ?A) n
enat (Suc n) < esize A
?i \<in> A \<Longrightarrow> enat ?i < esize B

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have 1: "A \<noteq> {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A \<noteq> {}
[PROOF STEP]
using Suc(2)
[PROOF STATE]
proof (prove)
using this:
enat (Suc n) < esize A

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

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have 2: "nth_least B ` (A - {least A}) = nth_least B ` A - nth_least B ` {least A}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least B ` (A - {least A}) = nth_least B ` A - nth_least B ` {least A}
[PROOF STEP]
proof (rule inj_on_image_set_diff)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. inj_on (nth_least B) ?C
 2. A - {least A} \<subseteq> ?C
 3. {least A} \<subseteq> ?C
[PROOF STEP]
show "inj_on (nth_least B) {i. enat i < esize B}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on (nth_least B) {i. enat i < esize B}
[PROOF STEP]
using nth_least.inj_on
[PROOF STATE]
proof (prove)
using this:
inj_on (nth_least ?A) {i. enat i < esize ?A}

goal (1 subgoal):
 1. inj_on (nth_least B) {i. enat i < esize B}
[PROOF STEP]
by this
[PROOF STATE]
proof (state)
this:
inj_on (nth_least B) {i. enat i < esize B}

goal (2 subgoals):
 1. A - {least A} \<subseteq> {i. enat i < esize B}
 2. {least A} \<subseteq> {i. enat i < esize B}
[PROOF STEP]
show "A - {least A} \<subseteq> {i. enat i < esize B}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. A - {least A} \<subseteq> {i. enat i < esize B}
[PROOF STEP]
using Suc(3)
[PROOF STATE]
proof (prove)
using this:
?i \<in> A \<Longrightarrow> enat ?i < esize B

goal (1 subgoal):
 1. A - {least A} \<subseteq> {i. enat i < esize B}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
A - {least A} \<subseteq> {i. enat i < esize B}

goal (1 subgoal):
 1. {least A} \<subseteq> {i. enat i < esize B}
[PROOF STEP]
show "{least A} \<subseteq> {i. enat i < esize B}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {least A} \<subseteq> {i. enat i < esize B}
[PROOF STEP]
using Suc(3) 1
[PROOF STATE]
proof (prove)
using this:
?i \<in> A \<Longrightarrow> enat ?i < esize B
A \<noteq> {}

goal (1 subgoal):
 1. {least A} \<subseteq> {i. enat i < esize B}
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
{least A} \<subseteq> {i. enat i < esize B}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
nth_least B ` (A - {least A}) = nth_least B ` A - nth_least B ` {least A}

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have "nth_least B (nth_least A (Suc n)) = nth_least B (nth_least (A - {least A}) n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least B (nth_least A (Suc n)) = nth_least B (nth_least (A - {least A}) n)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
nth_least B (nth_least A (Suc n)) = nth_least B (nth_least (A - {least A}) n)

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
nth_least B (nth_least A (Suc n)) = nth_least B (nth_least (A - {least A}) n)

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have "\<dots> = nth_least (nth_least B ` (A - {least A})) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least B (nth_least (A - {least A}) n) = nth_least (nth_least B ` (A - {least A})) n
[PROOF STEP]
using Suc 1
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>enat n < esize ?A; \<And>i. i \<in> ?A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least ?A n) = nth_least (nth_least B ` ?A) n
enat (Suc n) < esize A
?i \<in> A \<Longrightarrow> enat ?i < esize B
A \<noteq> {}

goal (1 subgoal):
 1. nth_least B (nth_least (A - {least A}) n) = nth_least (nth_least B ` (A - {least A})) n
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
nth_least B (nth_least (A - {least A}) n) = nth_least (nth_least B ` (A - {least A})) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
nth_least B (nth_least (A - {least A}) n) = nth_least (nth_least B ` (A - {least A})) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have "\<dots> = nth_least (nth_least B ` A - nth_least B ` {least A}) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least (nth_least B ` (A - {least A})) n = nth_least (nth_least B ` A - nth_least B ` {least A}) n
[PROOF STEP]
unfolding 2
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least (nth_least B ` A - nth_least B ` {least A}) n = nth_least (nth_least B ` A - nth_least B ` {least A}) n
[PROOF STEP]
by rule
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` (A - {least A})) n = nth_least (nth_least B ` A - nth_least B ` {least A}) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` (A - {least A})) n = nth_least (nth_least B ` A - nth_least B ` {least A}) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have "\<dots> = nth_least (nth_least B ` A - {nth_least B (least A)}) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least (nth_least B ` A - nth_least B ` {least A}) n = nth_least (nth_least B ` A - {nth_least B (least A)}) n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` A - nth_least B ` {least A}) n = nth_least (nth_least B ` A - {nth_least B (least A)}) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` A - nth_least B ` {least A}) n = nth_least (nth_least B ` A - {nth_least B (least A)}) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have "\<dots> = nth_least (nth_least B ` A - {least (nth_least B ` A)}) n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least (nth_least B ` A - {nth_least B (least A)}) n = nth_least (nth_least B ` A - {least (nth_least B ` A)}) n
[PROOF STEP]
using Suc(3) 1
[PROOF STATE]
proof (prove)
using this:
?i \<in> A \<Longrightarrow> enat ?i < esize B
A \<noteq> {}

goal (1 subgoal):
 1. nth_least (nth_least B ` A - {nth_least B (least A)}) n = nth_least (nth_least B ` A - {least (nth_least B ` A)}) n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` A - {nth_least B (least A)}) n = nth_least (nth_least B ` A - {least (nth_least B ` A)}) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` A - {nth_least B (least A)}) n = nth_least (nth_least B ` A - {least (nth_least B ` A)}) n

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
have "\<dots> = nth_least (nth_least B ` A) (Suc n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. nth_least (nth_least B ` A - {least (nth_least B ` A)}) n = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
nth_least (nth_least B ` A - {least (nth_least B ` A)}) n = nth_least (nth_least B ` A) (Suc n)

goal (1 subgoal):
 1. \<And>n A. \<lbrakk>\<And>A. \<lbrakk>enat n < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A n) = nth_least (nth_least B ` A) n; enat (Suc n) < esize A; \<And>i. i \<in> A \<Longrightarrow> enat i < esize B\<rbrakk> \<Longrightarrow> nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
show ?case
[PROOF STATE]
proof (prove)
using this:
nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)

goal (1 subgoal):
 1. nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)
[PROOF STEP]
by this
[PROOF STATE]
proof (state)
this:
nth_least B (nth_least A (Suc n)) = nth_least (nth_least B ` A) (Suc n)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma pairwise_intersect_finite:
  assumes "finite As"
  assumes "finite Bs"
  shows "finite (pairwise_intersect As Bs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite (pairwise_intersect As Bs)
[PROOF STEP]
proof-
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. finite (pairwise_intersect As Bs)
[PROOF STEP]
have 0: "(pairwise_intersect As Bs) = (\<Union> a \<in> As. (\<inter>) a ` Bs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. pairwise_intersect As Bs = (\<Union>a\<in>As. (\<inter>) a ` Bs)
[PROOF STEP]
unfolding pairwise_intersect_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {c. \<exists>a\<in>As. \<exists>b\<in>Bs. c = a \<inter> b} = (\<Union>a\<in>As. (\<inter>) a ` Bs)
[PROOF STEP]
apply(rule equalityI')
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>x. x \<in> {c. \<exists>a\<in>As. \<exists>b\<in>Bs. c = a \<inter> b} \<Longrightarrow> x \<in> (\<Union>a\<in>As. (\<inter>) a ` Bs)
 2. \<And>x. x \<in> (\<Union>a\<in>As. (\<inter>) a ` Bs) \<Longrightarrow> x \<in> {c. \<exists>a\<in>As. \<exists>b\<in>Bs. c = a \<inter> b}
[PROOF STEP]
unfolding mem_Collect_eq
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>x. \<exists>a\<in>As. \<exists>b\<in>Bs. x = a \<inter> b \<Longrightarrow> x \<in> (\<Union>a\<in>As. (\<inter>) a ` Bs)
 2. \<And>x. x \<in> (\<Union>a\<in>As. (\<inter>) a ` Bs) \<Longrightarrow> \<exists>a\<in>As. \<exists>b\<in>Bs. x = a \<inter> b
[PROOF STEP]
apply blast
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x. x \<in> (\<Union>a\<in>As. (\<inter>) a ` Bs) \<Longrightarrow> \<exists>a\<in>As. \<exists>b\<in>Bs. x = a \<inter> b
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
pairwise_intersect As Bs = (\<Union>a\<in>As. (\<inter>) a ` Bs)

goal (1 subgoal):
 1. finite (pairwise_intersect As Bs)
[PROOF STEP]
have 1: "\<And>a. a \<in> As \<Longrightarrow> finite ((\<inter>) a ` Bs)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a. a \<in> As \<Longrightarrow> finite ((\<inter>) a ` Bs)
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
finite As
finite Bs

goal (1 subgoal):
 1. \<And>a. a \<in> As \<Longrightarrow> finite ((\<inter>) a ` Bs)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
?a \<in> As \<Longrightarrow> finite ((\<inter>) ?a ` Bs)

goal (1 subgoal):
 1. finite (pairwise_intersect As Bs)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite (pairwise_intersect As Bs)
[PROOF STEP]
unfolding 0
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite (\<Union>a\<in>As. (\<inter>) a ` Bs)
[PROOF STEP]
using assms(1) 1
[PROOF STATE]
proof (prove)
using this:
finite As
?a \<in> As \<Longrightarrow> finite ((\<inter>) ?a ` Bs)

goal (1 subgoal):
 1. finite (\<Union>a\<in>As. (\<inter>) a ` Bs)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
finite (pairwise_intersect As Bs)

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma symetric:
  fixes P :: pi
  and   Q :: pi

  assumes "P \<simeq> Q"

  shows "Q \<simeq> P"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Q \<simeq> P
[PROOF STEP]
using assms
[PROOF STATE]
proof (prove)
using this:
P \<simeq> Q

goal (1 subgoal):
 1. Q \<simeq> P
[PROOF STEP]
by(force simp add: substClosed_def weakCongruence_def)


[STATEMENT]
lemma open_segment_separate_left:
  fixes u v x a b::'a
  assumes u:"u \<in> {a <--< b}"
  assumes v:"v \<in> {u <--< b}"
  assumes x: "dist x u < dist u v" "x \<in> {a <--< b}"
  shows "x \<in> {a <--< v}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
have "v \<noteq> x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. v \<noteq> x
[PROOF STEP]
by (smt dist_commute x(1))
[PROOF STATE]
proof (state)
this:
v \<noteq> x

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
v \<noteq> x

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
have "x \<notin> {v<--<b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<notin> {v<--<b}
[PROOF STEP]
by (smt dist_commute dist_in_open_segment open_segment_subsegment v x(1))
[PROOF STATE]
proof (state)
this:
x \<notin> {v<--<b}

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
x \<notin> {v<--<b}

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
have "v \<in> {a<--<b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. v \<in> {a<--<b}
[PROOF STEP]
using v
[PROOF STATE]
proof (prove)
using this:
v \<in> {u<--<b}

goal (1 subgoal):
 1. v \<in> {a<--<b}
[PROOF STEP]
by (metis ends_in_segment(1) segment_open_subset_closed subset_eq subset_segment(4) u)
[PROOF STATE]
proof (state)
this:
v \<in> {a<--<b}

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
v \<noteq> x
x \<notin> {v<--<b}
v \<in> {a<--<b}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
v \<noteq> x
x \<notin> {v<--<b}
v \<in> {a<--<b}

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
using open_segment_trichotomy[OF _ x(2)]
[PROOF STATE]
proof (prove)
using this:
v \<noteq> x
x \<notin> {v<--<b}
v \<in> {a<--<b}
?x \<in> {a<--<b} \<Longrightarrow> ?x = x \<or> x \<in> {?x<--<b} \<or> x \<in> {a<--<?x}

goal (1 subgoal):
 1. x \<in> {a<--<v}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
x \<in> {a<--<v}

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma Cauchy_Schwarz_strict_ineq2:
  "\<bar>inner x y\<bar> < norm x * norm y" if "y \<noteq> 0" "\<And>k. x \<noteq> k *\<^sub>R y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>x \<bullet> y\<bar> < norm x * norm y
[PROOF STEP]
apply (rule neq_le_trans)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<bar>x \<bullet> y\<bar> \<noteq> norm x * norm y
 2. \<bar>x \<bullet> y\<bar> \<le> norm x * norm y
[PROOF STEP]
subgoal
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>x \<bullet> y\<bar> \<noteq> norm x * norm y
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
y \<noteq> (0::'a)
x \<noteq> ?k *\<^sub>R y

goal (1 subgoal):
 1. \<bar>x \<bullet> y\<bar> \<noteq> norm x * norm y
[PROOF STEP]
unfolding Cauchy_Schwarz_eq2_iff
[PROOF STATE]
proof (prove)
using this:
y \<noteq> (0::'a)
x \<noteq> ?k *\<^sub>R y

goal (1 subgoal):
 1. \<not> ((\<exists>k. x = k *\<^sub>R y) \<or> y = (0::'a))
[PROOF STEP]
by auto
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>x \<bullet> y\<bar> \<le> norm x * norm y
[PROOF STEP]
subgoal
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>x \<bullet> y\<bar> \<le> norm x * norm y
[PROOF STEP]
by (rule Cauchy_Schwarz_ineq2)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done


[STATEMENT]
lemma prod_list_het0:
  shows "x\<noteq>[] \<and> het x = 0 \<Longrightarrow> \<Prod>:x = (mean x) ^ (length x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
assume "x\<noteq>[] \<and> het x = 0"
[PROOF STATE]
proof (state)
this:
x \<noteq> [] \<and> het x = 0

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
hence xne: "x\<noteq>[]" and hetx: "het x = 0"
[PROOF STATE]
proof (prove)
using this:
x \<noteq> [] \<and> het x = 0

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

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
from hetx
[PROOF STATE]
proof (chain)
picking this:
het x = 0
[PROOF STEP]
have lz: "length (list_neq x (mean x)) = 0"
[PROOF STATE]
proof (prove)
using this:
het x = 0

goal (1 subgoal):
 1. length (list_neq x (mean x)) = 0
[PROOF STEP]
unfolding het_def
[PROOF STATE]
proof (prove)
using this:
length (list_neq x (mean x)) = 0

goal (1 subgoal):
 1. length (list_neq x (mean x)) = 0
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
length (list_neq x (mean x)) = 0

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
hence "\<Prod>:(list_neq x (mean x)) = 1"
[PROOF STATE]
proof (prove)
using this:
length (list_neq x (mean x)) = 0

goal (1 subgoal):
 1. prod_list (list_neq x (mean x)) = 1
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
prod_list (list_neq x (mean x)) = 1

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
with prod_list_split
[PROOF STATE]
proof (chain)
picking this:
prod_list ?xs = prod_list (list_neq ?xs ?m) * prod_list (list_eq ?xs ?m)
prod_list (list_neq x (mean x)) = 1
[PROOF STEP]
have "\<Prod>:x = \<Prod>:(list_eq x (mean x))"
[PROOF STATE]
proof (prove)
using this:
prod_list ?xs = prod_list (list_neq ?xs ?m) * prod_list (list_eq ?xs ?m)
prod_list (list_neq x (mean x)) = 1

goal (1 subgoal):
 1. prod_list x = prod_list (list_eq x (mean x))
[PROOF STEP]
apply -
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>\<And>xs m. prod_list xs = prod_list (list_neq xs m) * prod_list (list_eq xs m); prod_list (list_neq x (mean x)) = 1\<rbrakk> \<Longrightarrow> prod_list x = prod_list (list_eq x (mean x))
[PROOF STEP]
apply (drule meta_spec [of _ x])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>prod_list (list_neq x (mean x)) = 1; \<And>m. prod_list x = prod_list (list_neq x m) * prod_list (list_eq x m)\<rbrakk> \<Longrightarrow> prod_list x = prod_list (list_eq x (mean x))
[PROOF STEP]
apply (drule meta_spec [of _ "mean x"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>prod_list (list_neq x (mean x)) = 1; prod_list x = prod_list (list_neq x (mean x)) * prod_list (list_eq x (mean x))\<rbrakk> \<Longrightarrow> prod_list x = prod_list (list_eq x (mean x))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
prod_list x = prod_list (list_eq x (mean x))

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
prod_list x = prod_list (list_eq x (mean x))

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
with list_eq_prod
[PROOF STATE]
proof (chain)
picking this:
prod_list (list_eq ?xs ?m) = ?m ^ length (list_eq ?xs ?m)
prod_list x = prod_list (list_eq x (mean x))
[PROOF STEP]
have
    "\<dots> = (mean x) ^ (length (list_eq x (mean x)))"
[PROOF STATE]
proof (prove)
using this:
prod_list (list_eq ?xs ?m) = ?m ^ length (list_eq ?xs ?m)
prod_list x = prod_list (list_eq x (mean x))

goal (1 subgoal):
 1. prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x))

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x))

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
with calculation lz sum_list_length_split
[PROOF STATE]
proof (chain)
picking this:
prod_list x = mean x ^ length (list_eq x (mean x))
length (list_neq x (mean x)) = 0
length ?xs = length (list_neq ?xs ?m) + length (list_eq ?xs ?m)
prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x))
[PROOF STEP]
have
    "\<Prod>:x = (mean x) ^ (length x)"
[PROOF STATE]
proof (prove)
using this:
prod_list x = mean x ^ length (list_eq x (mean x))
length (list_neq x (mean x)) = 0
length ?xs = length (list_neq ?xs ?m) + length (list_eq ?xs ?m)
prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x))

goal (1 subgoal):
 1. prod_list x = mean x ^ length x
[PROOF STEP]
apply -
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>prod_list x = mean x ^ length (list_eq x (mean x)); length (list_neq x (mean x)) = 0; \<And>xs m. length xs = length (list_neq xs m) + length (list_eq xs m); prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x))\<rbrakk> \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
apply (drule meta_spec [of _ x])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>prod_list x = mean x ^ length (list_eq x (mean x)); length (list_neq x (mean x)) = 0; prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x)); \<And>m. length x = length (list_neq x m) + length (list_eq x m)\<rbrakk> \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
apply (drule meta_spec [of _ "mean x"])
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>prod_list x = mean x ^ length (list_eq x (mean x)); length (list_neq x (mean x)) = 0; prod_list (list_eq x (mean x)) = mean x ^ length (list_eq x (mean x)); length x = length (list_neq x (mean x)) + length (list_eq x (mean x))\<rbrakk> \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
prod_list x = mean x ^ length x

goal (1 subgoal):
 1. x \<noteq> [] \<and> het x = 0 \<Longrightarrow> prod_list x = mean x ^ length x
[PROOF STEP]
thus ?thesis
[PROOF STATE]
proof (prove)
using this:
prod_list x = mean x ^ length x

goal (1 subgoal):
 1. prod_list x = mean x ^ length x
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
prod_list x = mean x ^ length x

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma replace_comp_stocks:
  assumes "support_set pf1 \<subseteq> stocks Mkt \<union> {x}"
  and "support_set pf2 \<subseteq> stocks Mkt"
shows "support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt
[PROOF STEP]
have "support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt
[PROOF STEP]
using assms(1) remove_comp_support_set
[PROOF STATE]
proof (prove)
using this:
support_set pf1 \<subseteq> stocks Mkt \<union> {x}
support_set (qty_rem_comp ?pf1.0 ?x) \<subseteq> support_set ?pf1.0 - {?x}

goal (1 subgoal):
 1. support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt

goal (1 subgoal):
 1. support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt

goal (1 subgoal):
 1. support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt
[PROOF STEP]
have "support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt
[PROOF STEP]
using assms mult_comp_support_set
[PROOF STATE]
proof (prove)
using this:
support_set pf1 \<subseteq> stocks Mkt \<union> {x}
support_set pf2 \<subseteq> stocks Mkt
support_set (qty_mult_comp ?pf1.0 ?qty) \<subseteq> support_set ?pf1.0

goal (1 subgoal):
 1. support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt

goal (1 subgoal):
 1. support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt
support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt
support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt

goal (1 subgoal):
 1. support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt
[PROOF STEP]
unfolding qty_replace_comp_def
[PROOF STATE]
proof (prove)
using this:
support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt
support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt

goal (1 subgoal):
 1. support_set (qty_sum (qty_rem_comp pf1 x) (qty_mult_comp pf2 (pf1 x))) \<subseteq> stocks Mkt
[PROOF STEP]
using sum_support_set
[PROOF STATE]
proof (prove)
using this:
support_set (qty_rem_comp pf1 x) \<subseteq> stocks Mkt
support_set (qty_mult_comp pf2 (pf1 x)) \<subseteq> stocks Mkt
support_set (qty_sum ?pf1.0 ?pf2.0) \<subseteq> support_set ?pf1.0 \<union> support_set ?pf2.0

goal (1 subgoal):
 1. support_set (qty_sum (qty_rem_comp pf1 x) (qty_mult_comp pf2 (pf1 x))) \<subseteq> stocks Mkt
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
support_set (qty_replace_comp pf1 x pf2) \<subseteq> stocks Mkt

goal:
No subgoals!
[PROOF STEP]
qed


[STATEMENT]
lemma card_mnm:
  assumes \<open>m < n\<close>
    shows \<open>card {i::nat. i < n \<and> P i}
         = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
have 1:\<open>{i::nat. i \<le> m \<and> P i} \<inter> {i. m < i \<and> i < n \<and> P i} = {}\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {i. i \<le> m \<and> P i} \<inter> {i. m < i \<and> i < n \<and> P i} = {}
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
{i. i \<le> m \<and> P i} \<inter> {i. m < i \<and> i < n \<and> P i} = {}

goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
from assms
[PROOF STATE]
proof (chain)
picking this:
m < n
[PROOF STEP]
have \<open>\<forall>i::nat. i < n = (i \<le> m) \<or> (m < i \<and> i < n)\<close>
[PROOF STATE]
proof (prove)
using this:
m < n

goal (1 subgoal):
 1. \<forall>i. (i < n) = (i \<le> m) \<or> m < i \<and> i < n
[PROOF STEP]
using less_trans
[PROOF STATE]
proof (prove)
using this:
m < n
\<lbrakk>?x < ?y; ?y < ?z\<rbrakk> \<Longrightarrow> ?x < ?z

goal (1 subgoal):
 1. \<forall>i. (i < n) = (i \<le> m) \<or> m < i \<and> i < n
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<forall>i. (i < n) = (i \<le> m) \<or> m < i \<and> i < n

goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
hence 2:
    \<open>{i::nat. i < n \<and> P i} = {i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}\<close>
[PROOF STATE]
proof (prove)
using this:
\<forall>i. (i < n) = (i \<le> m) \<or> m < i \<and> i < n

goal (1 subgoal):
 1. {i. i < n \<and> P i} = {i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
{i. i < n \<and> P i} = {i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}

goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
have 3:\<open>finite {i. i \<le> m \<and> P i}\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite {i. i \<le> m \<and> P i}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
finite {i. i \<le> m \<and> P i}

goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
have 4:\<open>finite {i. m < i \<and> i < n \<and> P i}\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
finite {i. m < i \<and> i < n \<and> P i}

goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
from card_Un_disjoint[OF 3 4 1] 2
[PROOF STATE]
proof (chain)
picking this:
card ({i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}) = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
{i. i < n \<and> P i} = {i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
card ({i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}) = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
{i. i < n \<and> P i} = {i. i \<le> m \<and> P i} \<union> {i. m < i \<and> i < n \<and> P i}

goal (1 subgoal):
 1. card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
card {i. i < n \<and> P i} = card {i. i \<le> m \<and> P i} + card {i. m < i \<and> i < n \<and> P i}

goal:
No subgoals!
[PROOF STEP]
qed