This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit 3d6e3774 authored by nipkow's avatar nipkow
Browse files

adapted to devel

parent a47dee63e525
......@@ -53,24 +53,24 @@ shows "row (all1_matrix nr nc) i = all1_vec nc"
by (simp add: all1_matrix_def all1_vec_def)
lemma all1_vec_scalar_prod:
shows "all1_vec (length xs) \<bullet> (vec_of_list xs) = listsum xs"
shows "all1_vec (length xs) \<bullet> (vec_of_list xs) = sum_list xs"
proof -
have "all1_vec (length xs) \<bullet> (vec_of_list xs) = (\<Sum>i = 0..<dim\<^sub>v (vec_of_list xs). vec_of_list xs $ i)"
unfolding scalar_prod_def by (metis (no_types, lifting) all1_vec_def mult_cancel_right1 setsum_ivl_cong
unfolding scalar_prod_def by (metis (no_types, lifting) all1_vec_def mult_cancel_right1 sum_ivl_cong
vec.abs_eq vec_dim_vec vec_index_vec vec_of_list.abs_eq)
also have "... = (\<Sum>i = 0..<length xs. xs ! i)" using vec.abs_eq vec_dim_vec vec_of_list.abs_eq
by (metis setsum_ivl_cong vec_index_vec)
also have "... = listsum xs" by (simp add: listsum_setsum_nth)
by (metis sum_ivl_cong vec_index_vec)
also have "... = sum_list xs" by (simp add: sum_list_sum_nth)
finally show ?thesis by auto
qed
lemma mult_all1_matrix:
assumes "i < nr"
shows "((all1_matrix nr (dim\<^sub>v v)) \<otimes>\<^sub>m\<^sub>v v) $ i = listsum (list_of_vec v)" (is "?a $ i = listsum (list_of_vec v)")
shows "((all1_matrix nr (dim\<^sub>v v)) \<otimes>\<^sub>m\<^sub>v v) $ i = sum_list (list_of_vec v)" (is "?a $ i = sum_list (list_of_vec v)")
proof -
have "?a $ i = row (all1_matrix nr (dim\<^sub>v v)) i \<bullet> v" using index_mat_mult_vec assms all1_matrix_dim by auto
also have "... = listsum (list_of_vec v)" unfolding row_all1_matrix[OF assms] using all1_vec_scalar_prod[of "list_of_vec v"]
also have "... = sum_list (list_of_vec v)" unfolding row_all1_matrix[OF assms] using all1_vec_scalar_prod[of "list_of_vec v"]
by (metis vec.abs_eq vec_dim_vec vec_list vec_of_list.abs_eq)
finally show ?thesis by auto
qed
......
......@@ -161,7 +161,7 @@ assumes "valid_net' m"
and "input_sizes m = map dim\<^sub>v input"
and "i<nr"
shows "evaluate_net (Conv (all1_matrix nr (output_size' m)) m) input $ i
= Groups_List.listsum (list_of_vec (evaluate_net m input))"
= Groups_List.sum_list (list_of_vec (evaluate_net m input))"
unfolding evaluate_net.simps output_size_correct[OF assms(1) assms(2)[symmetric]]
using mult_all1_matrix[OF `i<nr`, of "evaluate_net m input", unfolded dim_vec_of_list]
assms(3) all1_matrix_dim(1) by metis
......@@ -191,16 +191,16 @@ proof (rule tensor_lookup_eqI)
have "Tensor.lookup (?a $ i) is = evaluate_net Convm (base_input Convm is) $ i"
using lookup_tensors_from_net[OF `valid_net' Convm` `is \<lhd> input_sizes Convm` `i< output_size' Convm`]
by (metis Convm_def )
also have "... = monoid_add_class.listsum (list_of_vec (evaluate_net m (base_input Convm is)))"
also have "... = monoid_add_class.sum_list (list_of_vec (evaluate_net m (base_input Convm is)))"
using evaluate_net_Conv_all1 Convm_def \<open>is \<lhd> input_sizes Convm\<close> assms base_input_length \<open>i < nr\<close>
by simp
also have "... = monoid_add_class.listsum (list_of_vec (map\<^sub>v (\<lambda>A. lookup A is)(tensors_from_net m)))"
also have "... = monoid_add_class.sum_list (list_of_vec (map\<^sub>v (\<lambda>A. lookup A is)(tensors_from_net m)))"
unfolding `base_input Convm is = base_input m is`
using lookup_tensors_from_net[OF `valid_net' m` `is \<lhd> input_sizes m`]
base_input_length[OF \<open>is \<lhd> input_sizes m\<close>] output_size_correct[OF assms(1)] output_size_correct_tensors[OF assms(1)]
vec_eqI[of "evaluate_net m (base_input m is)" "map\<^sub>v (\<lambda>A. lookup A is) (tensors_from_net m)"] vec_index_map(1) vec_index_map(2)
by force
also have "... = monoid_add_class.listsum (map (\<lambda>A. lookup A is) (list_of_vec (tensors_from_net m)))"
also have "... = monoid_add_class.sum_list (map (\<lambda>A. lookup A is) (list_of_vec (tensors_from_net m)))"
using vec_eqI[of "vec_of_list (list_of_vec (map\<^sub>v (\<lambda>A. lookup A is)(tensors_from_net m)))"
"vec_of_list (map (\<lambda>A. lookup A is) (list_of_vec (tensors_from_net m)))"] dim_vec_of_list
nth_list_of_vec length_map list_vec nth_map vec_index_map(1) vec_index_map(2) vec_list
......@@ -348,14 +348,14 @@ proof -
unfolding witness_l1 using tensors_from_net_Conv_all1[OF witness_l0'_valid assms(1)]
witness_l0' `output_size' (witness' r0 [M]) = r0` by simp
then have "Tensor.lookup (tensors_from_net (witness r1 r0 [M]) $ j) is
= monoid_add_class.listsum (map (\<lambda>A. Tensor.lookup A is) (list_of_vec (tensors_from_net (witness' r0 [M]))))"
= monoid_add_class.sum_list (map (\<lambda>A. Tensor.lookup A is) (list_of_vec (tensors_from_net (witness' r0 [M]))))"
using lookup_listsum[OF `is \<lhd> [M, M]`] \<open>input_sizes (witness' r0 [M]) = [M, M]\<close>
dims_tensors_from_net by (metis set_list_of_vec)
also have "... = monoid_add_class.listsum (map (\<lambda>i. lookup (tensors_from_net (witness' r0 [M]) $ i) is) [0..<r0])"
also have "... = monoid_add_class.sum_list (map (\<lambda>i. lookup (tensors_from_net (witness' r0 [M]) $ i) is) [0..<r0])"
using map_map[of "(\<lambda>A. Tensor.lookup A is)" "\<lambda>i. (tensors_from_net (witness' r0 [M]) $ i)" "[0..<r0]"]
using list_of_vec_map `dim\<^sub>v (tensors_from_net (witness' r0 [M])) = r0` by (metis (mono_tags, lifting) comp_apply map_eq_conv)
also have "... = (\<Sum>i<r0. Tensor.lookup ((tensors_from_net (witness' r0 [M])) $ i) is)"
using setsum_set_upt_conv_listsum_nat atLeast0LessThan by (metis atLeast_upt)
using sum_set_upt_conv_sum_list_nat atLeast0LessThan by (metis atLeast_upt)
also have "... = (if is!0 = is!1 \<and> is!0<r0 then 1 else 0)"
proof (cases "is!0<r0")
case True
......@@ -364,13 +364,13 @@ proof -
have "(\<Sum>i<r0. Tensor.lookup ((tensors_from_net (witness' r0 [M])) $ i) is)
= Tensor.lookup (tensors_from_net (witness' r0 [M]) $ (is!0)) is"
using `dim\<^sub>v (tensors_from_net (witness' r0 [M])) = r0`
using setsum.remove[OF `finite {0..<r0}` `is!0 \<in> {0..<r0}`,
using sum.remove[OF `finite {0..<r0}` `is!0 \<in> {0..<r0}`,
of "\<lambda>i. (Tensor.lookup (tensors_from_net (witness' r0 [M])$i) is)"]
using all0_but1 atLeast0LessThan by force
then show ?thesis using lookup_tensors_ht_l0' \<open>is ! 0 < r0\<close> \<open>is \<lhd> [M, M]\<close> by fastforce
next
case False
then show ?thesis using all0_but1 atLeast0LessThan setsum.neutral by force
then show ?thesis using all0_but1 atLeast0LessThan sum.neutral by force
qed
finally show ?thesis by auto
qed
......@@ -476,22 +476,22 @@ assumes "remove_weights m = deep_model_l rs"
shows "order (tensors_from_net m $ y) = 2 * N_half"
using dims_tensor_deep_model by (simp add: assms)
lemma dims_A:
lemma dims_A:
shows "Tensor.dims (A ws) = replicate (2 * N_half) (last rs)"
unfolding A_def
using dims_tensor_deep_model remove_insert_weights[OF assms[unfolded weight_space_dim_def]] by blast
using dims_tensor_deep_model remove_insert_weights by blast
lemma order_A:
shows "order (A ws) = 2 * N_half" using dims_A assms length_replicate by auto
shows "order (A ws) = 2 * N_half" using dims_A length_replicate by auto
lemma dims_A':
shows "dim\<^sub>r (A' ws) = listprod (sublist (Tensor.dims (A ws)) {n. even n})"
and "dim\<^sub>c (A' ws) = listprod (sublist (Tensor.dims (A ws)) {n. odd n})"
unfolding A'_def matricize_def assms by (simp_all add: A_def Collect_neg_eq)
shows "dim\<^sub>r (A' ws) = prod_list (sublist (Tensor.dims (A ws)) {n. even n})"
and "dim\<^sub>c (A' ws) = prod_list (sublist (Tensor.dims (A ws)) {n. odd n})"
unfolding A'_def matricize_def by (simp_all add: A_def Collect_neg_eq)
lemma dims_A'_pow:
shows "dim\<^sub>r (A' ws) = (last rs) ^ N_half" "dim\<^sub>c (A' ws) = (last rs) ^ N_half"
unfolding dims_A'[OF assms] dims_A[OF assms] sublist_replicate set_le_in card_even card_odd listprod_replicate
unfolding dims_A' dims_A sublist_replicate set_le_in card_even card_odd prod_list_replicate
by simp_all
......@@ -520,8 +520,8 @@ lemma order_Aw: "order Aw = 2 * N_half"
unfolding Aw_def' using order_A by auto
lemma dims_Aw':
"dim\<^sub>r Aw' = listprod (sublist (Tensor.dims Aw) {n. even n})"
"dim\<^sub>c Aw' = listprod (sublist (Tensor.dims Aw) {n. odd n})"
"dim\<^sub>r Aw' = prod_list (sublist (Tensor.dims Aw) {n. even n})"
"dim\<^sub>c Aw' = prod_list (sublist (Tensor.dims Aw) {n. odd n})"
unfolding Aw'_def' Aw_def' using dims_A' by auto
lemma dims_Aw'_pow: "dim\<^sub>r Aw' = (last rs) ^ N_half" "dim\<^sub>c Aw' = (last rs) ^ N_half"
......@@ -762,13 +762,13 @@ definition "rows_with_1 = {i. (\<forall>i0\<in>set (digit_encode (sublist (Tenso
lemma card_low_digits:
assumes "m>0" "\<And>d. d\<in>set ds \<Longrightarrow> m \<le> d"
shows "card {i. i<listprod ds \<and> (\<forall>i0\<in>set (digit_encode ds i). i0 < m)} = m ^ (length ds)"
shows "card {i. i<prod_list ds \<and> (\<forall>i0\<in>set (digit_encode ds i). i0 < m)} = m ^ (length ds)"
using assms proof (induction ds)
case Nil
then show ?case using listprod.Nil by simp
then show ?case using prod_list.Nil by simp
next
case (Cons d ds)
def low_digits == "\<lambda>ds i. i < listprod ds \<and> (\<forall>i0\<in>set (digit_encode ds i). i0 < m)"
def low_digits == "\<lambda>ds i. i < prod_list ds \<and> (\<forall>i0\<in>set (digit_encode ds i). i0 < m)"
have "card {i. low_digits ds i} = m ^ (length ds)" unfolding low_digits_def
by (simp add: Cons.IH Cons.prems(1) Cons.prems(2))
have "card {i. low_digits (d # ds) i} = card ({..<m} \<times> {i. low_digits ds i})"
......@@ -790,29 +790,29 @@ next
then have "i0<d" using Cons(3) by (meson list.set_intros(1) not_le order_trans)
show "x \<in> {i. low_digits (d # ds) i}" unfolding low_digits_def
proof (rule; rule conjI)
have "i1 < listprod ds" "\<forall>i0\<in>set (digit_encode ds i1). i0 < m"
have "i1 < prod_list ds" "\<forall>i0\<in>set (digit_encode ds i1). i0 < m"
using `low_digits ds i1` low_digits_def by auto
show "x < listprod (d # ds)" unfolding listprod.Cons `x = i0 + d * i1` using `i0<d` `i1 < listprod ds`
show "x < prod_list (d # ds)" unfolding prod_list.Cons `x = i0 + d * i1` using `i0<d` `i1 < prod_list ds`
proof -
have "d \<noteq> 0"
by (metis \<open>i0 < d\<close> gr_implies_not0)
then have "(i0 + d * i1) div (d * listprod ds) = 0"
by (simp add: Divides.div_mult2_eq \<open>i0 < d\<close> \<open>i1 < listprod ds\<close>)
then show "i0 + d * i1 < d * listprod ds"
by (metis (no_types) \<open>i0 < d\<close> \<open>i1 < listprod ds\<close> div_eq_0_iff gr_implies_not0 no_zero_divisors)
then have "(i0 + d * i1) div (d * prod_list ds) = 0"
by (simp add: Divides.div_mult2_eq \<open>i0 < d\<close> \<open>i1 < prod_list ds\<close>)
then show "i0 + d * i1 < d * prod_list ds"
by (metis (no_types) \<open>i0 < d\<close> \<open>i1 < prod_list ds\<close> div_eq_0_iff gr_implies_not0 no_zero_divisors)
qed
show "\<forall>i0\<in>set (digit_encode (d # ds) x). i0 < m"
using \<open>\<forall>i0\<in>set (digit_encode ds i1). i0 < m\<close> \<open>i0 < d\<close> \<open>i0 < m\<close> \<open>x = i0 + d * i1\<close> by auto
qed
next
fix x assume "x \<in> {i. low_digits (d # ds) i}"
then have "x < listprod (d # ds)" "\<forall>i0\<in>set (digit_encode (d # ds) x). i0 < m" using low_digits_def by auto
then have "x < prod_list (d # ds)" "\<forall>i0\<in>set (digit_encode (d # ds) x). i0 < m" using low_digits_def by auto
have "x mod d < m" using `\<forall>i0\<in>set (digit_encode (d # ds) x). i0 < m`[unfolded digit_encode.simps] by simp
have "x div d < listprod ds" using `x < listprod (d # ds)`[unfolded listprod.Cons]
have "x div d < prod_list ds" using `x < prod_list (d # ds)`[unfolded prod_list.Cons]
by (metis Divides.div_mult2_eq div_eq_0_iff gr_implies_not0 mult_0_right)
have "\<forall>i0\<in>set (digit_encode ds (x div d)). i0 < m" by (simp add: \<open>\<forall>i0\<in>set (digit_encode (d # ds) x). i0 < m\<close>)
have "f ((x mod d),(x div d)) = x" by (simp add: f_def)
show "x \<in> f ` ({..<m} \<times> {i. low_digits ds i})" by (metis SigmaI \<open>\<forall>i0\<in>set (digit_encode ds (x div d)). i0 < m\<close> \<open>f (x mod d, x div d) = x\<close> \<open>x div d < listprod ds\<close> \<open>x mod d < m\<close> image_eqI lessThan_iff low_digits_def mem_Collect_eq)
show "x \<in> f ` ({..<m} \<times> {i. low_digits ds i})" by (metis SigmaI \<open>\<forall>i0\<in>set (digit_encode ds (x div d)). i0 < m\<close> \<open>f (x mod d, x div d) = x\<close> \<open>x div d < prod_list ds\<close> \<open>x mod d < m\<close> image_eqI lessThan_iff low_digits_def mem_Collect_eq)
qed
then have "bij_betw f ({..<m} \<times> {i. low_digits ds i}) {i. low_digits (d # ds) i}"
by (simp add: \<open>inj_on f ({..<m} \<times> {i. low_digits ds i})\<close> bij_betw_def)
......@@ -823,13 +823,13 @@ qed
lemma card_rows_with_1: "card {i\<in>rows_with_1. i<dim\<^sub>r Aw'} = r ^ N_half"
proof -
have 1:"{i\<in>rows_with_1. i<dim\<^sub>r Aw'} = {i. i < listprod (sublist (Tensor.dims Aw) (Collect even)) \<and>
have 1:"{i\<in>rows_with_1. i<dim\<^sub>r Aw'} = {i. i < prod_list (sublist (Tensor.dims Aw) (Collect even)) \<and>
(\<forall>i0\<in>set (digit_encode (sublist (Tensor.dims Aw) (Collect even)) i). i0 < r)}" (is "?A = ?B")
proof (rule subset_antisym; rule subsetI)
fix i assume "i \<in> ?A"
then have "i < dim\<^sub>r Aw'" "\<forall>i0\<in>set (digit_encode (sublist (Tensor.dims Aw) {n. even n}) i). i0 < last (butlast rs)"
using rows_with_1_def by auto
then have "i < listprod (sublist (dims Aw) (Collect even))" using dims_Aw' by linarith
then have "i < prod_list (sublist (dims Aw) (Collect even))" using dims_Aw' by linarith
then have "digit_encode (sublist (dims Aw) (Collect even)) i \<lhd> sublist (dims Aw) (Collect even)"
using digit_encode_valid_index by auto
have "\<forall>i0\<in>set (digit_encode (sublist (Tensor.dims Aw) {n. even n}) i). i0 < r"
......@@ -850,7 +850,7 @@ proof -
\<open>k < length (digit_encode (sublist (dims Aw) (Collect even)) i)\<close> valid_index_length by fastforce
then show "i0 < r" unfolding r_def by (simp add: \<open>i0 < last (butlast rs)\<close>)
qed
then show "i \<in> ?B" using \<open>i < listprod (sublist (dims Aw) (Collect even))\<close> by blast
then show "i \<in> ?B" using \<open>i < prod_list (sublist (dims Aw) (Collect even))\<close> by blast
next
fix i assume "i\<in>?B"
then show "i\<in>?A" by (simp add: dims_Aw' r_def rows_with_1_def)
......@@ -872,7 +872,7 @@ qed
lemma infinite_rows_with_1: "infinite rows_with_1"
proof -
def listpr == "listprod (sublist (Tensor.dims Aw) {n. even n})"
def listpr == "prod_list (sublist (Tensor.dims Aw) {n. even n})"
have "\<And>i. listpr dvd i \<Longrightarrow> i \<in> rows_with_1"
proof -
fix i assume dvd_i: "listpr dvd i"
......
......@@ -53,7 +53,7 @@ shows "polyfun N (\<lambda>x. \<Sum>i\<in>I. f i x)"
using assms
apply (induction I rule:finite_induct)
apply (simp add: polyfun_const)
using comm_monoid_add_class.setsum.insert polyfun_add by fastforce
using comm_monoid_add_class.sum.insert polyfun_add by fastforce
lemma polyfun_Prod:
assumes "finite I"
......@@ -62,7 +62,7 @@ shows "polyfun N (\<lambda>x. \<Prod>i\<in>I. f i x)"
using assms
apply (induction I rule:finite_induct)
apply (simp add: polyfun_const)
using comm_monoid_add_class.setsum.insert polyfun_mult by fastforce
using comm_monoid_add_class.sum.insert polyfun_mult by fastforce
lemma polyfun_single:
assumes "i\<in>N"
......
......@@ -40,7 +40,7 @@ lemma flatten_matrix_extract_matrix:
shows "\<And>k. k<m*n \<Longrightarrow> flatten_matrix (extract_matrix a m n) k = a k"
unfolding extract_matrix_def flatten_matrix_def
by (metis (no_types, lifting) Divides.div_mult2_eq case_prod_conv div_eq_0_iff mat_dim_col_mat(1)
mat_index_mat(1) mod_div_equality mod_less_divisor mult.commute mult_zero_right not_gr0 not_less0)
mat_index_mat(1) div_mult_mod_eq mod_less_divisor mult.commute mult_zero_right not_gr0 not_less0)
lemma index_extract_matrix:
assumes "i<m" "j<n"
......
......@@ -348,15 +348,15 @@ proof -
assms not_less not_le by blast
qed
lemma listprod_complementary_sublists:
lemma prod_list_complementary_sublists:
fixes f ::"'a \<Rightarrow> 'b::comm_monoid_mult"
shows "listprod (map f xs) = listprod (map f (sublist xs A)) * listprod (map f (sublist xs (-A)))"
shows "prod_list (map f xs) = prod_list (map f (sublist xs A)) * prod_list (map f (sublist xs (-A)))"
proof (induction xs rule:rev_induct)
case Nil
then show ?case by simp
next
case (snoc x xs)
show ?case unfolding map_append "listprod.append" sublist_append sublist_singleton snoc
show ?case unfolding map_append "prod_list.append" sublist_append sublist_singleton snoc
by (cases "(length xs)\<in>A"; simp;metis mult.assoc mult.commute)
qed
......
......@@ -223,7 +223,7 @@ proof (rule tensor_lookup_eqI)
unfolding scalar_prod_def rows_nth[OF `i<dim\<^sub>r A`] by simp
also have "... = (\<Sum>j\<in>{0..<dim\<^sub>v Ts}. lookup (A $$ (i, j) \<cdot> Ts $ j) is)" using summand_eq by force
also have "... = (\<Sum>A\<leftarrow>?Ts'. lookup A is)" unfolding map_map
Groups_List.setsum_set_upt_conv_listsum_nat[symmetric] atLeastLessThan_upt[symmetric] by auto
Groups_List.sum_set_upt_conv_sum_list_nat[symmetric] atLeastLessThan_upt[symmetric] by auto
also have "... = lookup (listsum ds ?Ts') is" using lookup_listsum[OF `is \<lhd> ds`] dims_Ts' by fastforce
finally show "lookup (mat_tensorlist_mult A Ts ds $ i) is = lookup (listsum ds ?Ts') is" by metis
qed
......@@ -346,7 +346,7 @@ qed
lemma insert_remove_weights:
obtains w where "m = insert_weights (remove_weights m) w"
using assms proof (induction m arbitrary:thesis)
proof (induction m arbitrary:thesis)
case (Input m thesis)
then show ?case by simp
next
......@@ -370,7 +370,7 @@ qed
lemma remove_insert_weights:
shows "remove_weights (insert_weights m w) = m"
using assms proof (induction m arbitrary:w)
proof (induction m arbitrary:w)
case Input
then show ?case by simp
next
......@@ -423,15 +423,15 @@ proof -
have 2:"inj_on (\<lambda>(is1, is2). is1 @ is2) ({is1. is1 \<lhd> ds1} \<times> {is2. is2 \<lhd> ds2})"
by (simp add: inj_on_def valid_index_length)
show ?thesis
unfolding Groups_Big.comm_monoid_add_class.setsum.cartesian_product[of "\<lambda>is1 is2. f (is1 @ is2)"]
using Groups_Big.comm_monoid_add_class.setsum.reindex[OF 2, of f] 1
"2" SigmaE prod.simps(2) setsum.reindex_cong by (simp add: split_def)
unfolding Groups_Big.comm_monoid_add_class.sum.cartesian_product[of "\<lambda>is1 is2. f (is1 @ is2)"]
using Groups_Big.comm_monoid_add_class.sum.reindex[OF 2, of f] 1
"2" SigmaE prod.simps(2) sum.reindex_cong by (simp add: split_def)
qed
lemma setprod_lessThan_split:
fixes g :: "nat \<Rightarrow> real" shows "setprod g {..<n+m} = setprod g {..<n} * setprod (\<lambda>x. g (x+n)) {..<m}"
using Groups_Big.comm_monoid_mult_class.setprod.union_inter_neutral[of "{..<n}" "{n..<n+m}" g, unfolded ivl_disj_un_one(2)[OF le_add1], OF finite_lessThan finite_atLeastLessThan]
by (metis (no_types) add.commute add.left_neutral atLeast0LessThan empty_iff ivl_disj_int_one(2) setprod_shift_bounds_nat_ivl)
lemma prod_lessThan_split:
fixes g :: "nat \<Rightarrow> real" shows "prod g {..<n+m} = prod g {..<n} * prod (\<lambda>x. g (x+n)) {..<m}"
using Groups_Big.comm_monoid_mult_class.prod.union_inter_neutral[of "{..<n}" "{n..<n+m}" g, unfolded ivl_disj_un_one(2)[OF le_add1], OF finite_lessThan finite_atLeastLessThan]
by (metis (no_types) add.commute add.left_neutral atLeast0LessThan empty_iff ivl_disj_int_one(2) prod_shift_bounds_nat_ivl)
lemma evaluate_net_from_tensors:
assumes "valid_net' m"
......@@ -455,9 +455,9 @@ using assms proof (induction m arbitrary:j "is" inputs)
then have "(\<Sum>is | is \<lhd> input_sizes (Input M). (\<Prod>k<length inputs. inputs ! k $ (is ! k)) * lookup (tensors_from_net (Input M) $ j) is)
= (\<Sum>is | is \<lhd> input_sizes (Input M). (if is=[j] then (\<Prod>k<length inputs. inputs ! k $ (is ! k)) else 0))" by auto
also have "(\<Sum>is | is \<lhd> input_sizes (Input M). (if is=[j] then (\<Prod>k<length inputs. inputs ! k $ (is ! k)) else 0))
= (\<Prod>k<length inputs. inputs ! k $ ([j] ! k))" unfolding setsum.delta[OF finite_valid_index]
= (\<Prod>k<length inputs. inputs ! k $ ([j] ! k))" unfolding sum.delta[OF finite_valid_index]
using Input.prems(3) valid_index.Cons valid_index.Nil by auto
also have "... = inputs ! 0 $ j" using `length inputs = 1` by (simp add: setprod_lessThan_Suc)
also have "... = inputs ! 0 $ j" using `length inputs = 1` by (simp add: prod_lessThan_Suc)
also have "... = evaluate_net (Input M) inputs $ j" unfolding evaluate_net.simps
by (metis \<open>length inputs = 1\<close> hd_conv_nth list.size(3) zero_neq_one)
finally show ?case by auto
......@@ -477,7 +477,7 @@ next
using vec_index_map by auto
show "(\<Prod>k<length inputs. inputs ! k $ (is ! k)) * lookup (tensors_from_net (Conv A m) $ j) is
= (\<Sum>i = 0..<dim\<^sub>v (tensors_from_net m). row A j $ i * ((\<Prod>k<length inputs. inputs ! k $ (is ! k)) * lookup (tensors_from_net m $ i) is))"
unfolding 0 setsum_right_distrib by (simp add: semiring_normalization_rules(19))
unfolding 0 sum_distrib_left by (simp add: semiring_normalization_rules(19))
qed
have "valid_net' m" by (metis Conv.prems(1) convnet.distinct(1) convnet.distinct(5) convnet.inject(2) remove_weights.simps(2) valid_net.simps)
have "map dim\<^sub>v inputs = input_sizes m" by (simp add: Conv.prems(2))
......@@ -487,9 +487,9 @@ next
have "(\<Sum>is | is \<lhd> input_sizes (Conv A m). (\<Prod>k<length inputs. inputs ! k $ (is ! k)) * lookup (tensors_from_net (Conv A m) $ j) is)
= (\<Sum>i = 0..<dim\<^sub>v (tensors_from_net m). (\<Sum>is | is \<lhd> input_sizes (Conv A m). row A j $ i * ((\<Prod>k<length inputs. inputs ! k $ (is ! k)) * lookup (tensors_from_net m $ i) is)))"
using Groups_Big.comm_monoid_add_class.setsum.commute 0 by auto
using Groups_Big.comm_monoid_add_class.sum.commute 0 by auto
also have "... = (\<Sum>i = 0..<dim\<^sub>v (tensors_from_net m). row A j $ i * (\<Sum>is | is \<lhd> input_sizes (Conv A m). ((\<Prod>k<length inputs. inputs ! k $ (is ! k)) * lookup (tensors_from_net m $ i) is)))"
by (simp add: setsum_right_distrib)
by (simp add: sum_distrib_left)
also have "... = (\<Sum>i = 0..<dim\<^sub>v (tensors_from_net m). row A j $ i * evaluate_net m inputs $ i)" using 1 by auto
also have "... = row A j \<bullet> evaluate_net m inputs"
by (metis (full_types) \<open>map dim\<^sub>v inputs = input_sizes m\<close> \<open>output_size' m = dim\<^sub>v (tensors_from_net m)\<close>
......@@ -521,13 +521,13 @@ next
using \<open>is2 \<lhd> input_sizes m2\<close> \<open>map dim\<^sub>v inputs2 = input_sizes m2\<close> valid_index_length by fastforce
have 1:"(\<Prod>k<length inputs1. (inputs1 @ inputs2) ! k $ ((is1 @ is2) ! k)) = (\<Prod>k<length inputs1. inputs1 ! k $ (is1 ! k))"
using `length is1 = length inputs1` `length is2 = length inputs2`
nth_append by (metis (no_types, lifting) lessThan_iff setprod.cong)
nth_append by (metis (no_types, lifting) lessThan_iff prod.cong)
have 2:"(\<Prod>x<length inputs2. (inputs1 @ inputs2) ! (x + length inputs1) $ ((is1 @ is2) ! (x + length inputs1))) =
(\<Prod>k<length inputs2. inputs2 ! k $ (is2 ! k))"
using `length is1 = length inputs1` `length is2 = length inputs2`
by (metis (no_types, lifting) add.commute nth_append_length_plus)
have "(\<Prod>k<length inputs. inputs ! k $ ((is1 @ is2) ! k)) = (\<Prod>k<length inputs1. inputs1 ! k $ (is1 ! k)) * (\<Prod>k<length inputs2. inputs2 ! k $ (is2 ! k))"
unfolding `inputs = inputs1 @ inputs2` length_append setprod_lessThan_split using 1 2 by metis
unfolding `inputs = inputs1 @ inputs2` length_append prod_lessThan_split using 1 2 by metis
}
note 1 = this
{
......@@ -549,10 +549,10 @@ next
(\<Prod>k<length inputs1. inputs1 ! k $ (is1 ! k)) * (\<Prod>k<length inputs2. inputs2 ! k $ (is2 ! k)) *
lookup (tensors_from_net m1 $ j) is1 * lookup (tensors_from_net m2 $ j) is2)"
unfolding input_sizes.simps setsum_valid_index_split using 1 2
using mem_Collect_eq setsum.cong by (simp add: mult.assoc)
using mem_Collect_eq sum.cong by (simp add: mult.assoc)
also have "... = (\<Sum>is1 | is1 \<lhd> input_sizes m1. (\<Prod>k<length inputs1. inputs1 ! k $ (is1 ! k)) * lookup (tensors_from_net m1 $ j) is1) *
(\<Sum>is2 | is2 \<lhd> input_sizes m2. (\<Prod>k<length inputs2. inputs2 ! k $ (is2 ! k)) * lookup (tensors_from_net m2 $ j) is2)"
unfolding setsum_product by (rule setsum.cong, metis, rule setsum.cong, metis, simp)
unfolding sum_product by (rule sum.cong, metis, rule sum.cong, metis, simp)
also have "... = evaluate_net (Pool m1 m2) inputs $ j" unfolding "evaluate_net.simps" index_component_mult[OF j_le_eval]
using Pool.IH(1)[OF `valid_net' m1` _ `j < output_size' m1`] Pool.IH(2)[OF `valid_net' m2` _ `j < output_size' m2`]
using \<open>map dim\<^sub>v inputs1 = input_sizes m1\<close> \<open>map dim\<^sub>v inputs2 = input_sizes m2\<close> inputs1_def inputs2_def by auto
......
......@@ -179,7 +179,7 @@ proof (rule vec_eqI)
image_subsetI lessThan_iff nth_mem)
then have " (\<Sum>x\<in>set (cols A). a x * x $ i) =
(\<Sum>j\<in>{..<length (cols A)}. a (cols A ! j) * (cols A ! j) $ i)"
using bij_betw_imageE bij_betw_imp_inj_on by (metis (no_types, lifting) setsum.reindex_cong)
using bij_betw_imp_surj_on bij_betw_imp_inj_on by (metis (no_types, lifting) sum.reindex_cong)
also have "... = (\<Sum>j\<in>{..<length (cols A)}. a (col A j) * (cols A ! j) $ i)"
using assms(1) assms(2) find_first_unique[OF `distinct (cols A)`] `i < n` by auto
also have "... = (\<Sum>j\<in>{..<length (cols A)}. (cols A ! j) $ i * a (col A j))" by (metis mult_commute_abs)
......@@ -187,7 +187,7 @@ proof (rule vec_eqI)
finally show "(A \<otimes>\<^sub>m\<^sub>v (vec nc (\<lambda>i. a (col A i)))) $ i = lincomb a (set (cols A)) $ i"
unfolding lincomb_index[OF `i < n` `set (cols A) \<subseteq> carrier\<^sub>v n`]
unfolding mat_mult_vec_def scalar_prod_def
using \<open>i < n\<close> assms(1) atLeast0LessThan lessThan_def mat_carrierD(1) vec_index_vec setsum.cong by auto
using \<open>i < n\<close> assms(1) atLeast0LessThan lessThan_def mat_carrierD(1) vec_index_vec sum.cong by auto
qed
lemma (in vec_space) lincomb_eq_mat_mult:
......
......@@ -12,25 +12,25 @@ no_notation "normal_rel" (infixl "\<lhd>" 60)
lemma lookup_order1_prod:
assumes "\<And>B. B\<in>set Bs \<Longrightarrow> Tensor.order B = 1"
assumes "is \<lhd> dims (listprod Bs)"
shows "lookup (listprod Bs) is = listprod (map (\<lambda>(i,B). lookup B [i]) (zip is Bs))"
assumes "is \<lhd> dims (prod_list Bs)"
shows "lookup (prod_list Bs) is = prod_list (map (\<lambda>(i,B). lookup B [i]) (zip is Bs))"
using assms proof (induction Bs arbitrary:"is")
case Nil
then show ?case unfolding "listprod.Nil" unfolding zip.simps tensor_one_def
by (metis (no_types, lifting) dims_tensor_from_lookup length_greater_0_conv length_map listprod.Nil
then show ?case unfolding "prod_list.Nil" unfolding zip.simps tensor_one_def
by (metis (no_types, lifting) dims_tensor_from_lookup length_greater_0_conv length_map prod_list.Nil
lookup_tensor_from_lookup tensor_one_def tensor_one_from_lookup)
next
case (Cons B Bs "is'")
then obtain i "is" where "is' = i # is"
by (metis append_is_Nil_conv dims_tensor_prod length_0_conv list.set_intros(1) listprod.Cons valid_index.simps zero_neq_one)
by (metis append_is_Nil_conv dims_tensor_prod length_0_conv list.set_intros(1) prod_list.Cons valid_index.simps zero_neq_one)
have "Tensor.order B = 1" using Cons by auto
then have valid1:"[i] \<lhd> dims B"
using `is' \<lhd> dims (listprod (B # Bs))`[unfolded listprod.Cons dims_tensor_prod `is' = i # is`]
using `is' \<lhd> dims (prod_list (B # Bs))`[unfolded prod_list.Cons dims_tensor_prod `is' = i # is`]
by (metis One_nat_def Suc_length_conv hd_append2 length_0_conv list.sel(1) list.simps(3) valid_index.Nil valid_index.simps)
have valid2:"is \<lhd> dims (listprod Bs)"
using `is' \<lhd> dims (listprod (B # Bs))`[unfolded listprod.Cons dims_tensor_prod `is' = i # is`] `Tensor.order B = 1`
have valid2:"is \<lhd> dims (prod_list Bs)"
using `is' \<lhd> dims (prod_list (B # Bs))`[unfolded prod_list.Cons dims_tensor_prod `is' = i # is`] `Tensor.order B = 1`
by (metis One_nat_def Suc_length_conv append_eq_Cons_conv length_0_conv list.sel(3) list.simps(3) self_append_conv2 valid_indexE)
show ?case unfolding `is' = i # is` List.zip_Cons_Cons List.list.map(2) listprod.Cons
show ?case unfolding `is' = i # is` List.zip_Cons_Cons List.list.map(2) prod_list.Cons
lookup_tensor_prod[OF valid1 valid2, simplified] by (simp add: Cons.IH Cons.prems(1) valid2)
qed
......@@ -39,19 +39,19 @@ fixes A::"'a::field tensor"
assumes "cprank_max1 A"
shows "mrank (matricize I A) \<le> 1"
proof -
obtain Bs a where "\<And>B. B \<in> set Bs \<Longrightarrow> Tensor.order B = 1" "a \<cdot> listprod Bs = A"
using cprank_max1_listprodE assms by metis
def row_factor == "\<lambda>ris. a * (listprod (map (\<lambda>(i,B). lookup B [i]) (zip ris (sublist Bs I))))"
def col_factor == "\<lambda>cis. (listprod (map (\<lambda>(i,B). lookup B [i]) (zip cis (sublist Bs (-I)))))"
obtain Bs a where "\<And>B. B \<in> set Bs \<Longrightarrow> Tensor.order B = 1" "a \<cdot> prod_list Bs = A"
using cprank_max1_prod_listE assms by metis
def row_factor == "\<lambda>ris. a * (prod_list (map (\<lambda>(i,B). lookup B [i]) (zip ris (sublist Bs I))))"
def col_factor == "\<lambda>cis. (prod_list (map (\<lambda>(i,B). lookup B [i]) (zip cis (sublist Bs (-I)))))"
have "\<And>is. is \<lhd> dims A \<Longrightarrow> lookup A is = row_factor (sublist is I) * col_factor (sublist is (-I))"
proof -
fix "is" assume "is \<lhd> dims A"
then have "lookup A is = a * (listprod (map (\<lambda>(i,B). lookup B [i]) (zip is Bs)))"
then have "lookup A is = a * (prod_list (map (\<lambda>(i,B). lookup B [i]) (zip is Bs)))"
using lookup_order1_prod[OF `\<And>B. B \<in> set Bs \<Longrightarrow> Tensor.order B = 1`] lookup_smult
using \<open>a \<cdot> listprod Bs = A\<close> dims_smult by fastforce
also have "... = a * (listprod (map (\<lambda>(i,B). lookup B [i]) (sublist (zip is Bs) I))) *
(listprod (map (\<lambda>(i,B). lookup B [i]) (sublist (zip is Bs) (-I))))"
using listprod_complementary_sublists by auto
using \<open>a \<cdot> prod_list Bs = A\<close> dims_smult by fastforce
also have "... = a * (prod_list (map (\<lambda>(i,B). lookup B [i]) (sublist (zip is Bs) I))) *
(prod_list (map (\<lambda>(i,B). lookup B [i]) (sublist (zip is Bs) (-I))))"
using prod_list_complementary_sublists by auto
also have "... = row_factor (sublist is I) * col_factor (sublist is (-I))"
using sublist_zip row_factor_def col_factor_def by metis
finally show "lookup A is = row_factor (sublist is I) * col_factor (sublist is (-I))" .
......
......@@ -373,7 +373,7 @@ is "\<lambda>p v. Max (insert 0 ((\<lambda>m. PP_Poly_Mapping.lookup m v) ` PP_P
lift_definition total_degree :: "'a::zero mpoly \<Rightarrow> nat"
is "\<lambda>p. Max (insert 0 ((\<lambda>m. setsum (PP_Poly_Mapping.lookup m) (PP_Poly_Mapping.keys m)) ` PP_Poly_Mapping.keys p))" .
is "\<lambda>p. Max (insert 0 ((\<lambda>m. sum (PP_Poly_Mapping.lookup m) (PP_Poly_Mapping.keys m)) ` PP_Poly_Mapping.keys p))" .
lemma degree_zero [simp]:
"degree 0 v = 0"
......
......@@ -218,11 +218,11 @@ section "MPoly extension"
lemma vars_setsum: "finite S \<Longrightarrow> vars (\<Sum>m\<in>S. f m) \<subseteq> (\<Union>m\<in>S. vars (f m))"
proof (induction S rule:finite_induct)
case empty
then show ?case by (metis UN_empty eq_iff monom_zero setsum.empty single_zero vars_monom_single_cases)
then show ?case by (metis UN_empty eq_iff monom_zero sum.empty single_zero vars_monom_single_cases)
next
case (insert s S)
then have "vars (setsum f (insert s S)) = vars (f s + setsum f S)" by (metis setsum.insert)
also have "... \<subseteq> vars (f s) \<union> vars (setsum f S)" by (simp add: vars_add)
then have "vars (sum f (insert s S)) = vars (f s + sum f S)" by (metis sum.insert)
also have "... \<subseteq> vars (f s) \<union> vars (sum f S)" by (simp add: vars_add)
also have "... \<subseteq> (\<Union>m\<in>insert s S. vars (f m))" using insert.IH by auto
finally show ?case by metis
qed
......@@ -311,7 +311,7 @@ section "MPoly extension"
lemma insertion_fun_single: "insertion_fun f (\<lambda>m. (a when (PP_Poly_Mapping.single (v::nat) (n::nat)) = m)) = a * f v ^ n" (is "?i = _")
proof -
have setsum_single:"\<And> a f. (\<Sum>m\<in>{a}. f m) = f a"
by (metis add.right_neutral empty_Diff finite.emptyI setsum.empty setsum.insert_remove)
by (metis add.right_neutral empty_Diff finite.emptyI sum.empty sum.insert_remove)
have 1:"?i = (\<Sum>m. (a when PP_Poly_Mapping.single v n = m) * (\<Prod>v. f v ^ lookup m v))"
unfolding insertion_fun_def by metis
......@@ -431,7 +431,7 @@ proof-
qed
lemma extract_var_non_zero_coeff: "extract_var p v = (\<Sum>m\<in>{m'. coeff p m' \<noteq> 0}. monom (remove_key v m) (monom (PP_Poly_Mapping.single v (lookup m v)) (coeff p m)))"
using extract_var_finite_set coeff_def finite_lookup order_refl by (metis (no_types, lifting) Collect_cong setsum.cong)
using extract_var_finite_set coeff_def finite_lookup order_refl by (metis (no_types, lifting) Collect_cong sum.cong)
lemma extract_var_sum: "extract_var (p+p') v = extract_var p v + extract_var p' v"
proof -
......@@ -442,7 +442,7 @@ proof -
extract_var_finite_set[OF subsets(1) `finite S`]
extract_var_finite_set[OF subsets(2) `finite S`]
extract_var_finite_set[OF subsets(3) `finite S`]
coeff_add[symmetric] monom_add setsum.distrib
coeff_add[symmetric] monom_add sum.distrib
by metis
qed
......@@ -456,14 +456,14 @@ proof (cases "a = 0")
unfolding coeff_monom using \<open>a \<noteq> 0\<close> by auto
show ?thesis
unfolding extract_var_non_zero_coeff unfolding 0 unfolding coeff_monom
using setsum.insert[OF finite.emptyI, unfolded setsum.empty add.right_neutral] when_def
using sum.insert[OF finite.emptyI, unfolded sum.empty add.right_neutral] when_def
by auto
next
assume "a = 0"
have 0:"{m'. coeff (monom m a) m' \<noteq> 0} = {}"
unfolding coeff_monom using \<open>a = 0\<close> by auto
show ?thesis unfolding extract_var_non_zero_coeff 0
using \<open>a = 0\<close> monom.abs_eq monom_zero setsum.empty single_zero by (metis (no_types, lifting))
using \<open>a = 0\<close> monom.abs_eq monom_zero sum.empty single_zero by (metis (no_types, lifting))
qed
......
......@@ -175,7 +175,7 @@ proof -
have "inj_on (\<lambda>a. (a, h a)) {a. g a \<noteq> 0}"
by (rule inj_onI) auto
then show ?thesis unfolding Sum_any.expand_set
by (rule setsum.reindex_cong) auto
by (rule sum.reindex_cong) auto
qed
lemma Sum_any_when_dependent_prod_left:
......@@ -462,17 +462,17 @@ proof -
using assms by simp
{ fix k l
have "{q. (f2 q when k = l + q) \<noteq> 0} \<subseteq> {q. f2 q \<noteq> 0 \<and> k = l + q}" by auto
with fin2 have "setsum f2 {q. f2 q \<noteq> 0 \<and> k = l + q} = (\<Sum>q. (f2 q when k = l + q))"
with fin2 have "sum f2 {q. f2 q \<noteq> 0 \<and> k = l + q} = (\<Sum>q. (f2 q when k = l + q))"
by (simp add: Sum_any.expand_superset [of "{q. f2 q \<noteq> 0 \<and> k = l + q}"]) }
note aux = this
have "{k. (\<Sum>l. f1 l * setsum f2 {q. f2 q \<noteq> 0 \<and> k = l + q}) \<noteq> 0}
\<subseteq> {k. (\<exists>l. f1 l * setsum f2 {q. f2 q \<noteq> 0 \<and> k = l + q} \<noteq> 0)}"
have "{k. (\<Sum>l. f1 l * sum f2 {q. f2 q \<noteq> 0 \<and> k = l + q}) \<noteq> 0}
\<subseteq> {k. (\<exists>l. f1 l * sum f2 {q. f2 q \<noteq> 0 \<and> k = l + q} \<noteq> 0)}"
by (auto elim!: Sum_any.not_neutral_obtains_not_neutral)
also have "\<dots> \<subseteq> {k. (\<exists>l. f1 l \<noteq> 0 \<and> setsum f2 {q. f2 q \<noteq> 0 \<and> k = l + q} \<noteq> 0)}"
also have "\<dots> \<subseteq> {k. (\<exists>l. f1 l \<noteq> 0 \<and> sum f2 {q. f2 q \<noteq> 0 \<and> k = l + q} \<noteq> 0)}"
by (auto dest: mult_not_zero)
also have "\<dots> \<subseteq> {k. (\<exists>l. f1 l \<noteq> 0 \<and> (\<exists>q. f2 q \<noteq> 0 \<and> k = l + q))}"
by (auto elim!: setsum.not_neutral_contains_not_neutral)
finally have "finite {k. (\<Sum>l. f1 l * setsum f2 {q. f2 q \<noteq> 0 \<and> k = l + q}) \<noteq> 0}"
by (auto elim!: sum.not_neutral_contains_not_neutral)
finally have "finite {k. (\<Sum>l. f1 l * sum f2 {q. f2 q \<noteq> 0 \<and> k = l + q}) \<noteq> 0}"
using * by (rule finite_subset)
with aux have "finite {k. (\<Sum>l. f1 l * (\<Sum>q. (f2 q when k = l + q))) \<noteq> 0}"
by simp
......@@ -1044,7 +1044,7 @@ lemma setsum_keys_plus_distrib:
proof -
let ?A = "PP_Poly_Mapping.keys p \<union> PP_Poly_Mapping.keys q"
have "?lhs = (\<Sum>k\<in>?A. f k (PP_Poly_Mapping.lookup p k + PP_Poly_Mapping.lookup q k))"
apply(rule setsum.mono_neutral_cong_left)
apply(rule sum.mono_neutral_cong_left)
apply(simp_all add: PP_Poly_Mapping.keys_add_subset)
apply(transfer fixing: f)
apply(auto simp add: hom_0)[1]
......@@ -1052,14 +1052,14 @@ proof -
apply(auto simp add: hom_0)[1]
done
also have "\<dots> = (\<Sum>k\<in>?A. f k (PP_Poly_Mapping.lookup p k) + f k (PP_Poly_Mapping.lookup q k))"
by(rule setsum.cong)(simp_all add: hom_plus)
by(rule sum.cong)(simp_all add: hom_plus)
also have "\<dots> = (\<Sum>k\<in>?A. f k (PP_Poly_Mapping.lookup p k)) + (\<Sum>k\<in>?A. f k (PP_Poly_Mapping.lookup q k))"
(is "_ = ?p' + ?q'")
by(simp add: setsum.distrib)
by(simp add: sum.distrib)
also have "?p' = ?p"
by(rule setsum.mono_neutral_right)(auto simp add: hom_0)
by(rule sum.mono_neutral_right)(auto simp add: hom_0)
also have "?q' = ?q"
by(rule setsum.mono_neutral_right)(auto simp add: hom_0)
by(rule sum.mono_neutral_right)(auto simp add: hom_0)
finally show ?thesis .
qed
......@@ -1377,7 +1377,7 @@ lemma range_nth [simp]:
lemma degree_nth:
"no_trailing_zeros xs \<Longrightarrow> degree (nth xs) = length xs"
using assms unfolding degree_def proof transfer
unfolding degree_def proof transfer
fix xs :: "'a list"
assume *: "no_trailing_zeros xs"
let ?A = "{n. nth_default 0 xs n \<noteq> 0}"
......@@ -1527,9 +1527,9 @@ proof transfer
let ?keys = "{k. m k \<noteq> 0}"
assume *: "finite ?keys" "k \<in> ?keys"
then have "f k + g (m k) = (\<Sum>k' \<in> ?keys. f k' + g (m k') when k' = k)"
by (simp add: setsum.delta when_def)
by (simp add: sum.delta when_def)
also have "\<dots> < (\<Sum>k' \<in> ?keys. Suc (f k' + g (m k')))" using *
by (intro setsum_strict_mono) (auto simp add: when_def)
by (intro sum_strict_mono) (auto simp add: when_def)
also have "\<dots> \<le> g 0 + \<dots>" by simp
finally have "f k + g (m k) < \<dots>" .
then show "f k + g (m k) < g 0 + (\<Sum>k | m k \<noteq> 0. Suc (f k + g (m k)))"
......@@ -1575,7 +1575,7 @@ lemma poly_mapping_size_cong [fundef_cong]:
"m = m' \<Longrightarrow> g 0 = g' 0 \<Longrightarrow> (\<And>k. k \<in> keys m' \<Longrightarrow> f k = f' k)
\<Longrightarrow> (\<And>v. v \<in> range m' \<Longrightarrow> g v = g' v)
\<Longrightarrow> poly_mapping_size f g m = poly_mapping_size f' g' m'"
by (auto simp add: poly_mapping_size_def intro!: setsum.cong)
by (auto simp add: poly_mapping_size_def intro!: sum.cong)
instantiation poly_mapping :: (type, zero) size
begin
......@@ -1611,4 +1611,3 @@ by transfer auto
hide_const (open) lookup single update keys range map map_key degree nth the_value items foldr mapp
end
......@@ -7,7 +7,7 @@ imports Main
begin
typedef 'a tensor = "{t::nat list \<times> 'a list. length (snd t) = listprod (fst t)}"
typedef 'a tensor = "{t::nat list \<times> 'a list. length (snd t) = prod_list (fst t)}"
by (simp add: Ex_list_of_length)
definition dims::"'a tensor \<Rightarrow> nat list" where
......@@ -20,7 +20,7 @@ definition tensor_from_vec::"nat list \<Rightarrow> 'a list \<Rightarrow> 'a ten