src/HOL/Groups_List.thy
author ballarin
Wed Nov 04 08:13:52 2015 +0100 (2015-11-04)
changeset 61566 c3d6e570ccef
parent 61378 3e04c9ca001a
child 61605 1bf7b186542e
permissions -rw-r--r--
Keyword 'rewrites' identifies rewrite morphisms.
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
no_notation times (infixl "*" 70)
haftmann@58320
    10
no_notation Groups.one ("1")
haftmann@58320
    11
 
haftmann@58320
    12
locale monoid_list = monoid
haftmann@58320
    13
begin
haftmann@58320
    14
 
haftmann@58320
    15
definition F :: "'a list \<Rightarrow> 'a"
haftmann@58320
    16
where
haftmann@58320
    17
  eq_foldr [code]: "F xs = foldr f xs 1"
haftmann@58320
    18
 
haftmann@58320
    19
lemma Nil [simp]:
haftmann@58320
    20
  "F [] = 1"
haftmann@58320
    21
  by (simp add: eq_foldr)
haftmann@58320
    22
 
haftmann@58320
    23
lemma Cons [simp]:
haftmann@58320
    24
  "F (x # xs) = x * F xs"
haftmann@58320
    25
  by (simp add: eq_foldr)
haftmann@58320
    26
 
haftmann@58320
    27
lemma append [simp]:
haftmann@58320
    28
  "F (xs @ ys) = F xs * F ys"
haftmann@58320
    29
  by (induct xs) (simp_all add: assoc)
haftmann@58320
    30
 
haftmann@58320
    31
end
haftmann@58101
    32
haftmann@58320
    33
locale comm_monoid_list = comm_monoid + monoid_list
haftmann@58320
    34
begin
haftmann@58320
    35
 
haftmann@58320
    36
lemma rev [simp]:
haftmann@58320
    37
  "F (rev xs) = F xs"
haftmann@58320
    38
  by (simp add: eq_foldr foldr_fold  fold_rev fun_eq_iff assoc left_commute)
haftmann@58320
    39
 
haftmann@58320
    40
end
haftmann@58320
    41
 
haftmann@58320
    42
locale comm_monoid_list_set = list: comm_monoid_list + set: comm_monoid_set
haftmann@58320
    43
begin
haftmann@58101
    44
haftmann@58320
    45
lemma distinct_set_conv_list:
haftmann@58320
    46
  "distinct xs \<Longrightarrow> set.F g (set xs) = list.F (map g xs)"
haftmann@58320
    47
  by (induct xs) simp_all
haftmann@58101
    48
haftmann@58320
    49
lemma set_conv_list [code]:
haftmann@58320
    50
  "set.F g (set xs) = list.F (map g (remdups xs))"
haftmann@58320
    51
  by (simp add: distinct_set_conv_list [symmetric])
haftmann@58320
    52
haftmann@58320
    53
end
haftmann@58320
    54
haftmann@58320
    55
notation times (infixl "*" 70)
haftmann@58320
    56
notation Groups.one ("1")
haftmann@58320
    57
haftmann@58320
    58
wenzelm@60758
    59
subsection \<open>List summation\<close>
haftmann@58320
    60
haftmann@58320
    61
context monoid_add
haftmann@58320
    62
begin
haftmann@58320
    63
haftmann@58320
    64
definition listsum :: "'a list \<Rightarrow> 'a"
haftmann@58320
    65
where
haftmann@58320
    66
  "listsum  = monoid_list.F plus 0"
haftmann@58101
    67
haftmann@58320
    68
sublocale listsum!: monoid_list plus 0
ballarin@61566
    69
rewrites
haftmann@58320
    70
 "monoid_list.F plus 0 = listsum"
haftmann@58320
    71
proof -
haftmann@58320
    72
  show "monoid_list plus 0" ..
haftmann@58320
    73
  then interpret listsum!: monoid_list plus 0 .
