670 end |
670 end |
671 |
671 |
672 text{* A simplified version for idempotent functions: *} |
672 text{* A simplified version for idempotent functions: *} |
673 |
673 |
674 locale fun_left_comm_idem = fun_left_comm + |
674 locale fun_left_comm_idem = fun_left_comm + |
675 assumes fun_left_idem: "f x (f x z) = f x z" |
675 assumes fun_comp_idem: "f x o f x = f x" |
676 begin |
676 begin |
677 |
677 |
678 text{* The nice version: *} |
678 lemma fun_left_idem: "f x (f x z) = f x z" |
679 lemma fun_comp_idem : "f x o f x = f x" |
679 using fun_comp_idem by (simp add: fun_eq_iff) |
680 by (simp add: fun_left_idem fun_eq_iff) |
|
681 |
680 |
682 lemma fold_insert_idem: |
681 lemma fold_insert_idem: |
683 assumes fin: "finite A" |
682 assumes fin: "finite A" |
684 shows "fold f z (insert x A) = f x (fold f z A)" |
683 shows "fold f z (insert x A) = f x (fold f z A)" |
685 proof cases |
684 proof cases |
699 end |
698 end |
700 |
699 |
701 |
700 |
702 subsubsection {* Expressing set operations via @{const fold} *} |
701 subsubsection {* Expressing set operations via @{const fold} *} |
703 |
702 |
704 lemma (in fun_left_comm) fun_left_comm_apply: |
703 lemma (in fun_left_comm) comp_comp_fun_commute: |
705 "fun_left_comm (\<lambda>x. f (g x))" |
704 "fun_left_comm (f \<circ> g)" |
706 proof |
705 proof |
707 qed (simp_all add: commute_comp) |
706 qed (simp_all add: commute_comp) |
708 |
707 |
709 lemma (in fun_left_comm_idem) fun_left_comm_idem_apply: |
708 lemma (in fun_left_comm_idem) comp_comp_fun_idem: |
710 "fun_left_comm_idem (\<lambda>x. f (g x))" |
709 "fun_left_comm_idem (f \<circ> g)" |
711 by (rule fun_left_comm_idem.intro, rule fun_left_comm_apply, unfold_locales) |
710 by (rule fun_left_comm_idem.intro, rule comp_comp_fun_commute, unfold_locales) |
712 (simp_all add: fun_left_idem) |
711 (simp_all add: fun_comp_idem) |
713 |
712 |
714 lemma fun_left_comm_idem_insert: |
713 lemma fun_left_comm_idem_insert: |
715 "fun_left_comm_idem insert" |
714 "fun_left_comm_idem insert" |
716 proof |
715 proof |
717 qed auto |
716 qed auto |
781 lemma inf_INFI_fold_inf: |
780 lemma inf_INFI_fold_inf: |
782 assumes "finite A" |
781 assumes "finite A" |
783 shows "inf B (INFI A f) = fold (\<lambda>A. inf (f A)) B A" (is "?inf = ?fold") |
782 shows "inf B (INFI A f) = fold (\<lambda>A. inf (f A)) B A" (is "?inf = ?fold") |
784 proof (rule sym) |
783 proof (rule sym) |
785 interpret fun_left_comm_idem inf by (fact fun_left_comm_idem_inf) |
784 interpret fun_left_comm_idem inf by (fact fun_left_comm_idem_inf) |
786 interpret fun_left_comm_idem "\<lambda>A. inf (f A)" by (fact fun_left_comm_idem_apply) |
785 interpret fun_left_comm_idem "inf \<circ> f" by (fact comp_comp_fun_idem) |
787 from `finite A` show "?fold = ?inf" |
786 from `finite A` have "fold (inf \<circ> f) B A = ?inf" |
788 by (induct A arbitrary: B) |
787 by (induct A arbitrary: B) |
789 (simp_all add: INFI_def Inf_insert inf_left_commute) |
788 (simp_all add: INFI_def Inf_insert inf_left_commute) |
|
789 then show "?fold = ?inf" by (simp add: comp_def) |
790 qed |
790 qed |
791 |
791 |
792 lemma sup_SUPR_fold_sup: |
792 lemma sup_SUPR_fold_sup: |
793 assumes "finite A" |
793 assumes "finite A" |
794 shows "sup B (SUPR A f) = fold (\<lambda>A. sup (f A)) B A" (is "?sup = ?fold") |
794 shows "sup B (SUPR A f) = fold (\<lambda>A. sup (f A)) B A" (is "?sup = ?fold") |
795 proof (rule sym) |
795 proof (rule sym) |
796 interpret fun_left_comm_idem sup by (fact fun_left_comm_idem_sup) |
796 interpret fun_left_comm_idem sup by (fact fun_left_comm_idem_sup) |
797 interpret fun_left_comm_idem "\<lambda>A. sup (f A)" by (fact fun_left_comm_idem_apply) |
797 interpret fun_left_comm_idem "sup \<circ> f" by (fact comp_comp_fun_idem) |
798 from `finite A` show "?fold = ?sup" |
798 from `finite A` have "fold (sup \<circ> f) B A = ?sup" |
799 by (induct A arbitrary: B) |
799 by (induct A arbitrary: B) |
800 (simp_all add: SUPR_def Sup_insert sup_left_commute) |
800 (simp_all add: SUPR_def Sup_insert sup_left_commute) |
|
801 then show "?fold = ?sup" by (simp add: comp_def) |
801 qed |
802 qed |
802 |
803 |
803 lemma INFI_fold_inf: |
804 lemma INFI_fold_inf: |
804 assumes "finite A" |
805 assumes "finite A" |
805 shows "INFI A f = fold (\<lambda>A. inf (f A)) top A" |
806 shows "INFI A f = fold (\<lambda>A. inf (f A)) top A" |
1136 |
1137 |
1137 context ab_semigroup_idem_mult |
1138 context ab_semigroup_idem_mult |
1138 begin |
1139 begin |
1139 |
1140 |
1140 lemma fun_left_comm_idem: "fun_left_comm_idem (op *)" proof |
1141 lemma fun_left_comm_idem: "fun_left_comm_idem (op *)" proof |
1141 qed (simp add: fun_eq_iff mult_left_commute, rule mult_left_idem) |
1142 qed (simp_all add: fun_eq_iff mult_left_commute) |
1142 |
1143 |
1143 lemma fold1_insert_idem [simp]: |
1144 lemma fold1_insert_idem [simp]: |
1144 assumes nonempty: "A \<noteq> {}" and A: "finite A" |
1145 assumes nonempty: "A \<noteq> {}" and A: "finite A" |
1145 shows "fold1 times (insert x A) = x * fold1 times A" |
1146 shows "fold1 times (insert x A) = x * fold1 times A" |
1146 proof - |
1147 proof - |