287 unfolding listsum.eq_foldr [abs_def] |
287 unfolding listsum.eq_foldr [abs_def] |
288 by transfer_prover |
288 by transfer_prover |
289 |
289 |
290 end |
290 end |
291 |
291 |
292 end |
292 |
|
293 subsection {* List product *} |
|
294 |
|
295 context monoid_mult |
|
296 begin |
|
297 |
|
298 definition listprod :: "'a list \<Rightarrow> 'a" |
|
299 where |
|
300 "listprod = monoid_list.F times 1" |
|
301 |
|
302 sublocale listprod!: monoid_list times 1 |
|
303 where |
|
304 "monoid_list.F times 1 = listprod" |
|
305 proof - |
|
306 show "monoid_list times 1" .. |
|
307 then interpret listprod!: monoid_list times 1 . |
|
308 from listprod_def show "monoid_list.F times 1 = listprod" by rule |
|
309 qed |
|
310 |
|
311 end |
|
312 |
|
313 context comm_monoid_mult |
|
314 begin |
|
315 |
|
316 sublocale listprod!: comm_monoid_list times 1 |
|
317 where |
|
318 "monoid_list.F times 1 = listprod" |
|
319 proof - |
|
320 show "comm_monoid_list times 1" .. |
|
321 then interpret listprod!: comm_monoid_list times 1 . |
|
322 from listprod_def show "monoid_list.F times 1 = listprod" by rule |
|
323 qed |
|
324 |
|
325 sublocale setprod!: comm_monoid_list_set times 1 |
|
326 where |
|
327 "monoid_list.F times 1 = listprod" |
|
328 and "comm_monoid_set.F times 1 = setprod" |
|
329 proof - |
|
330 show "comm_monoid_list_set times 1" .. |
|
331 then interpret setprod!: comm_monoid_list_set times 1 . |
|
332 from listprod_def show "monoid_list.F times 1 = listprod" by rule |
|
333 from setprod_def show "comm_monoid_set.F times 1 = setprod" by rule |
|
334 qed |
|
335 |
|
336 end |
|
337 |
|
338 text {* Some syntactic sugar: *} |
|
339 |
|
340 syntax |
|
341 "_listprod" :: "pttrn => 'a list => 'b => 'b" ("(3PROD _<-_. _)" [0, 51, 10] 10) |
|
342 syntax (xsymbols) |
|
343 "_listprod" :: "pttrn => 'a list => 'b => 'b" ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10) |
|
344 syntax (HTML output) |
|
345 "_listprod" :: "pttrn => 'a list => 'b => 'b" ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10) |
|
346 |
|
347 translations -- {* Beware of argument permutation! *} |
|
348 "PROD x<-xs. b" == "CONST listprod (CONST map (%x. b) xs)" |
|
349 "\<Prod>x\<leftarrow>xs. b" == "CONST listprod (CONST map (%x. b) xs)" |
|
350 |
|
351 end |