src/HOL/Groups_List.thy
author paulson <lp15@cam.ac.uk>
Tue Apr 25 16:39:54 2017 +0100 (2017-04-25)
changeset 65578 e4997c181cce
parent 64272 f76b6dda2e56
child 66308 b6a0d95b94be
permissions -rw-r--r--
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
haftmann@58101
     1
(* Author: Tobias Nipkow, TU Muenchen *)
haftmann@58101
     2
wenzelm@60758
     3
section \<open>Sum and product over lists\<close>
haftmann@58101
     4
haftmann@58101
     5
theory Groups_List
haftmann@58101
     6
imports List
haftmann@58101
     7
begin
haftmann@58101
     8
haftmann@58320
     9
locale monoid_list = monoid
haftmann@58320
    10
begin
haftmann@58320
    11
 
haftmann@58320
    12
definition F :: "'a list \<Rightarrow> 'a"
haftmann@58320
    13
where
haftmann@63290
    14
  eq_foldr [code]: "F xs = foldr f xs \<^bold>1"
haftmann@58320
    15
 
haftmann@58320
    16
lemma Nil [simp]:
haftmann@63290
    17
  "F [] = \<^bold>1"
haftmann@58320
    18
  by (simp add: eq_foldr)
haftmann@58320
    19
 
haftmann@58320
    20
lemma Cons [simp]:
haftmann@63290
    21
  "F (x # xs) = x \<^bold>* F xs"
haftmann@58320
    22
  by (simp add: eq_foldr)
haftmann@58320
    23
 
haftmann@58320
    24
lemma append [simp]:
haftmann@63290
    25
  "F (xs @ ys) = F xs \<^bold>* F ys"
haftmann@58320
    26
  by (induct xs) (simp_all add: assoc)
haftmann@58320
    27
 
haftmann@58320
    28
end
haftmann@58101
    29
haftmann@58320
    30
locale comm_monoid_list = comm_monoid + monoid_list
haftmann@58320
    31
begin
haftmann@58320
    32
 
haftmann@58320
    33
lemma rev [simp]:
haftmann@58320
    34
  "F (rev xs) = F xs"
haftmann@58320
    35
  by (simp add: eq_foldr foldr_fold  fold_rev fun_eq_iff assoc left_commute)
haftmann@58320
    36
 
haftmann@58320
    37
end
haftmann@58320
    38
 
haftmann@58320
    39
locale comm_monoid_list_set = list: comm_monoid_list + set: comm_monoid_set
haftmann@58320
    40
begin
haftmann@58101
    41
haftmann@58320
    42
lemma distinct_set_conv_list:
haftmann@58320
    43
  "distinct xs \<Longrightarrow> set.F g (set xs) = list.F (map g xs)"
haftmann@58320
    44
  by (induct xs) simp_all
haftmann@58101
    45
haftmann@58320
    46
lemma set_conv_list [code]:
haftmann@58320
    47
  "set.F g (set xs) = list.F (map g (remdups xs))"
haftmann@58320
    48
  by (simp add: distinct_set_conv_list [symmetric])
haftmann@58320
    49
haftmann@58320
    50
end
haftmann@58320
    51
haftmann@58320
    52
wenzelm@60758
    53
subsection \<open>List summation\<close>
haftmann@58320
    54
haftmann@58320
    55
context monoid_add
haftmann@58320
    56
begin
haftmann@58320
    57
nipkow@63882
    58
sublocale sum_list: monoid_list plus 0
haftmann@61776
    59
defines
nipkow@63882
    60
  sum_list = sum_list.F ..
haftmann@58320
    61
 
haftmann@58320
    62
end
haftmann@58320
    63
haftmann@58320
    64
context comm_monoid_add
haftmann@58320
    65
begin
haftmann@58320
    66
nipkow@63882
    67
sublocale sum_list: comm_monoid_list plus 0
ballarin@61566
    68
rewrites
nipkow@63882
    69
  "monoid_list.F plus 0 = sum_list"
haftmann@58320
    70
proof -
haftmann@58320
    71
  show "comm_monoid_list plus 0" ..
nipkow@63882
    72
  then interpret sum_list: comm_monoid_list plus 0 .
nipkow@63882
    73
  from sum_list_def show "monoid_list.F plus 0 = sum_list" by simp
haftmann@58101
    74
qed
haftmann@58101
    75
nipkow@64267
    76
sublocale sum: comm_monoid_list_set plus 0
ballarin@61566
    77
