From 62c1c8f306bff84b74b3b1c935d0d6722e1251a2 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Wed, 27 May 2020 21:31:35 +0200 Subject: 1. Define Maybe in terms of other types. 2. Move More_Types to Spartan --- spartan/data/Maybe.thy | 70 ++++++++++++++++++++-------------- spartan/data/More_Types.thy | 92 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 28 deletions(-) create mode 100644 spartan/data/More_Types.thy (limited to 'spartan') 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 :: \o \ o\ and - none :: \o \ o\ and - some :: \o \ o \ o\ and - MaybeInd :: \o \ (o \ o) \ o \ (o \ o) \ o \ o\ -where - MaybeF: "A: U i \ Maybe A: U i" and +definition "Maybe A \ A \ \" +definition "none A \ inr A \ tt" +definition "some A a \ inl A \ a" +lemma + MaybeF: "A: U i \ Maybe A: U i" and Maybe_none: "A: U i \ none A: Maybe A" and + Maybe_some: "a: A \ some A a: Maybe A" + unfolding Maybe_def none_def some_def by typechk+ - Maybe_some: "a: A \ some A a: Maybe A" and - - MaybeE: "\ - m: Maybe A; - c\<^sub>0: C (none A); - \a. a: A \ f a: C (some A a); - \m. m: Maybe A \ C m: U i - \ \ MaybeInd A (\m. C m) c\<^sub>0 (\a. f a) m: C m" and +Lemma (derive) MaybeInd: + assumes + "A: U i" + "\m. m: Maybe A \ C m: U i" + "c\<^sub>0: C (none A)" + "\a. a: A \ f a: C (some A a)" + "m: Maybe A" + shows "?MaybeInd A (\m. C m) c\<^sub>0 (\a. f a) m: C m" + supply assms[unfolded Maybe_def none_def some_def] + apply (elim m) + \ unfolding Maybe_def . + \ by (rule \_ \ _: C (inl _ _ _)\) + \ by elim (rule \_: C (inr _ _ _)\) + done - Maybe_comp_none: "\ - c\<^sub>0: C (none A); - \a. a: A \ f a: C (some A a); - \m. m: Maybe A \ C m: U i - \ \ MaybeInd A (\m. C m) c\<^sub>0 (\a. f a) (none A) \ c\<^sub>0" and +Lemma Maybe_comp_none: + assumes + "A: U i" + "c\<^sub>0: C (none A)" + "\a. a: A \ f a: C (some A a)" + "\m. m: Maybe A \ C m: U i" + shows "MaybeInd A (\m. C m) c\<^sub>0 (\a. f a) (none A) \ c\<^sub>0" + supply assms[unfolded Maybe_def some_def none_def] + unfolding MaybeInd_def none_def by reduce - Maybe_comp_some: "\ - m: Maybe A; - c\<^sub>0: C (none A); - \a. a: A \ f a: C (some A a); - \m. m: Maybe A \ C m: U i - \ \ MaybeInd A (\m. C m) c\<^sub>0 (\a. f a) (some A a) \ f a" +Lemma Maybe_comp_some: + assumes + "A: U i" + "a: A" + "c\<^sub>0: C (none A)" + "\a. a: A \ f a: C (some A a)" + "\m. m: Maybe A \ C m: U i" + shows "MaybeInd A (\m. C m) c\<^sub>0 (\a. f a) (some A a) \ 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 \ 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 \Sum type\ + +axiomatization + Sum :: \o \ o \ o\ and + inl :: \o \ o \ o \ o\ and + inr :: \o \ o \ o \ o\ and + SumInd :: \o \ o \ (o \ o) \ (o \ o) \ (o \ o) \ o \ o\ + +notation Sum (infixl "\" 50) + +axiomatization where + SumF: "\A: U i; B: U i\ \ A \ B: U i" and + + Sum_inl: "\a: A; B: U i\ \ inl A B a: A \ B" and + + Sum_inr: "\b: B; A: U i\ \ inr A B b: A \ B" and + + SumE: "\ + s: A \ B; + \s. s: A \ B \ C s: U i; + \a. a: A \ c a: C (inl A B a); + \b. b: B \ d b: C (inr A B b) + \ \ SumInd A B (\s. C s) (\a. c a) (\b. d b) s: C s" and + + Sum_comp_inl: "\ + a: A; + \s. s: A \ B \ C s: U i; + \a. a: A \ c a: C (inl A B a); + \b. b: B \ d b: C (inr A B b) + \ \ SumInd A B (\s. C s) (\a. c a) (\b. d b) (inl A B a) \ c a" and + + Sum_comp_inr: "\ + b: B; + \s. s: A \ B \ C s: U i; + \a. a: A \ c a: C (inl A B a); + \b. b: B \ d b: C (inr A B b) + \ \ SumInd A B (\s. C s) (\a. c a) (\b. d b) (inr A B b) \ d b" + +lemmas + [intros] = SumF Sum_inl Sum_inr and + [elims ?s] = SumE and + [comps] = Sum_comp_inl Sum_comp_inr + + +section \Empty and unit types\ + +axiomatization + Top :: \o\ and + tt :: \o\ and + TopInd :: \(o \ o) \ o \ o \ o\ +and + Bot :: \o\ and + BotInd :: \(o \ o) \ o \ o\ + +notation Top ("\") and Bot ("\") + +axiomatization where + TopF: "\: U i" and + + TopI: "tt: \" and + + TopE: "\a: \; \x. x: \ \ C x: U i; c: C tt\ \ TopInd (\x. C x) c a: C a" and + + Top_comp: "\\x. x: \ \ C x: U i; c: C tt\ \ TopInd (\x. C x) c tt \ c" +and + BotF: "\: U i" and + + BotE: "\x: \; \x. x: \ \ C x: U i\ \ BotInd (\x. C x) x: C x" + +lemmas + [intros] = TopF TopI BotF and + [elims ?a] = TopE and + [elims ?x] = BotE and + [comps] = Top_comp + + +section \Booleans\ + +definition "Bool \ \ \ \" +definition "true \ inl \ \ tt" +definition "false \ inr \ \ tt" + +\ \Can define if-then-else etc.\ + + +end -- cgit v1.2.3