haftmann@58320
    74
  from listsum_def show "monoid_list.F plus 0 = listsum" by rule
haftmann@58320
    75
qed
haftmann@58320
    76
 
haftmann@58320
    77
end
haftmann@58320
    78
haftmann@58320
    79
context comm_monoid_add
haftmann@58320
    80
begin
haftmann@58320
    81
haftmann@58320
    82
sublocale listsum!: comm_monoid_list plus 0
ballarin@61566
    83
rewrites
haftmann@58320
    84
  "monoid_list.F plus 0 = listsum"
haftmann@58320
    85
proof -
haftmann@58320
    86
  show "comm_monoid_list plus 0" ..
haftmann@58320
    87
  then interpret listsum!: comm_monoid_list plus 0 .
haftmann@58320
    88
  from listsum_def show "monoid_list.F plus 0 = listsum" by rule
haftmann@58101
    89
qed
haftmann@58101
    90
haftmann@58320
    91
sublocale setsum!: comm_monoid_list_set plus 0
ballarin@61566
    92
rewrites
haftmann@58320
    93
  "monoid_list.F plus 0 = listsum"
haftmann@58320
    94
  and "comm_monoid_set.F plus 0 = setsum"
haftmann@58320
    95
proof -
haftmann@58320
    96
  show "comm_monoid_list_set plus 0" ..
haftmann@58320
    97
  then interpret setsum!: comm_monoid_list_set plus 0 .
haftmann@58320
    98
  from listsum_def show "monoid_list.F plus 0 = listsum" by rule
haftmann@58320
    99
  from setsum_def show "comm_monoid_set.F plus 0 = setsum" by rule
haftmann@58320
   100
qed
haftmann@58320
   101
haftmann@58320
   102
end
haftmann@58320
   103
wenzelm@60758
   104
text \<open>Some syntactic sugar for summing a function over a list:\<close>
haftmann@58101
   105
haftmann@58101
   106
syntax
haftmann@58101
   107
  "_listsum" :: "pttrn => 'a list => 'b => 'b"    ("(3SUM _<-_. _)" [0, 51, 10] 10)
haftmann@58101
   108
syntax (xsymbols)
haftmann@58101
   109
  "_listsum" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Sum>_\<leftarrow>_. _)" [0, 51, 10] 10)
haftmann@58101
   110
wenzelm@60758
   111
translations -- \<open>Beware of argument permutation!\<close>
haftmann@58101
   112
  "SUM x<-xs. b" == "CONST listsum (CONST map (%x. b) xs)"
haftmann@58101
   113
  "\<Sum>x\<leftarrow>xs. b" == "CONST listsum (CONST map (%x. b) xs)"
haftmann@58101
   114
wenzelm@60758
   115
text \<open>TODO duplicates\<close>
haftmann@58320
   116
lemmas listsum_simps = listsum.Nil listsum.Cons
haftmann@58320
   117
lemmas listsum_append = listsum.append
haftmann@58320
   118
lemmas listsum_rev = listsum.rev
haftmann@58320
   119
haftmann@58320
   120
lemma (in monoid_add) fold_plus_listsum_rev:
haftmann@58320
   121
  "fold plus xs = plus (listsum (rev xs))"
haftmann@58320
   122
proof
haftmann@58320
   123
  fix x
haftmann@58320
   124
  have "fold plus xs x = listsum (rev xs @ [x])"
haftmann@58320
   125
    by (simp add: foldr_conv_fold listsum.eq_foldr)
haftmann@58320
   126
  also have "\<dots> = listsum (rev xs) + x"
haftmann@58320
   127
    by simp
haftmann@58320
   128
  finally show "fold plus xs x = listsum (rev xs) + x"
haftmann@58320
   129
    .
haftmann@58320
   130
qed
haftmann@58320
   131
haftmann@58101
   132