rewrites
nipkow@63882
    78
  "monoid_list.F plus 0 = sum_list"
nipkow@64267
    79
  and "comm_monoid_set.F plus 0 = sum"
haftmann@58320
    80
proof -
haftmann@58320
    81
  show "comm_monoid_list_set plus 0" ..
nipkow@64267
    82
  then interpret sum: comm_monoid_list_set plus 0 .
nipkow@63882
    83
  from sum_list_def show "monoid_list.F plus 0 = sum_list" by simp
nipkow@64267
    84
  from sum_def show "comm_monoid_set.F plus 0 = sum" by (auto intro: sym)
haftmann@58320
    85
qed
haftmann@58320
    86
haftmann@58320
    87
end
haftmann@58320
    88
wenzelm@60758
    89
text \<open>Some syntactic sugar for summing a function over a list:\<close>
wenzelm@61955
    90
syntax (ASCII)
nipkow@63882
    91
  "_sum_list" :: "pttrn => 'a list => 'b => 'b"    ("(3SUM _<-_. _)" [0, 51, 10] 10)
haftmann@58101
    92
syntax
nipkow@63882
    93
  "_sum_list" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Sum>_\<leftarrow>_. _)" [0, 51, 10] 10)
wenzelm@61799
    94
translations \<comment> \<open>Beware of argument permutation!\<close>
nipkow@63882
    95
  "\<Sum>x\<leftarrow>xs. b" == "CONST sum_list (CONST map (\<lambda>x. b) xs)"
haftmann@58101
    96
wenzelm@60758
    97
text \<open>TODO duplicates\<close>
nipkow@63882
    98
lemmas sum_list_simps = sum_list.Nil sum_list.Cons
nipkow@63882
    99
lemmas sum_list_append = sum_list.append
nipkow@63882
   100
lemmas sum_list_rev = sum_list.rev
haftmann@58320
   101
nipkow@63882
   102
lemma (in monoid_add) fold_plus_sum_list_rev:
nipkow@63882
   103
  "fold plus xs = plus (sum_list (rev xs))"
haftmann@58320
   104
proof
haftmann@58320
   105
  fix x
nipkow@63882
   106
  have "fold plus xs x = sum_list (rev xs @ [x])"
nipkow@63882
   107
    by (simp add: foldr_conv_fold sum_list.eq_foldr)
nipkow@63882
   108
  also have "\<dots> = sum_list (rev xs) + x"
haftmann@58320
   109
    by simp
nipkow@63882
   110
  finally show "fold plus xs x = sum_list (rev xs) + x"
haftmann@58320
   111
    .
haftmann@58320
   112
qed
haftmann@58320
   113
nipkow@63882
   114
lemma (in comm_monoid_add) sum_list_map_remove1:
nipkow@63882
   115
  "x \<in> set xs \<Longrightarrow> sum_list (map f xs) = f x + sum_list (map f (remove1 x xs))"
haftmann@58101
   116
  by (induct xs) (auto simp add: ac_simps)
haftmann@58101
   117
nipkow@63882
   118
lemma (in monoid_add) size_list_conv_sum_list:
nipkow@63882
   119
  "size_list f xs = sum_list (map f xs) + size xs"
haftmann@58101
   120
  by (induct xs) auto
haftmann@58101
   121
haftmann@58101
   122
lemma (in monoid_add) length_concat:
nipkow@63882
   123
  "length (concat xss) = sum_list (map length xss)"
haftmann@58101
   124
  by (induct xss) simp_all
haftmann@58101
   125
haftmann@58101
   126
lemma (in monoid_add) length_product_lists:
haftmann@58101
   127
  "length (product_lists xss) = foldr op * (map length xss) 1"
haftmann@58101
   128
proof (induct xss)
haftmann@58101
   129
  case (Cons xs xss) then show ?case by (induct xs) (auto simp: length_concat o_def)
haftmann@58101
   130
qed simp
haftmann@58101
   131
nipkow@63882
   132
lemma (in monoid_add) sum_list_map_filter:
haftmann@58101
   133
  assumes "\<And>x. x \<in> set xs \<Longrightarrow> \<not> P x \<Longrightarrow> f x = 0"
nipkow@63882
   134
  shows "sum_list (map f (filter P xs)) = sum_list (map f xs)"
haftmann@58101
   135
  using assms by (induct xs) auto
haftmann@58101
   136
nipkow@64267
   137
