theory ODList imports "HOL-Library.Multiset"
List_local begin (*>*)
text‹
a type of ordered distinct lists, intended to represent sets.
advantage of this representation is that it is isomorphic to the
of finite sets. Conversely it requires the carrier type to be a
order. Note that this representation does not arise from a
on lists: all the unsorted lists are junk.
›
context linorder begin
text‹
Absorbing" msort, a variant of Tobias Nipkow's proofs from 1992.
›
fun
merge :: "'a list ==> 'a list ==> 'a list" where "merge [] ys = ys"
| "merge xs [] = xs"
| "merge (x#xs) (y#ys) = (if x = y then merge xs (y#ys) else if x < y then x # merge xs (y#ys) else y # merge (x#xs) ys)"
(*<*) lemma set_merge[simp]: "set (merge xs ys) = set (xs @ ys)" by (induct xs ys rule: merge.induct) auto
cast from @{typ "'a list"} into @{typ "'a odlist"}. This is
a renaming of @{term "ODList"} -- names are significant to the
generator's abstract type machinery.
›
definition
fromList :: "('a :: linorder) list ==> 'a odlist" where "fromList ≡ ODList"
lemma toSet_eq_iff: "X = Y ⟷ toSet X = toSet Y" by (blast dest: injD[OF toSet_inj])
subsubsection‹head›
definition
hd :: "('a :: linorder) odlist ==> 'a" where
[code]: "hd ≡ List.hd ∘ toList"
lemma hd_toList: "toList xs = y # ys ==> ODList.hd xs = y" unfolding hd_def by simp
subsubsection‹member›
definition
member :: "('a :: linorder) odlist ==> 'a ==> bool" where
[code]: "member xs x ≡ List.member (toList xs) x"
lemma member_toSet[iff]: "member xs x ⟷x ∈ toSet xs" by (simp add: member_def toSet_def)
subsubsection‹Filter›
definition
filter :: "(('a :: linorder) ==> bool) ==> 'a odlist ==> 'a odlist" where "filter P xs ≡ ODList (List.filter P (toList xs))"
lemma toList_filter[simp, code abstract]: "toList (filter P xs) = List.filter P (toList xs)" unfolding filter_def by (simp add: toList_ODList)
lemma toSet_filter[simp]: "toSet (filter P xs) = { x ∈ toSet xs . P x }" unfolding filter_def apply simp apply (simp add: toSet_def) done
subsubsection‹All›
definition
odlist_all :: "('a :: linorder ==> bool) ==> 'a odlist ==> bool" where
[code]: "odlist_all P xs ≡ list_all P (toList xs)"
lemma odlist_all_iff: "odlist_all P xs ⟷ (∀x ∈ toSet xs. P x)" unfolding odlist_all_def toSet_def by (simp only: list_all_iff)
lemma odlist_all_cong [fundef_cong]: "xs = ys ==> (∧x. x ∈ toSet ys ==> f x = g x) ==> odlist_all f xs = odlist_all g ys" by (simp add: odlist_all_iff)
subsubsection‹Difference›
definition
difference :: "('a :: linorder) odlist ==> 'a odlist ==> 'a odlist" where "difference xs ys = ODList (List_local.difference (toList xs) (toList ys))"
definition
big_union :: "('b ==> ('a :: linorder) odlist) ==> 'b list ==> 'a odlist" where
[code]: "big_union f X ≡ foldr (λa A. ODList.union (f a) A) X ODList.empty"
lemma toSet_big_union[simp]: "toSet (big_union f X) = (∪x ∈ set X. toSet (f x))" proof -
{ fix X Y have"toSet (foldr (λx A. ODList.union (f x) A) X Y) = toSet Y ∪ (∪x ∈ set X. toSet (f x))" by (induct X arbitrary: Y) auto } thus ?thesis unfolding big_union_def by simp qed
subsubsection‹Case distinctions›
text‹
construct ODLists out of lists, so talk in terms of those, not a
-step constructor we don't use.
›
lemma distinct_sorted_induct [consumes 2, case_names Nil insert]: assumes"distinct xs" assumes"sorted xs" assumes base: "P []" assumes step: "∧x xs. [ distinct (x # xs); sorted (x # xs); P xs ]==> P (x # xs)" shows"P xs" using‹distinct xs›‹sorted xs›proof (induct xs) case Nil from‹P []›show ?case . next case (Cons x xs) thenhave"distinct (x # xs)"and"sorted (x # xs)"and"P xs"by (simp_all) with step show"P (x # xs)" . qed
lemma odlist_induct [case_names empty insert, cases type: odlist]: assumes empty: "∧dxs. dxs = empty ==> P dxs" assumes insrt: "∧dxs x xs. [ dxs = fromList (x # xs); distinct (x # xs); sorted (x # xs); P (fromList xs) ] ==> P dxs" shows"P dxs" proof (cases dxs) case (odlist_Abs xs) thenhave dxs: "dxs = ODList xs"and distinct: "distinct xs"and sorted: "sorted xs" by (simp_all add: ODList_def) from‹distinct xs›and‹sorted xs›have"P (ODList xs)" proof (induct xs rule: distinct_sorted_induct) case Nil from empty show ?caseby (simp add: empty_def) next case (insert x xs) thus ?case apply - apply (rule insrt) apply (auto simp: fromList_def) done qed with dxs show"P dxs"by simp qed
lemma odlist_cases [case_names empty insert, cases type: odlist]: assumes empty: "dxs = empty ==> P" assumes insert: "∧x xs. [ dxs = fromList (x # xs); distinct (x # xs); sorted (x # xs) ] ==> P" shows P proof (cases dxs) case (odlist_Abs xs) thenhave dxs: "dxs = ODList xs"and distinct: "distinct xs"and sorted: "sorted xs" by (simp_all add: ODList_def) show P proof (cases xs) case Nil with dxs have"dxs = empty"by (simp add: empty_def) with empty show P . next case (Cons y ys) with dxs distinct sorted insert show P by (simp add: fromList_def) qed qed
subsubsection‹Relations›
text‹
, represented as a list of pairs.
›
type_synonym 'a odrelation = "('a × 'a) odlist"
subsubsection‹Image›
text‹
output of @{term "List_local.image"} is not guaranteed to be
or distinct. Also the relation need not be monomorphic.
›
definition
image :: "('a :: linorder × 'b :: linorder) odlist ==> 'a odlist ==> 'b odlist" where "image R xs = ODList (List_local.image (toList R) (toList xs))"
lemma less_eq_list_cons_inv: fixes x :: 'a shows"less_eq_list (x # xs) yys ==>∃y ys. yys = y # ys ∧ (x < y ∨ (x = y ∧ less_eq_list xs ys))" by (cases yys) auto
instance apply intro_classes unfolding less_eq_odlist_def less_odlist_def using less_eq_list_not_le less_eq_list_refl less_eq_list_trans less_eq_list_antisym apply blast using less_eq_list_not_le less_eq_list_refl less_eq_list_trans less_eq_list_antisym apply blast using less_eq_list_not_le less_eq_list_refl less_eq_list_trans less_eq_list_antisym apply blast using less_eq_list_not_le less_eq_list_refl less_eq_list_trans less_eq_list_antisym apply blast apply (rule less_eq_list_linear) done
end
subsubsection‹Finite maps›
text‹
few operations on finite maps.
the AssocList theory, ODLists give us canonical
, so we can order them. Our tabulate has the wrong type
we want to take an odlist, not a list) so we can't use that
of the framework.
definition (in order) mono_on :: "('a ==> 'b::order) ==> 'a set ==> bool"where "mono_on f X ⟷ (∀x∈X. ∀y∈X. x ≤ y ⟶ f x ≤ f y)"
lemma (in order) mono_onI [intro?]: fixes f :: "'a ==> 'b::order" shows"(∧x y. x ∈ X ==> y ∈ X ==> x ≤ y ==> f x ≤ f y) ==> mono_on f X" unfolding mono_on_def by simp
lemma (in order) mono_onD [dest?]: fixes f :: "'a ==> 'b::order" shows"mono_on f X ==> x ∈ X ==> y ∈ X ==> x ≤ y ==> f x ≤ f y" unfolding mono_on_def by simp
lemma (in order) mono_on_subset: fixes f :: "'a ==> 'b::order" shows"mono_on f X ==> Y ⊆ X ==> mono_on f Y" unfolding mono_on_def by auto
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.