lemma (in comm_monoid_add) listsum_map_remove1:
haftmann@58101
   133
  "x \<in> set xs \<Longrightarrow> listsum (map f xs) = f x + listsum (map f (remove1 x xs))"
haftmann@58101
   134
  by (induct xs) (auto simp add: ac_simps)
haftmann@58101
   135
haftmann@58101
   136
lemma (in monoid_add) size_list_conv_listsum:
haftmann@58101
   137
  "size_list f xs = listsum (map f xs) + size xs"
haftmann@58101
   138
  by (induct xs) auto
haftmann@58101
   139
haftmann@58101
   140
lemma (in monoid_add) length_concat:
haftmann@58101
   141
  "length (concat xss) = listsum (map length xss)"
haftmann@58101
   142
  by (induct xss) simp_all
haftmann@58101
   143
haftmann@58101
   144
lemma (in monoid_add) length_product_lists:
haftmann@58101
   145
  "length (product_lists xss) = foldr op * (map length xss) 1"
haftmann@58101
   146
proof (induct xss)
haftmann@58101
   147
  case (Cons xs xss) then show ?case by (induct xs) (auto simp: length_concat o_def)
haftmann@58101
   148
qed simp
haftmann@58101
   149
haftmann@58101
   150
lemma (in monoid_add) listsum_map_filter:
haftmann@58101
   151
  assumes "\<And>x. x \<in> set xs \<Longrightarrow> \<not> P x \<Longrightarrow> f x = 0"
haftmann@58101
   152
  shows "listsum (map f (filter P xs)) = listsum (map f xs)"
haftmann@58101
   153
  using assms by (induct xs) auto
haftmann@58101
   154
haftmann@58101
   155
lemma (in comm_monoid_add) distinct_listsum_conv_Setsum:
haftmann@58101
   156
  "distinct xs \<Longrightarrow> listsum xs = Setsum (set xs)"
haftmann@58101
   157
  by (induct xs) simp_all
haftmann@58101
   158
nipkow@58995
   159
lemma listsum_upt[simp]:
nipkow@58995
   160
  "m \<le> n \<Longrightarrow> listsum [m..<n] = \<Sum> {m..<n}"
nipkow@58995
   161
by(simp add: distinct_listsum_conv_Setsum)
nipkow@58995
   162
haftmann@58101
   163
lemma listsum_eq_0_nat_iff_nat [simp]:
haftmann@58101
   164
  "listsum ns = (0::nat) \<longleftrightarrow> (\<forall>n \<in> set ns. n = 0)"
haftmann@58101
   165
  by (induct ns) simp_all
haftmann@58101
   166
haftmann@58101
   167
lemma member_le_listsum_nat:
haftmann@58101
   168
  "(n :: nat) \<in> set ns \<Longrightarrow> n \<le> listsum ns"
haftmann@58101
   169
  by (induct ns) auto
haftmann@58101
   170
haftmann@58101
   171
lemma elem_le_listsum_nat:
haftmann@58101
   172
  "k < size ns \<Longrightarrow> ns ! k \<le> listsum (ns::nat list)"
haftmann@58101
   173
  by (rule member_le_listsum_nat) simp
haftmann@58101
   174
haftmann@58101
   175
lemma listsum_update_nat:
haftmann@58101
   176
  "k < size ns \<Longrightarrow> listsum (ns[k := (n::nat)]) = listsum ns + n - ns ! k"
haftmann@58101
   177
apply(induct ns arbitrary:k)
haftmann@58101
   178
 apply (auto split:nat.split)
haftmann@58101
   179
apply(drule elem_le_listsum_nat)
haftmann@58101
   180
apply arith
haftmann@58101
   181
done
haftmann@58101
   182
haftmann@58101
   183
lemma (in monoid_add) listsum_triv:
haftmann@58101
   184
  "(\<Sum>x\<leftarrow>xs. r) = of_nat (length xs) * r"
haftmann@58101
   185
  by (induct xs) (simp_all add: distrib_right)
