src/HOL/Groups_List.thy
author wenzelm
Tue Sep 01 22:32:58 2015 +0200 (2015-09-01)
changeset 61076 bdc1e2f0a86a
parent 60758 d8d85a8172b5
child 61378 3e04c9ca001a
permissions -rw-r--r--
eliminated \<Colon>;
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
haftmann@58320
    69
where
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
haftmann@58320
    83
where
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
haftmann@58320
    92
where
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
syntax (HTML output)
haftmann@58101
   111
  "_listsum" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Sum>_\<leftarrow>_. _)" [0, 51, 10] 10)
haftmann@58101
   112
wenzelm@60758
   113
translations -- \<open>Beware of argument permutation!\<close>
haftmann@58101
   114
  "SUM x<-xs. b" == "CONST listsum (CONST map (%x. b) xs)"
haftmann@58101
   115
  "\<Sum>x\<leftarrow>xs. b" == "CONST listsum (CONST map (%x. b) xs)"
haftmann@58101
   116
wenzelm@60758
   117
text \<open>TODO duplicates\<close>
haftmann@58320
   118
lemmas listsum_simps = listsum.Nil listsum.Cons
haftmann@58320
   119
lemmas listsum_append = listsum.append
haftmann@58320
   120
lemmas listsum_rev = listsum.rev
haftmann@58320
   121
haftmann@58320
   122
lemma (in monoid_add) fold_plus_listsum_rev:
haftmann@58320
   123
  "fold plus xs = plus (listsum (rev xs))"
haftmann@58320
   124
proof
haftmann@58320
   125
  fix x
haftmann@58320
   126
  have "fold plus xs x = listsum (rev xs @ [x])"
haftmann@58320
   127
    by (simp add: foldr_conv_fold listsum.eq_foldr)
haftmann@58320
   128
  also have "\<dots> = listsum (rev xs) + x"
haftmann@58320
   129
    by simp
haftmann@58320
   130
  finally show "fold plus xs x = listsum (rev xs) + x"
haftmann@58320
   131
    .
haftmann@58320
   132
qed
haftmann@58320
   133
haftmann@58101
   134
lemma (in comm_monoid_add) listsum_map_remove1:
haftmann@58101
   135
  "x \<in> set xs \<Longrightarrow> listsum (map f xs) = f x + listsum (map f (remove1 x xs))"
haftmann@58101
   136
  by (induct xs) (auto simp add: ac_simps)
haftmann@58101
   137
haftmann@58101
   138
lemma (in monoid_add) size_list_conv_listsum:
haftmann@58101
   139
  "size_list f xs = listsum (map f xs) + size xs"
haftmann@58101
   140
  by (induct xs) auto
haftmann@58101
   141
haftmann@58101
   142
lemma (in monoid_add) length_concat:
haftmann@58101
   143
  "length (concat xss) = listsum (map length xss)"
haftmann@58101
   144
  by (induct xss) simp_all
haftmann@58101
   145
haftmann@58101
   146
lemma (in monoid_add) length_product_lists:
haftmann@58101
   147
  "length (product_lists xss) = foldr op * (map length xss) 1"
haftmann@58101
   148
proof (induct xss)
haftmann@58101
   149
  case (Cons xs xss) then show ?case by (induct xs) (auto simp: length_concat o_def)
haftmann@58101
   150
qed simp
haftmann@58101
   151
haftmann@58101
   152
lemma (in monoid_add) listsum_map_filter:
haftmann@58101
   153
  assumes "\<And>x. x \<in> set xs \<Longrightarrow> \<not> P x \<Longrightarrow> f x = 0"
haftmann@58101
   154
  shows "listsum (map f (filter P xs)) = listsum (map f xs)"
haftmann@58101
   155
  using assms by (induct xs) auto
haftmann@58101
   156
haftmann@58101
   157
lemma (in comm_monoid_add) distinct_listsum_conv_Setsum:
haftmann@58101
   158
  "distinct xs \<Longrightarrow> listsum xs = Setsum (set xs)"