lemma (in comm_monoid_add) distinct_sum_list_conv_Sum:
nipkow@64267
   138
  "distinct xs \<Longrightarrow> sum_list xs = Sum (set xs)"
haftmann@58101
   139
  by (induct xs) simp_all
haftmann@58101
   140
nipkow@63882
   141
lemma sum_list_upt[simp]:
nipkow@63882
   142
  "m \<le> n \<Longrightarrow> sum_list [m..<n] = \<Sum> {m..<n}"
nipkow@64267
   143
by(simp add: distinct_sum_list_conv_Sum)
nipkow@58995
   144
nipkow@63882
   145
lemma sum_list_eq_0_nat_iff_nat [simp]:
nipkow@63882
   146
  "sum_list ns = (0::nat) \<longleftrightarrow> (\<forall>n \<in> set ns. n = 0)"
haftmann@58101
   147
  by (induct ns) simp_all
haftmann@58101
   148
nipkow@63882
   149
lemma member_le_sum_list_nat:
nipkow@63882
   150
  "(n :: nat) \<in> set ns \<Longrightarrow> n \<le> sum_list ns"
haftmann@58101
   151
  by (induct ns) auto
haftmann@58101
   152
nipkow@63882
   153
lemma elem_le_sum_list_nat:
nipkow@63882
   154
  "k < size ns \<Longrightarrow> ns ! k \<le> sum_list (ns::nat list)"
nipkow@63882
   155
  by (rule member_le_sum_list_nat) simp
haftmann@58101
   156
nipkow@63882
   157
lemma sum_list_update_nat:
nipkow@63882
   158
  "k < size ns \<Longrightarrow> sum_list (ns[k := (n::nat)]) = sum_list ns + n - ns ! k"
haftmann@58101
   159
apply(induct ns arbitrary:k)
haftmann@58101
   160
 apply (auto split:nat.split)
nipkow@63882
   161
apply(drule elem_le_sum_list_nat)
haftmann@58101
   162
apply arith
haftmann@58101
   163
done
haftmann@58101
   164
nipkow@63882
   165
lemma (in monoid_add) sum_list_triv:
haftmann@58101
   166
  "(\<Sum>x\<leftarrow>xs. r) = of_nat (length xs) * r"
haftmann@58101
   167
  by (induct xs) (simp_all add: distrib_right)
haftmann@58101
   168
nipkow@63882
   169
lemma (in monoid_add) sum_list_0 [simp]:
haftmann@58101
   170
  "(\<Sum>x\<leftarrow>xs. 0) = 0"
haftmann@58101
   171
  by (induct xs) (simp_all add: distrib_right)
haftmann@58101
   172
wenzelm@61799
   173
text\<open>For non-Abelian groups \<open>xs\<close> needs to be reversed on one side:\<close>
nipkow@63882
   174
lemma (in ab_group_add) uminus_sum_list_map:
nipkow@63882
   175
  "- sum_list (map f xs) = sum_list (map (uminus \<circ> f) xs)"
haftmann@58101
   176
  by (induct xs) simp_all
haftmann@58101
   177
nipkow@63882
   178
lemma (in comm_monoid_add) sum_list_addf:
nipkow@63882
   179
  "(\<Sum>x\<leftarrow>xs. f x + g x) = sum_list (map f xs) + sum_list (map g xs)"
haftmann@58101
   180
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   181
nipkow@63882
   182
lemma (in ab_group_add) sum_list_subtractf:
nipkow@63882
   183
  "(\<Sum>x\<leftarrow>xs. f x - g x) = sum_list (map f xs) - sum_list (map g xs)"
haftmann@58101
   184
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   185
nipkow@63882
   186
lemma (in semiring_0) sum_list_const_mult:
haftmann@58101
   187
  "(\<Sum>x\<leftarrow>xs. c * f x) = c * (\<Sum>x\<leftarrow>xs. f x)"
haftmann@58101
   188
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   189
nipkow@63882
   190
lemma (in semiring_0) sum_list_mult_const:
haftmann@58101
   191
  "(\<Sum>x\<leftarrow>xs. f x * c) = (\<Sum>x\<leftarrow>xs. f x) * c"
haftmann@58101
   192
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   193
nipkow@63882
   194
lemma (in ordered_ab_group_add_abs) sum_list_abs:
nipkow@63882
   195
  "\<bar>sum_list xs\<bar> \<le> sum_list (map abs xs)"
haftmann@58101
   196
  by (induct xs) (simp_all add: order_trans [OF abs_triangle_ineq])
haftmann@58101
   197
