src/HOL/Groups_List.thy
changeset 58368 fe083c681ed8
parent 58320 351810c45a48
child 58889 5b7a9633cfa8
equal deleted inserted replaced
58367:8af1e68d7e1a 58368:fe083c681ed8
     1 
     1 
     2 (* Author: Tobias Nipkow, TU Muenchen *)
     2 (* Author: Tobias Nipkow, TU Muenchen *)
     3 
     3 
     4 header {* Sum over lists *}
     4 header {* Sum and product over lists *}
     5 
     5 
     6 theory Groups_List
     6 theory Groups_List
     7 imports List
     7 imports List
     8 begin
     8 begin
     9 
     9 
   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