haftmann@58101
   159
  by (induct xs) simp_all
haftmann@58101
   160
nipkow@58995
   161
lemma listsum_upt[simp]:
nipkow@58995
   162
  "m \<le> n \<Longrightarrow> listsum [m..<n] = \<Sum> {m..<n}"
nipkow@58995
   163
by(simp add: distinct_listsum_conv_Setsum)
nipkow@58995
   164
haftmann@58101
   165
lemma listsum_eq_0_nat_iff_nat [simp]:
haftmann@58101
   166
  "listsum ns = (0::nat) \<longleftrightarrow> (\<forall>n \<in> set ns. n = 0)"
haftmann@58101
   167
  by (induct ns) simp_all
haftmann@58101
   168
haftmann@58101
   169
lemma member_le_listsum_nat:
haftmann@58101
   170
  "(n :: nat) \<in> set ns \<Longrightarrow> n \<le> listsum ns"
haftmann@58101
   171
  by (induct ns) auto
haftmann@58101
   172
haftmann@58101
   173
lemma elem_le_listsum_nat:
haftmann@58101
   174
  "k < size ns \<Longrightarrow> ns ! k \<le> listsum (ns::nat list)"
haftmann@58101
   175
  by (rule member_le_listsum_nat) simp
haftmann@58101
   176
haftmann@58101
   177
lemma listsum_update_nat:
haftmann@58101
   178
  "k < size ns \<Longrightarrow> listsum (ns[k := (n::nat)]) = listsum ns + n - ns ! k"
haftmann@58101
   179
apply(induct ns arbitrary:k)
haftmann@58101
   180
 apply (auto split:nat.split)
haftmann@58101
   181
apply(drule elem_le_listsum_nat)
haftmann@58101
   182
apply arith
haftmann@58101
   183
done
haftmann@58101
   184
haftmann@58101
   185
lemma (in monoid_add) listsum_triv:
haftmann@58101
   186
  "(\<Sum>x\<leftarrow>xs. r) = of_nat (length xs) * r"
haftmann@58101
   187
  by (induct xs) (simp_all add: distrib_right)
haftmann@58101
   188
haftmann@58101
   189
lemma (in monoid_add) listsum_0 [simp]:
haftmann@58101
   190
  "(\<Sum>x\<leftarrow>xs. 0) = 0"
haftmann@58101
   191
  by (induct xs) (simp_all add: distrib_right)
haftmann@58101
   192
wenzelm@60758
   193
text\<open>For non-Abelian groups @{text xs} needs to be reversed on one side:\<close>
haftmann@58101
   194
lemma (in ab_group_add) uminus_listsum_map:
haftmann@58101
   195
  "- listsum (map f xs) = listsum (map (uminus \<circ> f) xs)"
haftmann@58101
   196
  by (induct xs) simp_all
haftmann@58101
   197
haftmann@58101
   198
lemma (in comm_monoid_add) listsum_addf:
haftmann@58101
   199
  "(\<Sum>x\<leftarrow>xs. f x + g x) = listsum (map f xs) + listsum (map g xs)"
haftmann@58101
   200
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   201
haftmann@58101
   202
lemma (in ab_group_add) listsum_subtractf:
haftmann@58101
   203
  "(\<Sum>x\<leftarrow>xs. f x - g x) = listsum (map f xs) - listsum (map g xs)"
haftmann@58101
   204
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   205
haftmann@58101
   206
lemma (in semiring_0) listsum_const_mult:
haftmann@58101
   207
  "(\<Sum>x\<leftarrow>xs. c * f x) = c * (\<Sum>x\<leftarrow>xs. f x)"
haftmann@58101
   208
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   209
haftmann@58101
   210
lemma (in semiring_0) listsum_mult_const:
haftmann@58101
   211
  "(\<Sum>x\<leftarrow>xs. f x * c) = (\<Sum>x\<leftarrow>xs. f x) * c"
haftmann@58101
   212
  by (induct xs) (simp_all add: algebra_simps)
haftmann@58101
   213
