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