nipkow@63882
   198
lemma sum_list_mono:
haftmann@58101
   199
  fixes f g :: "'a \<Rightarrow> 'b::{monoid_add, ordered_ab_semigroup_add}"
haftmann@58101
   200
  shows "(\<And>x. x \<in> set xs \<Longrightarrow> f x \<le> g x) \<Longrightarrow> (\<Sum>x\<leftarrow>xs. f x) \<le> (\<Sum>x\<leftarrow>xs. g x)"
haftmann@58101
   201
  by (induct xs) (simp, simp add: add_mono)
haftmann@58101
   202
nipkow@64267
   203
lemma (in monoid_add) sum_list_distinct_conv_sum_set:
nipkow@64267
   204
  "distinct xs \<Longrightarrow> sum_list (map f xs) = sum f (set xs)"
haftmann@58101
   205
  by (induct xs) simp_all
haftmann@58101
   206
nipkow@64267
   207
lemma (in monoid_add) interv_sum_list_conv_sum_set_nat:
nipkow@64267
   208
  "sum_list (map f [m..<n]) = sum f (set [m..<n])"
nipkow@64267
   209
  by (simp add: sum_list_distinct_conv_sum_set)
haftmann@58101
   210
nipkow@64267
   211
lemma (in monoid_add) interv_sum_list_conv_sum_set_int:
nipkow@64267
   212
  "sum_list (map f [k..l]) = sum f (set [k..l])"
nipkow@64267
   213
  by (simp add: sum_list_distinct_conv_sum_set)
haftmann@58101
   214
nipkow@64267
   215
text \<open>General equivalence between @{const sum_list} and @{const sum}\<close>
nipkow@64267
   216
lemma (in monoid_add) sum_list_sum_nth:
nipkow@63882
   217
  "sum_list xs = (\<Sum> i = 0 ..< length xs. xs ! i)"
nipkow@64267
   218
  using interv_sum_list_conv_sum_set_nat [of "op ! xs" 0 "length xs"] by (simp add: map_nth)
haftmann@58101
   219
nipkow@64267
   220
lemma sum_list_map_eq_sum_count:
nipkow@64267
   221
  "sum_list (map f xs) = sum (\<lambda>x. count_list xs x * f x) (set xs)"
nipkow@59728
   222
proof(induction xs)
nipkow@59728
   223
  case (Cons x xs)
nipkow@59728
   224
  show ?case (is "?l = ?r")
nipkow@59728
   225
  proof cases
nipkow@59728
   226
    assume "x \<in> set xs"
nipkow@60541
   227
    have "?l = f x + (\<Sum>x\<in>set xs. count_list xs x * f x)" by (simp add: Cons.IH)
wenzelm@60758
   228
    also have "set xs = insert x (set xs - {x})" using \<open>x \<in> set xs\<close>by blast
nipkow@60541
   229
    also have "f x + (\<Sum>x\<in>insert x (set xs - {x}). count_list xs x * f x) = ?r"
nipkow@64267
   230
      by (simp add: sum.insert_remove eq_commute)
nipkow@59728
   231
    finally show ?thesis .
nipkow@59728
   232
  next
nipkow@59728
   233
    assume "x \<notin> set xs"
nipkow@59728
   234
    hence "\<And>xa. xa \<in> set xs \<Longrightarrow> x \<noteq> xa" by blast
wenzelm@60758
   235
    thus ?thesis by (simp add: Cons.IH \<open>x \<notin> set xs\<close>)
nipkow@59728
   236
  qed
nipkow@59728
   237
qed simp
nipkow@59728
   238
nipkow@64267
   239
lemma sum_list_map_eq_sum_count2:
nipkow@59728
   240
assumes "set xs \<subseteq> X" "finite X"
nipkow@64267
   241
shows "sum_list (map f xs) = sum (\<lambda>x. count_list xs x * f x) X"
nipkow@59728
   242
proof-
nipkow@60541
   243
  let ?F = "\<lambda>x. count_list xs x * f x"
nipkow@64267
   244
  have "sum ?F X = sum ?F (set xs \<union> (X - set xs))"
nipkow@59728
   245
    using Un_absorb1[OF assms(1)] by(simp)
nipkow@64267
   246
  also have "\<dots> = sum ?F (set xs)"
nipkow@59728
   247
    using assms(2)
nipkow@64267
   248
    by(simp add: sum.union_disjoint[OF _ _ Diff_disjoint] del: Un_Diff_cancel)