haftmann@58101
   214
lemma (in ordered_ab_group_add_abs) listsum_abs:
haftmann@58101
   215
  "\<bar>listsum xs\<bar> \<le> listsum (map abs xs)"
haftmann@58101
   216
  by (induct xs) (simp_all add: order_trans [OF abs_triangle_ineq])
haftmann@58101
   217
haftmann@58101
   218
lemma listsum_mono:
haftmann@58101
   219
  fixes f g :: "'a \<Rightarrow> 'b::{monoid_add, ordered_ab_semigroup_add}"
haftmann@58101
   220
  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
   221
  by (induct xs) (simp, simp add: add_mono)
haftmann@58101
   222
haftmann@58101
   223
lemma (in monoid_add) listsum_distinct_conv_setsum_set:
haftmann@58101
   224
  "distinct xs \<Longrightarrow> listsum (map f xs) = setsum f (set xs)"
haftmann@58101
   225
  by (induct xs) simp_all
haftmann@58101
   226
haftmann@58101
   227
lemma (in monoid_add) interv_listsum_conv_setsum_set_nat:
haftmann@58101
   228
  "listsum (map f [m..<n]) = setsum f (set [m..<n])"
haftmann@58101
   229
  by (simp add: listsum_distinct_conv_setsum_set)
haftmann@58101
   230
haftmann@58101
   231
lemma (in monoid_add) interv_listsum_conv_setsum_set_int:
haftmann@58101
   232
  "listsum (map f [k..l]) = setsum f (set [k..l])"
haftmann@58101
   233
  by (simp add: listsum_distinct_conv_setsum_set)
haftmann@58101
   234
wenzelm@60758
   235
text \<open>General equivalence between @{const listsum} and @{const setsum}\<close>
haftmann@58101
   236
lemma (in monoid_add) listsum_setsum_nth:
haftmann@58101
   237
  "listsum xs = (\<Sum> i = 0 ..< length xs. xs ! i)"
haftmann@58101
   238
  using interv_listsum_conv_setsum_set_nat [of "op ! xs" 0 "length xs"] by (simp add: map_nth)
haftmann@58101
   239
nipkow@59728
   240
lemma listsum_map_eq_setsum_count:
nipkow@60541
   241
  "listsum (map f xs) = setsum (\<lambda>x. count_list xs x * f x) (set xs)"
nipkow@59728
   242
proof(induction xs)
nipkow@59728
   243
  case (Cons x xs)
nipkow@59728
   244
  show ?case (is "?l = ?r")
nipkow@59728
   245
  proof cases
nipkow@59728
   246
    assume "x \<in> set xs"
nipkow@60541
   247
    have "?l = f x + (\<Sum>x\<in>set xs. count_list xs x * f x)" by (simp add: Cons.IH)
wenzelm@60758
   248
    also have "set xs = insert x (set xs - {x})" using \<open>x \<in> set xs\<close>by blast
nipkow@60541
   249
    also have "f x + (\<Sum>x\<in>insert x (set xs - {x}). count_list xs x * f x) = ?r"
nipkow@59728
   250
      by (simp add: setsum.insert_remove eq_commute)
nipkow@59728
   251
    finally show ?thesis .
nipkow@59728
   252
  next
nipkow@59728
   253
    assume "x \<notin> set xs"
nipkow@59728
   254
    hence "\<And>xa. xa \<in> set xs \<Longrightarrow> x \<noteq> xa" by blast
wenzelm@60758
   255
    thus ?thesis by (simp add: Cons.IH \<open>x \<notin> set xs\<close>)
nipkow@59728
   256
  qed
nipkow@59728
   257
qed simp
nipkow@59728
   258
nipkow@59728
   259
lemma listsum_map_eq_setsum_count2:
nipkow@59728
   260
assumes "set xs \<subseteq> X" "finite X"
nipkow@60541
   261
shows "listsum (map f xs) = setsum (\<lambda>x. count_list xs x * f x) X"
nipkow@59728
   262
proof-
nipkow@60541
   263
  let ?F = "\<lambda>x. count_list xs x * f x"
