From ff5454812f9e2720bd90c3a5437505644f63b487 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Fri, 31 Jul 2020 14:56:24 +0200 Subject: (FEAT) Term elaboration of assumption and goal statements. . spartan/core/goals.ML . spartan/core/elaboration.ML . spartan/core/elaborated_statement.ML (FEAT) More context tacticals and search tacticals. . spartan/core/context_tactical.ML (FEAT) Improved subgoal focus. Moves fully elaborated assumptions into the context (MINOR INCOMPATIBILITY). . spartan/core/focus.ML (FIX) Normalize facts in order to be able to resolve properly. . spartan/core/typechecking.ML (MAIN) New definitions. (MAIN) Renamed theories and theorems. (MAIN) Refactor theories to fit new features. --- spartan/lib/List.thy | 10 +-- spartan/lib/Maybe.thy | 19 +++--- spartan/lib/More_Types.thy | 150 --------------------------------------------- spartan/lib/Prelude.thy | 150 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+), 164 deletions(-) delete mode 100644 spartan/lib/More_Types.thy create mode 100644 spartan/lib/Prelude.thy (limited to 'spartan/lib') diff --git a/spartan/lib/List.thy b/spartan/lib/List.thy index be86b63..34873e4 100644 --- a/spartan/lib/List.thy +++ b/spartan/lib/List.thy @@ -132,9 +132,9 @@ Definition app: assumes "A: U i" "xs: List A" "ys: List A" shows "List A" apply (elim xs) - \ by (fact \ys:_\) - \ prems vars x _ rec - proof - show "x # rec: List A" by typechk qed + \<^item> by (fact \ys:_\) + \<^item> vars x _ rec + proof - show "x # rec: List A" by typechk qed done definition app_i ("app") where [implicit]: "app xs ys \ List.app ? xs ys" @@ -169,8 +169,8 @@ Definition rev: assumes "A: U i" "xs: List A" shows "List A" apply (elim xs) - \ by (rule List_nil) - \ prems vars x _ rec proof - show "app rec [x]: List A" by typechk qed + \<^item> by (rule List_nil) + \<^item> vars x _ rec proof - show "app rec [x]: List A" by typechk qed done definition rev_i ("rev") where [implicit]: "rev \ List.rev ?" diff --git a/spartan/lib/Maybe.thy b/spartan/lib/Maybe.thy index 0ce534c..a2e1638 100644 --- a/spartan/lib/Maybe.thy +++ b/spartan/lib/Maybe.thy @@ -1,7 +1,7 @@ chapter \Maybe type\ theory Maybe -imports More_Types +imports Prelude begin @@ -25,11 +25,10 @@ Definition MaybeInd: "\a. a: A \ f a: C (some A a)" "m: Maybe A" shows "C m" - supply assms[unfolded Maybe_def none_def some_def] + using assms[unfolded Maybe_def none_def some_def] apply (elim m) - \ unfolding Maybe_def . - \ by (rule \_ \ _: C (inl _ _ _)\) - \ by elim (rule \_: C (inr _ _ _)\) + apply (rule \_ \ _: C (inl _ _ _)\) + apply (elim, rule \_: C (inr _ _ _)\) done Lemma Maybe_comp_none: @@ -39,8 +38,9 @@ Lemma Maybe_comp_none: "\a. a: A \ f a: C (some A a)" "\m. m: Maybe A \ C m: U i" shows "MaybeInd A C c\<^sub>0 f (none A) \ c\<^sub>0" - supply assms[unfolded Maybe_def some_def none_def] - unfolding MaybeInd_def none_def by reduce + using assms + unfolding Maybe_def MaybeInd_def none_def some_def + by reduce Lemma Maybe_comp_some: assumes @@ -50,8 +50,9 @@ Lemma Maybe_comp_some: "\a. a: A \ f a: C (some A a)" "\m. m: Maybe A \ C m: U i" shows "MaybeInd A C c\<^sub>0 f (some A a) \ f a" - supply assms[unfolded Maybe_def some_def none_def] - unfolding MaybeInd_def some_def by (reduce add: Maybe_def) + using assms + unfolding Maybe_def MaybeInd_def none_def some_def + by reduce lemmas [form] = MaybeF and diff --git a/spartan/lib/More_Types.thy b/spartan/lib/More_Types.thy deleted file mode 100644 index 55e6554..0000000 --- a/spartan/lib/More_Types.thy +++ /dev/null @@ -1,150 +0,0 @@ -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: "\B: U i; a: A\ \ inl A B a: A \ B" and - - Sum_inr: "\A: U i; b: B\ \ 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 (fn s. C s) (fn a. c a) (fn 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 (fn s. C s) (fn a. c a) (fn 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 (fn s. C s) (fn a. c a) (fn b. d b) (inr A B b) \ d b" - -lemmas - [form] = SumF and - [intro] = Sum_inl Sum_inr and - [intros] = Sum_inl[rotated] Sum_inr[rotated] and - [elim ?s] = SumE and - [comp] = Sum_comp_inl Sum_comp_inr - -method left = rule Sum_inl -method right = rule Sum_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 (fn x. C x) c a: C a" and - - Top_comp: "\\x. x: \ \ C x: U i; c: C tt\ \ TopInd (fn x. C x) c tt \ c" -and - BotF: "\: U i" and - - BotE: "\x: \; \x. x: \ \ C x: U i\ \ BotInd (fn x. C x) x: C x" - -lemmas - [form] = TopF BotF and - [intro, intros] = TopI and - [elim ?a] = TopE and - [elim ?x] = BotE and - [comp] = Top_comp - - -section \Booleans\ - -definition "Bool \ \ \ \" -definition "true \ inl \ \ tt" -definition "false \ inr \ \ tt" - -Lemma - BoolF: "Bool: U i" and - Bool_true: "true: Bool" and - Bool_false: "false: Bool" - unfolding Bool_def true_def false_def by typechk+ - -\ \Definitions like these should be handled by a future function package\ -Definition ifelse [rotated 1]: - assumes *[unfolded Bool_def true_def false_def]: - "\x. x: Bool \ C x: U i" - "x: Bool" - "a: C true" - "b: C false" - shows "C x" - by (elim x) (elim, rule *)+ - -Lemma if_true: - assumes - "\x. x: Bool \ C x: U i" - "a: C true" - "b: C false" - shows "ifelse C true a b \ a" - unfolding ifelse_def true_def - supply assms[unfolded Bool_def true_def false_def] - by reduce - -Lemma if_false: - assumes - "\x. x: Bool \ C x: U i" - "a: C true" - "b: C false" - shows "ifelse C false a b \ b" - unfolding ifelse_def false_def - supply assms[unfolded Bool_def true_def false_def] - by reduce - -lemmas - [form] = BoolF and - [intro, intros] = Bool_true Bool_false and - [comp] = if_true if_false and - [elim ?x] = ifelse -lemmas - BoolE = ifelse - -subsection \Notation\ - -definition ifelse_i ("if _ then _ else _") - where [implicit]: "if x then a else b \ ifelse ? x a b" - -translations "if x then a else b" \ "CONST ifelse C x a b" - -subsection \Logical connectives\ - -definition not ("!_") where "not x \ ifelse (K Bool) x false true" - - -end diff --git a/spartan/lib/Prelude.thy b/spartan/lib/Prelude.thy new file mode 100644 index 0000000..36f12d2 --- /dev/null +++ b/spartan/lib/Prelude.thy @@ -0,0 +1,150 @@ +theory Prelude +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: "\B: U i; a: A\ \ inl A B a: A \ B" and + + Sum_inr: "\A: U i; b: B\ \ 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 (fn s. C s) (fn a. c a) (fn 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 (fn s. C s) (fn a. c a) (fn 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 (fn s. C s) (fn a. c a) (fn b. d b) (inr A B b) \ d b" + +lemmas + [form] = SumF and + [intro] = Sum_inl Sum_inr and + [intros] = Sum_inl[rotated] Sum_inr[rotated] and + [elim ?s] = SumE and + [comp] = Sum_comp_inl Sum_comp_inr + +method left = rule Sum_inl +method right = rule Sum_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 (fn x. C x) c a: C a" and + + Top_comp: "\\x. x: \ \ C x: U i; c: C tt\ \ TopInd (fn x. C x) c tt \ c" +and + BotF: "\: U i" and + + BotE: "\x: \; \x. x: \ \ C x: U i\ \ BotInd (fn x. C x) x: C x" + +lemmas + [form] = TopF BotF and + [intro, intros] = TopI and + [elim ?a] = TopE and + [elim ?x] = BotE and + [comp] = Top_comp + + +section \Booleans\ + +definition "Bool \ \ \ \" +definition "true \ inl \ \ tt" +definition "false \ inr \ \ tt" + +Lemma + BoolF: "Bool: U i" and + Bool_true: "true: Bool" and + Bool_false: "false: Bool" + unfolding Bool_def true_def false_def by typechk+ + +\ \Definitions like these should be handled by a future function package\ +Definition ifelse [rotated 1]: + assumes *[unfolded Bool_def true_def false_def]: + "\x. x: Bool \ C x: U i" + "x: Bool" + "a: C true" + "b: C false" + shows "C x" + by (elim x) (elim, rule *)+ + +Lemma if_true: + assumes + "\x. x: Bool \ C x: U i" + "a: C true" + "b: C false" + shows "ifelse C true a b \ a" + unfolding ifelse_def true_def + using assms unfolding Bool_def true_def false_def + by reduce + +Lemma if_false: + assumes + "\x. x: Bool \ C x: U i" + "a: C true" + "b: C false" + shows "ifelse C false a b \ b" + unfolding ifelse_def false_def + using assms unfolding Bool_def true_def false_def + by reduce + +lemmas + [form] = BoolF and + [intro, intros] = Bool_true Bool_false and + [comp] = if_true if_false and + [elim ?x] = ifelse +lemmas + BoolE = ifelse + +subsection \Notation\ + +definition ifelse_i ("if _ then _ else _") + where [implicit]: "if x then a else b \ ifelse ? x a b" + +translations "if x then a else b" \ "CONST ifelse C x a b" + +subsection \Logical connectives\ + +definition not ("!_") where "not x \ ifelse (K Bool) x false true" + + +end -- cgit v1.2.3