nipkow@64267
   249
  finally show ?thesis by(simp add:sum_list_map_eq_sum_count)
nipkow@59728
   250
qed
nipkow@59728
   251
nipkow@63882
   252
lemma sum_list_nonneg: 
nipkow@63882
   253
    "(\<And>x. x \<in> set xs \<Longrightarrow> (x :: 'a :: ordered_comm_monoid_add) \<ge> 0) \<Longrightarrow> sum_list xs \<ge> 0"
eberlm@63099
   254
  by (induction xs) simp_all
eberlm@63099
   255
nipkow@63882
   256
lemma (in monoid_add) sum_list_map_filter':
nipkow@63882
   257
  "sum_list (map f (filter P xs)) = sum_list (map (\<lambda>x. if P x then f x else 0) xs)"
eberlm@63099
   258
  by (induction xs) simp_all
eberlm@63099
   259
nipkow@63882
   260
lemma sum_list_cong [fundef_cong]:
eberlm@63099
   261
  assumes "xs = ys"
eberlm@63099
   262
  assumes "\<And>x. x \<in> set xs \<Longrightarrow> f x = g x"
nipkow@63882
   263
  shows    "sum_list (map f xs) = sum_list (map g ys)"
eberlm@63099
   264
proof -
nipkow@63882
   265
  from assms(2) have "sum_list (map f xs) = sum_list (map g xs)"
eberlm@63099
   266
    by (induction xs) simp_all
eberlm@63099
   267
  with assms(1) show ?thesis by simp
eberlm@63099
   268
qed
eberlm@63099
   269
haftmann@58101
   270
wenzelm@60758
   271
subsection \<open>Further facts about @{const List.n_lists}\<close>
haftmann@58101
   272
haftmann@58101
   273
lemma length_n_lists: "length (List.n_lists n xs) = length xs ^ n"
nipkow@63882
   274
  by (induct n) (auto simp add: comp_def length_concat sum_list_triv)
haftmann@58101
   275
haftmann@58101
   276
lemma distinct_n_lists:
haftmann@58101
   277
  assumes "distinct xs"
haftmann@58101
   278
  shows "distinct (List.n_lists n xs)"
haftmann@58101
   279
proof (rule card_distinct)
haftmann@58101
   280
  from assms have card_length: "card (set xs) = length xs" by (rule distinct_card)
haftmann@58101
   281
  have "card (set (List.n_lists n xs)) = card (set xs) ^ n"
haftmann@58101
   282
  proof (induct n)
haftmann@58101
   283
    case 0 then show ?case by simp
haftmann@58101
   284
  next
haftmann@58101
   285
    case (Suc n)
haftmann@58101
   286
    moreover have "card (\<Union>ys\<in>set (List.n_lists n xs). (\<lambda>y. y # ys) ` set xs)