nipkow@59728
   264
  have "setsum ?F X = setsum ?F (set xs \<union> (X - set xs))"
nipkow@59728
   265
    using Un_absorb1[OF assms(1)] by(simp)
nipkow@59728
   266
  also have "\<dots> = setsum ?F (set xs)"
nipkow@59728
   267
    using assms(2)
nipkow@59728
   268
    by(simp add: setsum.union_disjoint[OF _ _ Diff_disjoint] del: Un_Diff_cancel)
nipkow@59728
   269
  finally show ?thesis by(simp add:listsum_map_eq_setsum_count)
nipkow@59728
   270
qed
nipkow@59728
   271
haftmann@58101
   272
wenzelm@60758
   273
subsection \<open>Further facts about @{const List.n_lists}\<close>
haftmann@58101
   274
haftmann@58101
   275
lemma length_n_lists: "length (List.n_lists n xs) = length xs ^ n"
haftmann@58101
   276
  by (induct n) (auto simp add: comp_def length_concat listsum_triv)
haftmann@58101
   277
haftmann@58101
   278
lemma distinct_n_lists:
haftmann@58101
   279
  assumes "distinct xs"
haftmann@58101
   280
  shows "distinct (List.n_lists n xs)"
haftmann@58101
   281
proof (rule card_distinct)
haftmann@58101
   282
  from assms have card_length: "card (set xs) = length xs" by (rule distinct_card)
haftmann@58101
   283
  have "card (set (List.n_lists n xs)) = card (set xs) ^ n"
haftmann@58101
   284
  proof (induct n)
haftmann@58101
   285
    case 0 then show ?case by simp
haftmann@58101
   286
  next
haftmann@58101
   287
    case (Suc n)
haftmann@58101
   288
    moreover have "card (\<Union>ys\<in>set (List.n_lists n xs). (\<lambda>y. y # ys) ` set xs)
