equal
deleted
inserted
replaced
11 |
11 |
12 subsection {* List constructors over the datatype universe *} |
12 subsection {* List constructors over the datatype universe *} |
13 |
13 |
14 definition |
14 definition |
15 "NIL = Datatype.In0 (Datatype.Numb 0)" |
15 "NIL = Datatype.In0 (Datatype.Numb 0)" |
|
16 definition |
16 "CONS M N = Datatype.In1 (Datatype.Scons M N)" |
17 "CONS M N = Datatype.In1 (Datatype.Scons M N)" |
17 |
18 |
18 lemma CONS_not_NIL [iff]: "CONS M N \<noteq> NIL" |
19 lemma CONS_not_NIL [iff]: "CONS M N \<noteq> NIL" |
19 and NIL_not_CONS [iff]: "NIL \<noteq> CONS M N" |
20 and NIL_not_CONS [iff]: "NIL \<noteq> CONS M N" |
20 and CONS_inject [iff]: "(CONS K M) = (CONS L N) = (K = L \<and> M = N)" |
21 and CONS_inject [iff]: "(CONS K M) = (CONS L N) = (K = L \<and> M = N)" |
144 finally show ?thesis . |
145 finally show ?thesis . |
145 qed |
146 qed |
146 |
147 |
147 definition |
148 definition |
148 "LNil = Abs_llist NIL" |
149 "LNil = Abs_llist NIL" |
|
150 definition |
149 "LCons x xs = Abs_llist (CONS (Datatype.Leaf x) (Rep_llist xs))" |
151 "LCons x xs = Abs_llist (CONS (Datatype.Leaf x) (Rep_llist xs))" |
150 |
152 |
151 lemma LCons_not_LNil [iff]: "LCons x xs \<noteq> LNil" |
153 lemma LCons_not_LNil [iff]: "LCons x xs \<noteq> LNil" |
152 apply (simp add: LNil_def LCons_def) |
154 apply (simp add: LNil_def LCons_def) |
153 apply (subst Abs_llist_inject) |
155 apply (subst Abs_llist_inject) |
571 |
573 |
572 subsubsection {* @{text Lmap} and @{text lmap} *} |
574 subsubsection {* @{text Lmap} and @{text lmap} *} |
573 |
575 |
574 definition |
576 definition |
575 "Lmap f M = LList_corec M (List_case None (\<lambda>x M'. Some (f x, M')))" |
577 "Lmap f M = LList_corec M (List_case None (\<lambda>x M'. Some (f x, M')))" |
|
578 definition |
576 "lmap f l = llist_corec l |
579 "lmap f l = llist_corec l |
577 (\<lambda>z. |
580 (\<lambda>z. |
578 case z of LNil \<Rightarrow> None |
581 case z of LNil \<Rightarrow> None |
579 | LCons y z \<Rightarrow> Some (f y, z))" |
582 | LCons y z \<Rightarrow> Some (f y, z))" |
580 |
583 |
669 definition |
672 definition |
670 "Lappend M N = LList_corec (M, N) |
673 "Lappend M N = LList_corec (M, N) |
671 (split (List_case |
674 (split (List_case |
672 (List_case None (\<lambda>N1 N2. Some (N1, (NIL, N2)))) |
675 (List_case None (\<lambda>N1 N2. Some (N1, (NIL, N2)))) |
673 (\<lambda>M1 M2 N. Some (M1, (M2, N)))))" |
676 (\<lambda>M1 M2 N. Some (M1, (M2, N)))))" |
|
677 definition |
674 "lappend l n = llist_corec (l, n) |
678 "lappend l n = llist_corec (l, n) |
675 (split (llist_case |
679 (split (llist_case |
676 (llist_case None (\<lambda>n1 n2. Some (n1, (LNil, n2)))) |
680 (llist_case None (\<lambda>n1 n2. Some (n1, (LNil, n2)))) |
677 (\<lambda>l1 l2 n. Some (l1, (l2, n)))))" |
681 (\<lambda>l1 l2 n. Some (l1, (l2, n)))))" |
678 |
682 |
744 subsection{* iterates *} |
748 subsection{* iterates *} |
745 |
749 |
746 text {* @{text llist_fun_equalityI} cannot be used here! *} |
750 text {* @{text llist_fun_equalityI} cannot be used here! *} |
747 |
751 |
748 definition |
752 definition |
749 iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a llist" |
753 iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a llist" where |
750 "iterates f a = llist_corec a (\<lambda>x. Some (x, f x))" |
754 "iterates f a = llist_corec a (\<lambda>x. Some (x, f x))" |
751 |
755 |
752 lemma iterates: "iterates f x = LCons x (iterates f (f x))" |
756 lemma iterates: "iterates f x = LCons x (iterates f (f x))" |
753 apply (unfold iterates_def) |
757 apply (unfold iterates_def) |
754 apply (subst llist_corec) |
758 apply (subst llist_corec) |