theory linear_map imports Main begin locale linear_map_setup = fixes zeroV :: "'v" and addV :: "'v \ 'v \ 'v" (infixl "+V" 65) and smul :: "'r \ 'v \ 'v" (infixr "\V" 70) and zeroW :: "'w" and addW :: "'w \ 'w \ 'w" (infixl "+W" 65) and smulW :: "'r \ 'w \ 'w" (infixr "\W" 70) and toFun :: "'v \ 'w" assumes addV_comm : "\u v. u +V v = v +V u" and addV_assoc : "\u v w. (u +V v) +V w = u +V (v +V w)" and addV_zero : "\u. u +V zeroV = u" and smul_zeroV : "\a. a \V zeroV = zeroV" and addW_comm : "\u v. u +W v = v +W u" and addW_assoc : "\u v w. (u +W v) +W w = u +W (v +W w)" and addW_zero : "\u. u +W zeroW = u" and smulW_zero : "\a. a \W zeroW = zeroW" and map_add : "\u v. toFun (u +V v) = toFun u +W toFun v" and map_smul : "\a u. toFun (a \V u) = a \W toFun u" begin definition ker :: "'v \ bool" where "ker x \ toFun x = zeroW" definition im :: "'w \ bool" where "im y \ \x. toFun x = y" lemma ker_add: assumes "ker x" "ker y" shows "ker (x +V y)" proof - have "toFun (x +V y) = toFun x +W toFun y" by (rule map_add) also have "\ = zeroW +W zeroW" using assms unfolding ker_def by simp also have "\ = zeroW" by (simp add: addW_comm addW_zero) finally show ?thesis unfolding ker_def . qed lemma ker_smul: assumes "ker x" shows "ker (a \V x)" unfolding ker_def using assms unfolding ker_def by (simp add: map_smul smulW_zero) lemma im_add: assumes "im y" "im z" shows "im (y +W z)" proof - from assms(1) obtain x where hx : "toFun x = y" unfolding im_def by blast from assms(2) obtain x' where hx' : "toFun x' = z" unfolding im_def by blast have "toFun (x +V x') = toFun x +W toFun x'" by (rule map_add) with hx hx' show ?thesis unfolding im_def by blast qed lemma im_smul: assumes "im y" shows "im (a \W y)" proof - from assms obtain x where hx : "toFun x = y" unfolding im_def by blast have "toFun (a \V x) = a \W toFun x" by (rule map_smul) with hx show ?thesis unfolding im_def by blast qed end end