haftmann@58101
   289
      = (\<Sum>ys\<in>set (List.n_lists n xs). card ((\<lambda>y. y # ys) ` set xs))"
haftmann@58101
   290
      by (rule card_UN_disjoint) auto
haftmann@58101
   291
    moreover have "\<And>ys. card ((\<lambda>y. y # ys) ` set xs) = card (set xs)"
haftmann@58101
   292
      by (rule card_image) (simp add: inj_on_def)
haftmann@58101
   293
    ultimately show ?case by auto
haftmann@58101
   294
  qed
haftmann@58101
   295
  also have "\<dots> = length xs ^ n" by (simp add: card_length)
haftmann@58101
   296
  finally show "card (set (List.n_lists n xs)) = length (List.n_lists n xs)"
haftmann@58101
   297
    by (simp add: length_n_lists)
haftmann@58101
   298
qed
haftmann@58101
   299
haftmann@58101
   300
wenzelm@60758
   301
subsection \<open>Tools setup\<close>
haftmann@58101
   302
haftmann@58320
   303
lemmas setsum_code = setsum.set_conv_list
haftmann@58320
   304
haftmann@58101
   305
lemma setsum_set_upto_conv_listsum_int [code_unfold]:
haftmann@58101
   306
  "setsum f (set [i..j::int]) = listsum (map f [i..j])"
haftmann@58101
   307
  by (simp add: interv_listsum_conv_setsum_set_int)
haftmann@58101
   308
haftmann@58101
   309
lemma setsum_set_upt_conv_listsum_nat [code_unfold]:
haftmann@58101
   310
  "setsum f (set [m..<n]) = listsum (map f [m..<n])"
haftmann@58101
   311
  by (simp add: interv_listsum_conv_setsum_set_nat)
haftmann@58101
   312
haftmann@58101
   313
context
haftmann@58101
   314
begin
haftmann@58101
   315
haftmann@58101
   316
interpretation lifting_syntax .
haftmann@58101
   317
haftmann@58101
   318
lemma listsum_transfer[transfer_rule]:
haftmann@58101
   319
  assumes [transfer_rule]: "A 0 0"
haftmann@58101
   320
  assumes [transfer_rule]: "(A ===> A ===> A) op + op +"
haftmann@58101
   321
  shows "(list_all2 A ===> A) listsum listsum"
haftmann@58320
   322
  unfolding listsum.eq_foldr [abs_def]
haftmann@58101
   323
  by transfer_prover
haftmann@58101
   324
haftmann@58101
   325
end
haftmann@58101
   326
haftmann@58368
   327
wenzelm@60758
   328
subsection \<open>List product\<close>
haftmann@58368
   329
haftmann@58368
   330
context monoid_mult
haftmann@58368
   331
begin
haftmann@58368
   332
haftmann@58368
   333
definition listprod :: "'a list \<Rightarrow> 'a"
haftmann@58368
   334
where
haftmann@58368
   335
  "listprod  = monoid_list.F times 1"
haftmann@58368
   336
haftmann@58368
   337
sublocale listprod!: monoid_list times 1
haftmann@58368
   338
where
haftmann@58368
   339
  "monoid_list.F times 1 = listprod"
haftmann@58368
   340
proof -
haftmann@58368
   341
  show "monoid_list times 1" ..
haftmann@58368
   342
  then interpret listprod!: monoid_list times 1 .
haftmann@58368
   343
  from listprod_def show "monoid_list.F times 1 = listprod" by rule
haftmann@58368
   344
qed
haftmann@58368
   345
haftmann@58320
   346
end
haftmann@58368
   347
haftmann@58368
   348
context comm_monoid_mult
haftmann@58368
   349
begin
haftmann@58368
   350
haftmann@58368
   351
sublocale listprod!: comm_monoid_list times 1
haftmann@58368
   352
where
haftmann@58368
   353
  "monoid_list.F times 1 = listprod"
haftmann@58368
   354
proof -
haftmann@58368
   355
  show "comm_monoid_list times 1" ..
haftmann@58368
   356
  then interpret listprod!: comm_monoid_list times 1 .
haftmann@58368
   357
  from listprod_def show "monoid_list.F times 1 = listprod" by rule
haftmann@58368
   358
qed
haftmann@58368
   359
haftmann@58368
   360
sublocale setprod!: comm_monoid_list_set times 1
haftmann@58368
   361
where
haftmann@58368
   362
  "monoid_list.F times 1 = listprod"
haftmann@58368
   363
  and "comm_monoid_set.F times 1 = setprod"
haftmann@58368
   364
proof -
haftmann@58368
   365
  show "comm_monoid_list_set times 1" ..
haftmann@58368
   366
  then interpret setprod!: comm_monoid_list_set times 1 .
haftmann@58368
   367
  from listprod_def show "monoid_list.F times 1 = listprod" by rule
haftmann@58368
   368
  from setprod_def show "comm_monoid_set.F times 1 = setprod" by rule
haftmann@58368
   369
qed
haftmann@58368
   370
haftmann@58368
   371
end
haftmann@58368
   372
wenzelm@60758
   373
text \<open>Some syntactic sugar:\<close>
haftmann@58368
   374
haftmann@58368
   375
syntax
haftmann@58368
   376
  "_listprod" :: "pttrn => 'a list => 'b => 'b"    ("(3PROD _<-_. _)" [0, 51, 10] 10)
haftmann@58368
   377
syntax (xsymbols)
haftmann@58368
   378
  "_listprod" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10)
haftmann@58368
   379
syntax (HTML output)
haftmann@58368
   380
  "_listprod" :: "pttrn => 'a list => 'b => 'b"    ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10)
haftmann@58368
   381
wenzelm@60758
   382
translations -- \<open>Beware of argument permutation!\<close>
haftmann@58368
   383
  "PROD x<-xs. b" == "CONST listprod (CONST map (%x. b) xs)"
haftmann@58368
   384
  "\<Prod>x\<leftarrow>xs. b" == "CONST listprod (CONST map (%x. b) xs)"
haftmann@58368
   385
haftmann@58368
   386
end