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