equal
deleted
inserted
replaced
754 done |
754 done |
755 |
755 |
756 |
756 |
757 text{* A simplified version for idempotent functions: *} |
757 text{* A simplified version for idempotent functions: *} |
758 |
758 |
759 lemma (in ACIf) fold_insert2: |
759 lemma (in ACIf) fold_insert_idem: |
760 assumes finA: "finite A" |
760 assumes finA: "finite A" |
761 shows "fold f g z (insert a A) = g a \<cdot> fold f g z A" |
761 shows "fold f g z (insert a A) = g a \<cdot> fold f g z A" |
762 proof cases |
762 proof cases |
763 assume "a \<in> A" |
763 assume "a \<in> A" |
764 then obtain B where A: "A = insert a B" and disj: "a \<notin> B" |
764 then obtain B where A: "A = insert a B" and disj: "a \<notin> B" |
778 with finA show ?thesis by simp |
778 with finA show ?thesis by simp |
779 qed |
779 qed |
780 |
780 |
781 lemma (in ACIf) foldI_conv_id: |
781 lemma (in ACIf) foldI_conv_id: |
782 "finite A \<Longrightarrow> fold f g z A = fold f id z (g ` A)" |
782 "finite A \<Longrightarrow> fold f g z A = fold f id z (g ` A)" |
783 by(erule finite_induct)(simp_all add: fold_insert2 del: fold_insert) |
783 by(erule finite_induct)(simp_all add: fold_insert_idem del: fold_insert) |
784 |
784 |
785 subsubsection{*Lemmas about @{text fold}*} |
785 subsubsection{*Lemmas about @{text fold}*} |
786 |
786 |
787 lemma (in ACf) fold_commute: |
787 lemma (in ACf) fold_commute: |
788 "finite A ==> (!!z. f x (fold f g z A) = fold f g (f x z) A)" |
788 "finite A ==> (!!z. f x (fold f g z A) = fold f g (f x z) A)" |
1842 apply (erule conjE) |
1842 apply (erule conjE) |
1843 apply (simp add: fold1_eq_fold) |
1843 apply (simp add: fold1_eq_fold) |
1844 apply (subst fold1_eq_fold, auto) |
1844 apply (subst fold1_eq_fold, auto) |
1845 done |
1845 done |
1846 |
1846 |
1847 lemma (in ACIf) fold1_insert2 [simp]: |
1847 lemma (in ACIf) fold1_insert_idem [simp]: |
1848 "finite A ==> A \<noteq> {} \<Longrightarrow> fold1 f (insert x A) = f x (fold1 f A)" |
1848 "finite A ==> A \<noteq> {} \<Longrightarrow> fold1 f (insert x A) = f x (fold1 f A)" |
1849 apply (induct A rule: finite_induct, force) |
1849 apply (induct A rule: finite_induct, force) |
1850 apply (case_tac "xa=x") |
1850 apply (case_tac "xa=x") |
1851 prefer 2 apply (simp add: insert_commute fold1_eq_fold fold_insert2) |
1851 prefer 2 apply (simp add: insert_commute fold1_eq_fold fold_insert_idem) |
1852 apply (case_tac "F={}") |
1852 apply (case_tac "F={}") |
1853 apply (simp add: idem) |
1853 apply (simp add: idem) |
1854 apply (simp add: fold1_insert assoc [symmetric] idem) |
1854 apply (simp add: fold1_insert assoc [symmetric] idem) |
1855 done |
1855 done |
1856 |
1856 |
1862 |
1862 |
1863 lemma (in ACf) fold1_insert_def: |
1863 lemma (in ACf) fold1_insert_def: |
1864 "\<lbrakk> g \<equiv> fold1 f; finite A; x \<notin> A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g(insert x A) = x \<cdot> (g A)" |
1864 "\<lbrakk> g \<equiv> fold1 f; finite A; x \<notin> A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g(insert x A) = x \<cdot> (g A)" |
1865 by(simp add:fold1_insert) |
1865 by(simp add:fold1_insert) |
1866 |
1866 |
1867 lemma (in ACIf) fold1_insert2_def: |
1867 lemma (in ACIf) fold1_insert_idem_def: |
1868 "\<lbrakk> g \<equiv> fold1 f; finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g(insert x A) = x \<cdot> (g A)" |
1868 "\<lbrakk> g \<equiv> fold1 f; finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g(insert x A) = x \<cdot> (g A)" |
1869 by(simp add:fold1_insert2) |
1869 by(simp add:fold1_insert_idem) |
1870 |
1870 |
1871 subsubsection{* Determinacy for @{term fold1Set} *} |
1871 subsubsection{* Determinacy for @{term fold1Set} *} |
1872 |
1872 |
1873 text{*Not actually used!!*} |
1873 text{*Not actually used!!*} |
1874 |
1874 |
2002 assumes A: "finite A" "A \<noteq> {}" |
2002 assumes A: "finite A" "A \<noteq> {}" |
2003 shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow> |
2003 shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow> |
2004 fold1 f (A Un B) = f (fold1 f A) (fold1 f B)" |
2004 fold1 f (A Un B) = f (fold1 f A) (fold1 f B)" |
2005 using A |
2005 using A |
2006 proof(induct rule:finite_ne_induct) |
2006 proof(induct rule:finite_ne_induct) |
2007 case singleton thus ?case by(simp add:fold1_insert2) |
2007 case singleton thus ?case by(simp add:fold1_insert_idem) |
2008 next |
2008 next |
2009 case insert thus ?case by (simp add:fold1_insert2 assoc) |
2009 case insert thus ?case by (simp add:fold1_insert_idem assoc) |
2010 qed |
2010 qed |
2011 |
2011 |
2012 lemma (in ACf) fold1_in: |
2012 lemma (in ACf) fold1_in: |
2013 assumes A: "finite (A)" "A \<noteq> {}" and elem: "\<And>x y. x\<cdot>y \<in> {x,y}" |
2013 assumes A: "finite (A)" "A \<noteq> {}" and elem: "\<And>x y. x\<cdot>y \<in> {x,y}" |
2014 shows "fold1 f A \<in> A" |
2014 shows "fold1 f A \<in> A" |
2228 have "x \<squnion> \<Sqinter> (insert y A) = x \<squnion> (y \<sqinter> \<Sqinter> A)" |
2228 have "x \<squnion> \<Sqinter> (insert y A) = x \<squnion> (y \<sqinter> \<Sqinter> A)" |
2229 using insert by(simp add:ACf.fold1_insert_def[OF ACf_inf Inf_def]) |
2229 using insert by(simp add:ACf.fold1_insert_def[OF ACf_inf Inf_def]) |
2230 also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> \<Sqinter> A)" by(rule sup_inf_distrib1) |
2230 also have "\<dots> = (x \<squnion> y) \<sqinter> (x \<squnion> \<Sqinter> A)" by(rule sup_inf_distrib1) |
2231 also have "x \<squnion> \<Sqinter> A = \<Sqinter>{x \<squnion> a|a. a \<in> A}" using insert by simp |
2231 also have "x \<squnion> \<Sqinter> A = \<Sqinter>{x \<squnion> a|a. a \<in> A}" using insert by simp |
2232 also have "(x \<squnion> y) \<sqinter> \<dots> = \<Sqinter> (insert (x \<squnion> y) {x \<squnion> a |a. a \<in> A})" |
2232 also have "(x \<squnion> y) \<sqinter> \<dots> = \<Sqinter> (insert (x \<squnion> y) {x \<squnion> a |a. a \<in> A})" |
2233 using insert by(simp add:ACIf.fold1_insert2_def[OF ACIf_inf Inf_def fin]) |
2233 using insert by(simp add:ACIf.fold1_insert_idem_def[OF ACIf_inf Inf_def fin]) |
2234 also have "insert (x\<squnion>y) {x\<squnion>a |a. a \<in> A} = {x\<squnion>a |a. a \<in> insert y A}" |
2234 also have "insert (x\<squnion>y) {x\<squnion>a |a. a \<in> A} = {x\<squnion>a |a. a \<in> insert y A}" |
2235 by blast |
2235 by blast |
2236 finally show ?case . |
2236 finally show ?case . |
2237 qed |
2237 qed |
2238 |
2238 |
2253 by blast |
2253 by blast |
2254 thus ?thesis by(simp add: insert(0) B(0)) |
2254 thus ?thesis by(simp add: insert(0) B(0)) |
2255 qed |
2255 qed |
2256 have ne: "{a \<squnion> b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast |
2256 have ne: "{a \<squnion> b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast |
2257 have "\<Sqinter>(insert x A) \<squnion> \<Sqinter>B = (x \<sqinter> \<Sqinter>A) \<squnion> \<Sqinter>B" |
2257 have "\<Sqinter>(insert x A) \<squnion> \<Sqinter>B = (x \<sqinter> \<Sqinter>A) \<squnion> \<Sqinter>B" |
2258 using insert by(simp add:ACIf.fold1_insert2_def[OF ACIf_inf Inf_def]) |
2258 using insert by(simp add:ACIf.fold1_insert_idem_def[OF ACIf_inf Inf_def]) |
2259 also have "\<dots> = (x \<squnion> \<Sqinter>B) \<sqinter> (\<Sqinter>A \<squnion> \<Sqinter>B)" by(rule sup_inf_distrib2) |
2259 also have "\<dots> = (x \<squnion> \<Sqinter>B) \<sqinter> (\<Sqinter>A \<squnion> \<Sqinter>B)" by(rule sup_inf_distrib2) |
2260 also have "\<dots> = \<Sqinter>{x \<squnion> b|b. b \<in> B} \<sqinter> \<Sqinter>{a \<squnion> b|a b. a \<in> A \<and> b \<in> B}" |
2260 also have "\<dots> = \<Sqinter>{x \<squnion> b|b. b \<in> B} \<sqinter> \<Sqinter>{a \<squnion> b|a b. a \<in> A \<and> b \<in> B}" |
2261 using insert by(simp add:sup_Inf1_distrib[OF B]) |
2261 using insert by(simp add:sup_Inf1_distrib[OF B]) |
2262 also have "\<dots> = \<Sqinter>({x\<squnion>b |b. b \<in> B} \<union> {a\<squnion>b |a b. a \<in> A \<and> b \<in> B})" |
2262 also have "\<dots> = \<Sqinter>({x\<squnion>b |b. b \<in> B} \<union> {a\<squnion>b |a b. a \<in> A \<and> b \<in> B})" |
2263 (is "_ = \<Sqinter>?M") |
2263 (is "_ = \<Sqinter>?M") |
2384 text{* Now we instantiate the recursion equations and declare them |
2384 text{* Now we instantiate the recursion equations and declare them |
2385 simplification rules: *} |
2385 simplification rules: *} |
2386 |
2386 |
2387 declare |
2387 declare |
2388 fold1_singleton_def[OF Min_def, simp] |
2388 fold1_singleton_def[OF Min_def, simp] |
2389 ACIf.fold1_insert2_def[OF ACIf_min Min_def, simp] |
2389 ACIf.fold1_insert_idem_def[OF ACIf_min Min_def, simp] |
2390 fold1_singleton_def[OF Max_def, simp] |
2390 fold1_singleton_def[OF Max_def, simp] |
2391 ACIf.fold1_insert2_def[OF ACIf_max Max_def, simp] |
2391 ACIf.fold1_insert_idem_def[OF ACIf_max Max_def, simp] |
2392 |
2392 |
2393 text{* Now we instantiate some @{text fold1} properties: *} |
2393 text{* Now we instantiate some @{text fold1} properties: *} |
2394 |
2394 |
2395 lemma Min_in [simp]: |
2395 lemma Min_in [simp]: |
2396 shows "finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> Min A \<in> A" |
2396 shows "finite A \<Longrightarrow> A \<noteq> {} \<Longrightarrow> Min A \<in> A" |