diff options
Diffstat (limited to 'spartan')
-rw-r--r-- | spartan/data/Maybe.thy | 70 | ||||
-rw-r--r-- | spartan/data/More_Types.thy | 92 |
2 files changed, 134 insertions, 28 deletions
diff --git a/spartan/data/Maybe.thy b/spartan/data/Maybe.thy index 532879a..dc3ad04 100644 --- a/spartan/data/Maybe.thy +++ b/spartan/data/Maybe.thy @@ -1,43 +1,57 @@ theory Maybe -imports Spartan +imports More_Types begin -axiomatization - Maybe :: \<open>o \<Rightarrow> o\<close> and - none :: \<open>o \<Rightarrow> o\<close> and - some :: \<open>o \<Rightarrow> o \<Rightarrow> o\<close> and - MaybeInd :: \<open>o \<Rightarrow> (o \<Rightarrow> o) \<Rightarrow> o \<Rightarrow> (o \<Rightarrow> o) \<Rightarrow> o \<Rightarrow> o\<close> -where - MaybeF: "A: U i \<Longrightarrow> Maybe A: U i" and +definition "Maybe A \<equiv> A \<or> \<top>" +definition "none A \<equiv> inr A \<top> tt" +definition "some A a \<equiv> inl A \<top> a" +lemma + MaybeF: "A: U i \<Longrightarrow> Maybe A: U i" and Maybe_none: "A: U i \<Longrightarrow> none A: Maybe A" and + Maybe_some: "a: A \<Longrightarrow> some A a: Maybe A" + unfolding Maybe_def none_def some_def by typechk+ - Maybe_some: "a: A \<Longrightarrow> some A a: Maybe A" and - - MaybeE: "\<lbrakk> - m: Maybe A; - c\<^sub>0: C (none A); - \<And>a. a: A \<Longrightarrow> f a: C (some A a); - \<And>m. m: Maybe A \<Longrightarrow> C m: U i - \<rbrakk> \<Longrightarrow> MaybeInd A (\<lambda>m. C m) c\<^sub>0 (\<lambda>a. f a) m: C m" and +Lemma (derive) MaybeInd: + assumes + "A: U i" + "\<And>m. m: Maybe A \<Longrightarrow> C m: U i" + "c\<^sub>0: C (none A)" + "\<And>a. a: A \<Longrightarrow> f a: C (some A a)" + "m: Maybe A" + shows "?MaybeInd A (\<lambda>m. C m) c\<^sub>0 (\<lambda>a. f a) m: C m" + supply assms[unfolded Maybe_def none_def some_def] + apply (elim m) + \<guillemotright> unfolding Maybe_def . + \<guillemotright> by (rule \<open>_ \<Longrightarrow> _: C (inl _ _ _)\<close>) + \<guillemotright> by elim (rule \<open>_: C (inr _ _ _)\<close>) + done - Maybe_comp_none: "\<lbrakk> - c\<^sub>0: C (none A); - \<And>a. a: A \<Longrightarrow> f a: C (some A a); - \<And>m. m: Maybe A \<Longrightarrow> C m: U i - \<rbrakk> \<Longrightarrow> MaybeInd A (\<lambda>m. C m) c\<^sub>0 (\<lambda>a. f a) (none A) \<equiv> c\<^sub>0" and +Lemma Maybe_comp_none: + assumes + "A: U i" + "c\<^sub>0: C (none A)" + "\<And>a. a: A \<Longrightarrow> f a: C (some A a)" + "\<And>m. m: Maybe A \<Longrightarrow> C m: U i" + shows "MaybeInd A (\<lambda>m. C m) c\<^sub>0 (\<lambda>a. f a) (none A) \<equiv> c\<^sub>0" + supply assms[unfolded Maybe_def some_def none_def] + unfolding MaybeInd_def none_def by reduce - Maybe_comp_some: "\<lbrakk> - m: Maybe A; - c\<^sub>0: C (none A); - \<And>a. a: A \<Longrightarrow> f a: C (some A a); - \<And>m. m: Maybe A \<Longrightarrow> C m: U i - \<rbrakk> \<Longrightarrow> MaybeInd A (\<lambda>m. C m) c\<^sub>0 (\<lambda>a. f a) (some A a) \<equiv> f a" +Lemma Maybe_comp_some: + assumes + "A: U i" + "a: A" + "c\<^sub>0: C (none A)" + "\<And>a. a: A \<Longrightarrow> f a: C (some A a)" + "\<And>m. m: Maybe A \<Longrightarrow> C m: U i" + shows "MaybeInd A (\<lambda>m. C m) c\<^sub>0 (\<lambda>a. f a) (some A a) \<equiv> f a" + supply assms[unfolded Maybe_def some_def none_def] + unfolding MaybeInd_def some_def by (reduce add: Maybe_def) lemmas [intros] = MaybeF Maybe_none Maybe_some and - [elims "?m"] = MaybeE and + MaybeE [elims "?m"] = MaybeInd and [comps] = Maybe_comp_none Maybe_comp_some abbreviation "MaybeRec A C \<equiv> MaybeInd A (K C)" diff --git a/spartan/data/More_Types.thy b/spartan/data/More_Types.thy new file mode 100644 index 0000000..f0cee6d --- /dev/null +++ b/spartan/data/More_Types.thy @@ -0,0 +1,92 @@ +theory More_Types +imports Spartan + +begin + + +section \<open>Sum type\<close> + +axiomatization + Sum :: \<open>o \<Rightarrow> o \<Rightarrow> o\<close> and + inl :: \<open>o \<Rightarrow> o \<Rightarrow> o \<Rightarrow> o\<close> and + inr :: \<open>o \<Rightarrow> o \<Rightarrow> o \<Rightarrow> o\<close> and + SumInd :: \<open>o \<Rightarrow> o \<Rightarrow> (o \<Rightarrow> o) \<Rightarrow> (o \<Rightarrow> o) \<Rightarrow> (o \<Rightarrow> o) \<Rightarrow> o \<Rightarrow> o\<close> + +notation Sum (infixl "\<or>" 50) + +axiomatization where + SumF: "\<lbrakk>A: U i; B: U i\<rbrakk> \<Longrightarrow> A \<or> B: U i" and + + Sum_inl: "\<lbrakk>a: A; B: U i\<rbrakk> \<Longrightarrow> inl A B a: A \<or> B" and + + Sum_inr: "\<lbrakk>b: B; A: U i\<rbrakk> \<Longrightarrow> inr A B b: A \<or> B" and + + SumE: "\<lbrakk> + s: A \<or> B; + \<And>s. s: A \<or> B \<Longrightarrow> C s: U i; + \<And>a. a: A \<Longrightarrow> c a: C (inl A B a); + \<And>b. b: B \<Longrightarrow> d b: C (inr A B b) + \<rbrakk> \<Longrightarrow> SumInd A B (\<lambda>s. C s) (\<lambda>a. c a) (\<lambda>b. d b) s: C s" and + + Sum_comp_inl: "\<lbrakk> + a: A; + \<And>s. s: A \<or> B \<Longrightarrow> C s: U i; + \<And>a. a: A \<Longrightarrow> c a: C (inl A B a); + \<And>b. b: B \<Longrightarrow> d b: C (inr A B b) + \<rbrakk> \<Longrightarrow> SumInd A B (\<lambda>s. C s) (\<lambda>a. c a) (\<lambda>b. d b) (inl A B a) \<equiv> c a" and + + Sum_comp_inr: "\<lbrakk> + b: B; + \<And>s. s: A \<or> B \<Longrightarrow> C s: U i; + \<And>a. a: A \<Longrightarrow> c a: C (inl A B a); + \<And>b. b: B \<Longrightarrow> d b: C (inr A B b) + \<rbrakk> \<Longrightarrow> SumInd A B (\<lambda>s. C s) (\<lambda>a. c a) (\<lambda>b. d b) (inr A B b) \<equiv> d b" + +lemmas + [intros] = SumF Sum_inl Sum_inr and + [elims ?s] = SumE and + [comps] = Sum_comp_inl Sum_comp_inr + + +section \<open>Empty and unit types\<close> + +axiomatization + Top :: \<open>o\<close> and + tt :: \<open>o\<close> and + TopInd :: \<open>(o \<Rightarrow> o) \<Rightarrow> o \<Rightarrow> o \<Rightarrow> o\<close> +and + Bot :: \<open>o\<close> and + BotInd :: \<open>(o \<Rightarrow> o) \<Rightarrow> o \<Rightarrow> o\<close> + +notation Top ("\<top>") and Bot ("\<bottom>") + +axiomatization where + TopF: "\<top>: U i" and + + TopI: "tt: \<top>" and + + TopE: "\<lbrakk>a: \<top>; \<And>x. x: \<top> \<Longrightarrow> C x: U i; c: C tt\<rbrakk> \<Longrightarrow> TopInd (\<lambda>x. C x) c a: C a" and + + Top_comp: "\<lbrakk>\<And>x. x: \<top> \<Longrightarrow> C x: U i; c: C tt\<rbrakk> \<Longrightarrow> TopInd (\<lambda>x. C x) c tt \<equiv> c" +and + BotF: "\<bottom>: U i" and + + BotE: "\<lbrakk>x: \<bottom>; \<And>x. x: \<bottom> \<Longrightarrow> C x: U i\<rbrakk> \<Longrightarrow> BotInd (\<lambda>x. C x) x: C x" + +lemmas + [intros] = TopF TopI BotF and + [elims ?a] = TopE and + [elims ?x] = BotE and + [comps] = Top_comp + + +section \<open>Booleans\<close> + +definition "Bool \<equiv> \<top> \<or> \<top>" +definition "true \<equiv> inl \<top> \<top> tt" +definition "false \<equiv> inr \<top> \<top> tt" + +\<comment> \<open>Can define if-then-else etc.\<close> + + +end |