haftmann@58101
   287
      = (\<Sum>ys\<in>set (List.n_lists n xs). card ((\<lambda>y. y # ys) ` set xs))"
haftmann@58101
   288
      by (rule card_UN_disjoint) auto
haftmann@58101
   289
    moreover have "\<And>ys. card ((\<lambda>y. y # ys) ` set xs) = card (set xs)"
haftmann@58101
   290
      by (rule card_image) (simp add: inj_on_def)
haftmann@58101
   291
    ultimately show ?case by auto
haftmann@58101
   292
  qed
haftmann@58101
   293
  also have "\<dots> = length xs ^ n" by (simp add: card_length)
haftmann@58101
   294
  finally show "card (set (List.n_lists n xs)) = length (List.n_lists n xs)"
haftmann@58101
   295
    by (simp add: length_n_lists)
haftmann@58101
   296
qed
haftmann@58101
   297
haftmann@58101
   298
wenzelm@60758
   299
subsection \<open>Tools setup\<close>
haftmann@58101
   300
nipkow@64267
   301
lemmas sum_code = sum.set_conv_list
haftmann@58320
   302
nipkow@64267
   303
lemma sum_set_upto_conv_sum_list_int [code_unfold]:
nipkow@64267
   304
  "sum f (set [i..j::int]) = sum_list (map f [i..j])"
nipkow@64267
   305
  by (simp add: interv_sum_list_conv_sum_set_int)
haftmann@58101
   306
nipkow@64267
   307
lemma sum_set_upt_conv_sum_list_nat [code_unfold]:
nipkow@64267
   308
  "sum f (set [m..<n]) = sum_list (map f [m..<n])"
nipkow@64267
   309
  by (simp add: interv_sum_list_conv_sum_set_nat)
haftmann@58101
   310
nipkow@63882
   311
lemma sum_list_transfer[transfer_rule]:
wenzelm@63343
   312
  includes lifting_syntax
haftmann@58101
   313
  assumes [transfer_rule]: "A 0 0"
haftmann@58101
   314
  assumes [transfer_rule]: "(A ===> A ===> A) op + op +"
nipkow@63882
   315
  shows "(list_all2 A ===> A) sum_list sum_list"
nipkow@63882
   316
  unfolding sum_list.eq_foldr [abs_def]
haftmann@58101
   317
  by transfer_prover
haftmann@58101
   318
haftmann@58368
   319
wenzelm@60758
   320
subsection \<open>List product\<close>
haftmann@58368
   321
haftmann@58368
   322
context monoid_mult
haftmann@58368
   323
begin
haftmann@58368
   324
nipkow@63882
   325
sublocale prod_list: monoid_list times 1
haftmann@61776
   326
defines
nipkow@63882
   327
  prod_list = prod_list.F ..
haftmann@58368
   328
haftmann@58320
   329
end
haftmann@58368
   330
haftmann@58368
   331
context comm_monoid_mult
haftmann@58368
   332
begin
haftmann@58368
   333
nipkow@63882
   334
sublocale prod_list: comm_monoid_list times 1
ballarin@61566
   335
rewrites
nipkow@63882
   336
  "monoid_list.F times 1 = prod_list"
haftmann@58368
   337
proof -
haftmann@58368
   338
  show "comm_monoid_list times 1" ..
nipkow@63882
   339
  then interpret prod_list: comm_monoid_list times 1 .
nipkow@63882
   340
  from prod_list_def show "monoid_list.F times 1 = prod_list" by simp
haftmann@58368
   341
qed
haftmann@58368
   342
nipkow@64272
   343
sublocale prod: comm_monoid_list_set times 1
ballarin@61566
   344
rewrites
nipkow@63882
   345
  "monoid_list.F times 1 = prod_list"
nipkow@64272
   346
  and "comm_monoid_set.F times 1 = prod"
haftmann@58368
   347
proof -
haftmann@58368
   348
  show "comm_monoid_list_set times 1" ..
nipkow@64272
   349
  then interpret prod: comm_monoid_list_set times 1 .
nipkow@63882
   350
  from prod_list_def show "monoid_list.F times 1 = prod_list" by simp
nipkow@64272
   351
  from prod_def show "comm_monoid_set.F times 1 = prod" by (auto intro: sym)
haftmann@58368
   352
qed
haftmann@58368
   353
haftmann@58368
   354
end
haftmann@58368
   355
nipkow@63882
   356
lemma prod_list_cong [fundef_cong]:
eberlm@63099
   357
  assumes "xs = ys"
eberlm@63099
   358
  assumes "\<And>x. x \<in> set xs \<Longrightarrow> f x = g x"
nipkow@63882
   359
  shows    "prod_list (map f xs) = prod_list (map g ys)"
eberlm@63099
   360
proof -
nipkow@63882
   361
  from assms(2) have "prod_list (map f xs) = prod_list (map g xs)"
eberlm@63099
   362
    by (induction xs) simp_all
eberlm@63099
   363
  with assms(1) show ?thesis by simp
eberlm@63099
   364
qed
eberlm@63099
   365
nipkow@63882
   366
lemma prod_list_zero_iff: 
nipkow@63882
   367
  "prod_list xs = 0 \<longleftrightarrow> (0 :: 'a :: {semiring_no_zero_divisors, semiring_1}) \<in> set xs"
eberlm@63317
   368
  by (induction xs) simp_all
eberlm@63317
   369
wenzelm@60758
   370
text \<open>Some syntactic sugar:\<close>
haftmann@58368
   371
wenzelm@61955
   372
syntax (ASCII)
nipkow@63882
   373
  "_prod_list" :: "pttrn => 'a list => 'b => 'b"    ("(3PROD _<-_. _)" [0, 51, 10] 10)
wenzelm@61955
   374
syntax
nipkow@63882
   375
  "_prod_list" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10)
wenzelm@61799
   376
translations \<comment> \<open>Beware of argument permutation!\<close>
nipkow@63882
   377
  "\<Prod>x\<leftarrow>xs. b" \<rightleftharpoons> "CONST prod_list (CONST map (\<lambda>x. b) xs)"
haftmann@58368
   378
haftmann@58368
   379
end