haftmann@58101
   186
haftmann@58101
   187
lemma (in monoid_add) listsum_0 [simp]:
haftmann@58101
   188
  "(\<Sum>x\<leftarrow>xs. 0) = 0"
haftmann@58101
   189
  by (induct xs) (simp_all add: distrib_right)
haftmann@58101
   190
wenzelm@60758
   191
text\<open>For non-Abelian groups @{text xs} needs to be reversed on one side:\<close>
haftmann@58101
   192
lemma (in ab_group_add) uminus_listsum_map:
haftmann@58101
   193
  "- listsum (map f xs) = listsum (map (uminus \<circ> f) xs)"
haftmann@58101
   194
  by (induct xs) simp_all
haftmann@58101
   195
haftmann@58101
   196
lemma (in comm_monoid_add) listsum_addf:
haftmann@58101
   197
  "(\<Sum>x\<leftarrow>xs. f x + g x) = listsum (map f xs) + listsum (map g xs)"
haftmann@58101
   198
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   199
haftmann@58101
   200
lemma (in ab_group_add) listsum_subtractf:
haftmann@58101
   201
  "(\<Sum>x\<leftarrow>xs. f x - g x) = listsum (map f xs) - listsum (map g xs)"
haftmann@58101
   202
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   203
haftmann@58101
   204
lemma (in semiring_0) listsum_const_mult:
haftmann@58101
   205
  "(\<Sum>x\<leftarrow>xs. c * f x) = c * (\<Sum>x\<leftarrow>xs. f x)"
haftmann@58101
   206
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   207
haftmann@58101
   208
lemma (in semiring_0) listsum_mult_const:
haftmann@58101
   209
  "(\<Sum>x\<leftarrow>xs. f x * c) = (\<Sum>x\<leftarrow>xs. f x) * c"
haftmann@58101
   210
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   211
haftmann@58101
   212
lemma (in ordered_ab_group_add_abs) listsum_abs:
haftmann@58101
   213
  "\<bar>listsum xs\<bar> \<le> listsum (map abs xs)"
haftmann@58101
   214
  by (induct xs) (simp_all add: order_trans [OF abs_triangle_ineq])
haftmann@58101
   215
haftmann@58101
   216
lemma listsum_mono:
haftmann@58101
   217
  fixes f g :: "'a \<Rightarrow> 'b::{monoid_add, ordered_ab_semigroup_add}"
haftmann@58101
   218
  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
   219
  by (induct xs) (simp, simp add: add_mono)
haftmann@58101
   220
haftmann@58101
   221
lemma (in monoid_add) listsum_distinct_conv_setsum_set:
haftmann@58101
   222
  "distinct xs \<Longrightarrow> listsum (map f xs) = setsum f (set xs)"
haftmann@58101
   223
  by (induct xs) simp_all
haftmann@58101
   224
haftmann@58101
   225
lemma (in monoid_add) interv_listsum_conv_setsum_set_nat:
haftmann@58101
   226
  "listsum (map f [m..<n]) = setsum f (set [m..<n])"
haftmann@58101
   227
  by (simp add: listsum_distinct_conv_setsum_set)
haftmann@58101
   228
haftmann@58101
   229
lemma (in monoid_add) interv_listsum_conv_setsum_set_int:
haftmann@58101
   230
  "listsum (map f [k..l]) = setsum f (set [k..l])"
haftmann@58101
   231
  by (simp add: listsum_distinct_conv_setsum_set)
haftmann@58101
   232
wenzelm@60758
   233
text \<open>General equivalence between @{const listsum} and @{const setsum}\<close>
haftmann@58101
   234
lemma (in monoid_add) listsum_setsum_nth:
haftmann@58101
   235
  "listsum xs = (\<Sum> i = 0 ..< length xs. xs ! i)"
