784 |
784 |
785 subsection{* A rather complex proof about iterates -- cf.\ Andy Pitts *} |
785 subsection{* A rather complex proof about iterates -- cf.\ Andy Pitts *} |
786 |
786 |
787 lemma funpow_lmap: |
787 lemma funpow_lmap: |
788 fixes f :: "'a \<Rightarrow> 'a" |
788 fixes f :: "'a \<Rightarrow> 'a" |
789 shows "(lmap f ^ n) (LCons b l) = LCons ((f ^ n) b) ((lmap f ^ n) l)" |
789 shows "(lmap f o^ n) (LCons b l) = LCons ((f o^ n) b) ((lmap f o^ n) l)" |
790 by (induct n) simp_all |
790 by (induct n) simp_all |
791 |
791 |
792 |
792 |
793 lemma iterates_equality: |
793 lemma iterates_equality: |
794 assumes h: "\<And>x. h x = LCons x (lmap f (h x))" |
794 assumes h: "\<And>x. h x = LCons x (lmap f (h x))" |
795 shows "h = iterates f" |
795 shows "h = iterates f" |
796 proof |
796 proof |
797 fix x |
797 fix x |
798 have "(h x, iterates f x) \<in> |
798 have "(h x, iterates f x) \<in> |
799 {((lmap f ^ n) (h u), (lmap f ^ n) (iterates f u)) | u n. True}" |
799 {((lmap f o^ n) (h u), (lmap f o^ n) (iterates f u)) | u n. True}" |
800 proof - |
800 proof - |
801 have "(h x, iterates f x) = ((lmap f ^ 0) (h x), (lmap f ^ 0) (iterates f x))" |
801 have "(h x, iterates f x) = ((lmap f o^ 0) (h x), (lmap f o^ 0) (iterates f x))" |
802 by simp |
802 by simp |
803 then show ?thesis by blast |
803 then show ?thesis by blast |
804 qed |
804 qed |
805 then show "h x = iterates f x" |
805 then show "h x = iterates f x" |
806 proof (coinduct rule: llist_equalityI) |
806 proof (coinduct rule: llist_equalityI) |
807 case (Eqllist q) |
807 case (Eqllist q) |
808 then obtain u n where "q = ((lmap f ^ n) (h u), (lmap f ^ n) (iterates f u))" |
808 then obtain u n where "q = ((lmap f o^ n) (h u), (lmap f o^ n) (iterates f u))" |
809 (is "_ = (?q1, ?q2)") |
809 (is "_ = (?q1, ?q2)") |
810 by auto |
810 by auto |
811 also have "?q1 = LCons ((f ^ n) u) ((lmap f ^ Suc n) (h u))" |
811 also have "?q1 = LCons ((f o^ n) u) ((lmap f o^ Suc n) (h u))" |
812 proof - |
812 proof - |
813 have "?q1 = (lmap f ^ n) (LCons u (lmap f (h u)))" |
813 have "?q1 = (lmap f o^ n) (LCons u (lmap f (h u)))" |
814 by (subst h) rule |
814 by (subst h) rule |
815 also have "\<dots> = LCons ((f ^ n) u) ((lmap f ^ n) (lmap f (h u)))" |
815 also have "\<dots> = LCons ((f o^ n) u) ((lmap f o^ n) (lmap f (h u)))" |
816 by (rule funpow_lmap) |
816 by (rule funpow_lmap) |
817 also have "(lmap f ^ n) (lmap f (h u)) = (lmap f ^ Suc n) (h u)" |
817 also have "(lmap f o^ n) (lmap f (h u)) = (lmap f o^ Suc n) (h u)" |
818 by (simp add: funpow_swap1) |
818 by (simp add: funpow_swap1) |
819 finally show ?thesis . |
819 finally show ?thesis . |
820 qed |
820 qed |
821 also have "?q2 = LCons ((f ^ n) u) ((lmap f ^ Suc n) (iterates f u))" |
821 also have "?q2 = LCons ((f o^ n) u) ((lmap f o^ Suc n) (iterates f u))" |
822 proof - |
822 proof - |
823 have "?q2 = (lmap f ^ n) (LCons u (iterates f (f u)))" |
823 have "?q2 = (lmap f o^ n) (LCons u (iterates f (f u)))" |
824 by (subst iterates) rule |
824 by (subst iterates) rule |
825 also have "\<dots> = LCons ((f ^ n) u) ((lmap f ^ n) (iterates f (f u)))" |
825 also have "\<dots> = LCons ((f o^ n) u) ((lmap f o^ n) (iterates f (f u)))" |
826 by (rule funpow_lmap) |
826 by (rule funpow_lmap) |
827 also have "(lmap f ^ n) (iterates f (f u)) = (lmap f ^ Suc n) (iterates f u)" |
827 also have "(lmap f o^ n) (iterates f (f u)) = (lmap f o^ Suc n) (iterates f u)" |
828 by (simp add: lmap_iterates funpow_swap1) |
828 by (simp add: lmap_iterates funpow_swap1) |
829 finally show ?thesis . |
829 finally show ?thesis . |
830 qed |
830 qed |
831 finally have ?EqLCons by (auto simp del: funpow.simps) |
831 finally have ?EqLCons by (auto simp del: funpow.simps) |
832 then show ?case .. |
832 then show ?case .. |