added Option_ord.thy
authorhaftmann
Fri, 07 Mar 2008 16:46:57 +0100
changeset 26241 b7d8c2338585
parent 26240 cc630a75b62a
child 26242 d64510d3c7b7
added Option_ord.thy
src/HOL/Library/Option_ord.thy
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/HOL/Library/Option_ord.thy	Fri Mar 07 16:46:57 2008 +0100
@@ -0,0 +1,59 @@
+(*  Title:      HOL/Library/Option_ord.thy
+    ID:         $Id$
+    Author:     Florian Haftmann, TU Muenchen
+*)
+
+header {* Canonical order on option type *}
+
+theory Option_ord
+imports ATP_Linkup
+begin
+
+instantiation option :: (order) order
+begin
+
+definition less_eq_option where
+  [code func del]: "x \<le> y \<longleftrightarrow> (case x of None \<Rightarrow> True | Some x \<Rightarrow> (case y of None \<Rightarrow> False | Some y \<Rightarrow> x \<le> y))"
+
+definition less_option where
+  [code func del]: "x < y \<longleftrightarrow> (case y of None \<Rightarrow> False | Some y \<Rightarrow> (case x of None \<Rightarrow> True | Some x \<Rightarrow> x < y))"
+
+lemma less_eq_option_None [simp]: "None \<le> (x\<Colon>'a option)"
+  by (simp add: less_eq_option_def)
+
+lemma less_eq_option_None_code [code]: "None \<le> (x\<Colon>'a option) \<longleftrightarrow> True"
+  by simp
+
+lemma less_eq_option_None_is_None: "(x\<Colon>'a option) \<le> None \<Longrightarrow> x = None"
+  by (cases x) (simp_all add: less_eq_option_def)
+
+lemma less_eq_option_Some_None [simp, code]: "Some (x\<Colon>'a) \<le> None \<longleftrightarrow> False"
+  by (simp add: less_eq_option_def)
+
+lemma less_eq_option_Some [simp, code]: "Some (x\<Colon>'a) \<le> Some y \<longleftrightarrow> x \<le> y"
+  by (simp add: less_eq_option_def)
+
+lemma less_option_None [simp, code]: "(x\<Colon>'a option) < None \<longleftrightarrow> False"
+  by (simp add: less_option_def)
+
+lemma less_option_None_is_Some: "None < (x\<Colon>'a option) \<Longrightarrow> \<exists>z. x = Some z"
+  by (cases x) (simp_all add: less_option_def)
+
+lemma less_option_None_Some [simp]: "None < Some (x\<Colon>'a)"
+  by (simp add: less_option_def)
+
+lemma less_option_None_Some_code [code]: "None < Some (x\<Colon>'a) \<longleftrightarrow> True"
+  by simp
+
+lemma less_option_Some [simp, code]: "Some (x\<Colon>'a) < Some y \<longleftrightarrow> x < y"
+  by (simp add: less_option_def)
+
+instance by default
+  (auto simp add: less_eq_option_def less_option_def split: option.splits)
+
+end 
+
+instance option :: (linorder) linorder
+  by default (auto simp add: less_eq_option_def less_option_def split: option.splits)
+
+end