haftmann@58101
   236
  using interv_listsum_conv_setsum_set_nat [of "op ! xs" 0 "length xs"] by (simp add: map_nth)
haftmann@58101
   237
nipkow@59728
   238
lemma listsum_map_eq_setsum_count:
nipkow@60541
   239
  "listsum (map f xs) = setsum (\<lambda>x. count_list xs x * f x) (set xs)"
nipkow@59728
   240
proof(induction xs)
nipkow@59728
   241
  case (Cons x xs)
nipkow@59728
   242
  show ?case (is "?l = ?r")
nipkow@59728
   243
  proof cases
nipkow@59728
   244
    assume "x \<in> set xs"
nipkow@60541
   245
    have "?l = f x + (\<Sum>x\<in>set xs. count_list xs x * f x)" by (simp add: Cons.IH)
wenzelm@60758
   246
    also have "set xs = insert x (set xs - {x})" using \<open>x \<in> set xs\<close>by blast
nipkow@60541
   247
    also have "f x + (\<Sum>x\<in>insert x (set xs - {x}). count_list xs x * f x) = ?r"
nipkow@59728
   248
      by (simp add: setsum.insert_remove eq_commute)
nipkow@59728
   249
    finally show ?thesis .
nipkow@59728
   250
  next
nipkow@59728
   251
    assume "x \<notin> set xs"
nipkow@59728
   252
    hence "\<And>xa. xa \<in> set xs \<Longrightarrow> x \<noteq> xa" by blast
wenzelm@60758
   253
    thus ?thesis by (simp add: Cons.IH \<open>x \<notin> set xs\<close>)
nipkow@59728
   254
  qed
nipkow@59728
   255
qed simp
nipkow@59728
   256
nipkow@59728
   257
lemma listsum_map_eq_setsum_count2:
nipkow@59728
   258
assumes "set xs \<subseteq> X" "finite X"
nipkow@60541
   259
shows "listsum (map f xs) = setsum (\<lambda>x. count_list xs x * f x) X"
nipkow@59728
   260
proof-
nipkow@60541
   261
  let ?F = "\<lambda>x. count_list xs x * f x"
nipkow@59728
   262
  have "setsum ?F X = setsum ?F (set xs \<union> (X - set xs))"
nipkow@59728
   263
    using Un_absorb1[OF assms(1)] by(simp)
nipkow@59728
   264
  also have "\<dots> = setsum ?F (set xs)"
nipkow@59728
   265
    using assms(2)
nipkow@59728
   266
    by(simp add: setsum.union_disjoint[OF _ _ Diff_disjoint] del: Un_Diff_cancel)
nipkow@59728
   267
  finally show ?thesis by(simp add:listsum_map_eq_setsum_count)
nipkow@59728
   268
qed
nipkow@59728
   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"
