91 "_sum_list" :: "pttrn => 'a list => 'b => 'b" ("(3SUM _<-_. _)" [0, 51, 10] 10) |
91 "_sum_list" :: "pttrn => 'a list => 'b => 'b" ("(3SUM _<-_. _)" [0, 51, 10] 10) |
92 syntax |
92 syntax |
93 "_sum_list" :: "pttrn => 'a list => 'b => 'b" ("(3\<Sum>_\<leftarrow>_. _)" [0, 51, 10] 10) |
93 "_sum_list" :: "pttrn => 'a list => 'b => 'b" ("(3\<Sum>_\<leftarrow>_. _)" [0, 51, 10] 10) |
94 translations \<comment> \<open>Beware of argument permutation!\<close> |
94 translations \<comment> \<open>Beware of argument permutation!\<close> |
95 "\<Sum>x\<leftarrow>xs. b" == "CONST sum_list (CONST map (\<lambda>x. b) xs)" |
95 "\<Sum>x\<leftarrow>xs. b" == "CONST sum_list (CONST map (\<lambda>x. b) xs)" |
|
96 |
|
97 context |
|
98 includes lifting_syntax |
|
99 begin |
|
100 |
|
101 lemma sum_list_transfer [transfer_rule]: |
|
102 "(list_all2 A ===> A) sum_list sum_list" |
|
103 if [transfer_rule]: "A 0 0" "(A ===> A ===> A) (+) (+)" |
|
104 unfolding sum_list.eq_foldr [abs_def] |
|
105 by transfer_prover |
|
106 |
|
107 end |
96 |
108 |
97 text \<open>TODO duplicates\<close> |
109 text \<open>TODO duplicates\<close> |
98 lemmas sum_list_simps = sum_list.Nil sum_list.Cons |
110 lemmas sum_list_simps = sum_list.Nil sum_list.Cons |
99 lemmas sum_list_append = sum_list.append |
111 lemmas sum_list_append = sum_list.append |
100 lemmas sum_list_rev = sum_list.rev |
112 lemmas sum_list_rev = sum_list.rev |
365 |
377 |
366 lemma sum_set_upt_conv_sum_list_nat [code_unfold]: |
378 lemma sum_set_upt_conv_sum_list_nat [code_unfold]: |
367 "sum f (set [m..<n]) = sum_list (map f [m..<n])" |
379 "sum f (set [m..<n]) = sum_list (map f [m..<n])" |
368 by (simp add: interv_sum_list_conv_sum_set_nat) |
380 by (simp add: interv_sum_list_conv_sum_set_nat) |
369 |
381 |
370 context |
|
371 includes lifting_syntax |
|
372 begin |
|
373 |
|
374 lemma sum_list_transfer [transfer_rule]: |
|
375 "(list_all2 A ===> A) sum_list sum_list" |
|
376 if [transfer_rule]: "A 0 0" "(A ===> A ===> A) (+) (+)" |
|
377 unfolding sum_list.eq_foldr [abs_def] |
|
378 by transfer_prover |
|
379 |
|
380 end |
|
381 |
|
382 |
382 |
383 subsection \<open>List product\<close> |
383 subsection \<open>List product\<close> |
384 |
384 |
385 context monoid_mult |
385 context monoid_mult |
386 begin |
386 begin |
414 from prod_def show "comm_monoid_set.F times 1 = prod" by (auto intro: sym) |
414 from prod_def show "comm_monoid_set.F times 1 = prod" by (auto intro: sym) |
415 qed |
415 qed |
416 |
416 |
417 end |
417 end |
418 |
418 |
419 lemma prod_list_zero_iff: |
|
420 "prod_list xs = 0 \<longleftrightarrow> (0 :: 'a :: {semiring_no_zero_divisors, semiring_1}) \<in> set xs" |
|
421 by (induction xs) simp_all |
|
422 |
|
423 text \<open>Some syntactic sugar:\<close> |
419 text \<open>Some syntactic sugar:\<close> |
424 |
420 |
425 syntax (ASCII) |
421 syntax (ASCII) |
426 "_prod_list" :: "pttrn => 'a list => 'b => 'b" ("(3PROD _<-_. _)" [0, 51, 10] 10) |
422 "_prod_list" :: "pttrn => 'a list => 'b => 'b" ("(3PROD _<-_. _)" [0, 51, 10] 10) |
427 syntax |
423 syntax |
428 "_prod_list" :: "pttrn => 'a list => 'b => 'b" ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10) |
424 "_prod_list" :: "pttrn => 'a list => 'b => 'b" ("(3\<Prod>_\<leftarrow>_. _)" [0, 51, 10] 10) |
429 translations \<comment> \<open>Beware of argument permutation!\<close> |
425 translations \<comment> \<open>Beware of argument permutation!\<close> |
430 "\<Prod>x\<leftarrow>xs. b" \<rightleftharpoons> "CONST prod_list (CONST map (\<lambda>x. b) xs)" |
426 "\<Prod>x\<leftarrow>xs. b" \<rightleftharpoons> "CONST prod_list (CONST map (\<lambda>x. b) xs)" |
431 |
427 |
432 end |
428 context |
|
429 includes lifting_syntax |
|
430 begin |
|
431 |
|
432 lemma prod_list_transfer [transfer_rule]: |
|
433 "(list_all2 A ===> A) prod_list prod_list" |
|
434 if [transfer_rule]: "A 1 1" "(A ===> A ===> A) (*) (*)" |
|
435 unfolding prod_list.eq_foldr [abs_def] |
|
436 by transfer_prover |
|
437 |
|
438 end |
|
439 |
|
440 lemma prod_list_zero_iff: |
|
441 "prod_list xs = 0 \<longleftrightarrow> (0 :: 'a :: {semiring_no_zero_divisors, semiring_1}) \<in> set xs" |
|
442 by (induction xs) simp_all |
|
443 |
|
444 end |