haftmann@58101
   274
  by (induct n) (auto simp add: comp_def length_concat listsum_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
haftmann@58320
   301
lemmas setsum_code = setsum.set_conv_list
haftmann@58320
   302
haftmann@58101
   303
lemma setsum_set_upto_conv_listsum_int [code_unfold]:
haftmann@58101
   304
  "setsum f (set [i..j::int]) = listsum (map f [i..j])"
haftmann@58101
   305
  by (simp add: interv_listsum_conv_setsum_set_int)
haftmann@58101
   306
haftmann@58101
   307
lemma setsum_set_upt_conv_listsum_nat [code_unfold]:
haftmann@58101
   308
  "setsum f (set [m..<n]) = listsum (map f [m..<n])"
haftmann@58101
   309
  by (simp add: interv_listsum_conv_setsum_set_nat)
haftmann@58101
   310
haftmann@58101
   311
context
haftmann@58101
   312
begin
haftmann@58101
   313
haftmann@58101
   314
interpretation lifting_syntax .
haftmann@58101
   315
haftmann@58101
   316
lemma listsum_transfer[transfer_rule]:
haftmann@58101
   317
  assumes [transfer_rule]: "A 0 0"
haftmann@58101
   318
  assumes [transfer_rule]: "(A ===> A ===> A) op + op +"
haftmann@58101
   319
  shows "(list_all2 A ===> A) listsum listsum"
haftmann@58320
   320
  unfolding listsum.eq_foldr [abs_def]
haftmann@58101
   321
  by transfer_prover
haftmann@58101
   322
haftmann@58101
   323
end
haftmann@58101
   324
haftmann@58368
   325
wenzelm@60758
   326
subsection \<open>List product\<close>
haftmann@58368
   327
haftmann@58368
   328
context monoid_mult
haftmann@58368
   329
begin
haftmann@58368
   330
haftmann@58368
   331
definition listprod :: "'a list \<Rightarrow> 'a"
haftmann@58368
   332
where
haftmann@58368
   333
  "listprod  = monoid_list.F times 1"
haftmann@58368
   334
haftmann@58368
   335
sublocale listprod!: monoid_list times 1
ballarin@61566
   336
rewrites
haftmann@58368
   337
  "monoid_list.F times 1 = listprod"
haftmann@58368
   338
proof -
haftmann@58368
   339
  show "monoid_list times 1" ..
haftmann@58368
   340
  then interpret listprod!: monoid_list times 1 .
haftmann@58368
   341
  from listprod_def show "monoid_list.F times 1 = listprod" by rule
haftmann@58368
   342
qed
haftmann@58368
   343
haftmann@58320
   344
end
haftmann@58368
   345
haftmann@58368
   346
context comm_monoid_mult
haftmann@58368
   347
begin
haftmann@58368
   348
haftmann@58368
   349
sublocale listprod!: comm_monoid_list times 1
ballarin@61566
   350
rewrites
haftmann@58368
   351
  "monoid_list.F times 1 = listprod"
haftmann@58368
   352
proof -
haftmann@58368
   353
  show "comm_monoid_list times 1" ..
haftmann@58368
   354
  then interpret listprod!: comm_monoid_list times 1 .
haftmann@58368
   355
  from listprod_def show "monoid_list.F times 1 = listprod" by rule
haftmann@58368
   356
qed
haftmann@58368
   357
haftmann@58368
   358
sublocale setprod!: comm_monoid_list_set times 1
ballarin@61566
   359
rewrites
haftmann@58368
   360
  "monoid_list.F times 1 = listprod"
haftmann@58368
   361
  and "comm_monoid_set.F times 1 = setprod"
haftmann@58368
   362
proof -
haftmann@58368
   363
  show "comm_monoid_list_set times 1" ..
haftmann@58368
   364
  then interpret setprod!: comm_monoid_list_set times 1 .
haftmann@58368
   365
  from listprod_def show "monoid_list.F times 1 = listprod" by rule
haftmann@58368
   366
  from setprod_def show "comm_monoid_set.F times 1 = setprod" by rule
haftmann@58368
   367
qed
haftmann@58368
   368
haftmann@58368
   369
end
haftmann@58368
   370
wenzelm@60758
   371
text \<open>Some syntactic sugar:\<close>
haftmann@58368
   372
haftmann@58368
   373
syntax
haftmann@58368
   374
  "_listprod" :: "pttrn => 'a list => 'b => 'b"    ("(3PROD _<-_. _)" [0, 51, 10] 10)
haftmann@58368
   375
syntax (xsymbols)
haftmann@58368
   376
  "_listprod" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10)
haftmann@58368
   377
wenzelm@60758
   378
translations -- \<open>Beware of argument permutation!\<close>
haftmann@58368
   379
  "PROD x<-xs. b" == "CONST listprod (CONST map (%x. b) xs)"
haftmann@58368
   380
  "\<Prod>x\<leftarrow>xs. b" == "CONST listprod (CONST map (%x. b) xs)"
haftmann@58368
   381
haftmann@58368
   382
end