From 2feb56660700af107abb5a28a7120052ac405518 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Sun, 31 Jan 2021 02:54:51 +0000 Subject: rename things + some small changes --- spartan/lib/List.thy | 191 ------------------------------------------------ spartan/lib/Maybe.thy | 75 ------------------- spartan/lib/Prelude.thy | 151 -------------------------------------- 3 files changed, 417 deletions(-) delete mode 100644 spartan/lib/List.thy delete mode 100644 spartan/lib/Maybe.thy delete mode 100644 spartan/lib/Prelude.thy (limited to 'spartan/lib') diff --git a/spartan/lib/List.thy b/spartan/lib/List.thy deleted file mode 100644 index 4beb9b6..0000000 --- a/spartan/lib/List.thy +++ /dev/null @@ -1,191 +0,0 @@ -chapter \Lists\ - -theory List -imports Maybe - -begin - -(*TODO: Inductive type and recursive function definitions. The ad-hoc - axiomatization below should be subsumed once general inductive types are - properly implemented.*) - -axiomatization - List :: \o \ o\ and - nil :: \o \ o\ and - cons :: \o \ o \ o \ o\ and - ListInd :: \o \ (o \ o) \ o \ (o \ o \ o \ o) \ o \ o\ -where - ListF: "A: U i \ List A: U i" and - - List_nil: "A: U i \ nil A: List A" and - - List_cons: "\x: A; xs: List A\ \ cons A x xs: List A" and - - ListE: "\ - xs: List A; - c\<^sub>0: C (nil A); - \x xs rec. \x: A; xs: List A; rec: C xs\ \ f x xs rec: C (cons A x xs); - \xs. xs: List A \ C xs: U i - \ \ ListInd A (fn xs. C xs) c\<^sub>0 (fn x xs rec. f x xs rec) xs: C xs" and - - List_comp_nil: "\ - c\<^sub>0: C (nil A); - \x xs rec. \x: A; xs: List A; rec: C xs\ \ f x xs rec: C (cons A x xs); - \xs. xs: List A \ C xs: U i - \ \ ListInd A (fn xs. C xs) c\<^sub>0 (fn x xs rec. f x xs rec) (nil A) \ c\<^sub>0" and - - List_comp_cons: "\ - xs: List A; - c\<^sub>0: C (nil A); - \x xs rec. \x: A; xs: List A; rec: C xs\ \ f x xs rec: C (cons A x xs); - \xs. xs: List A \ C xs: U i - \ \ - ListInd A (fn xs. C xs) c\<^sub>0 (fn x xs rec. f x xs rec) (cons A x xs) \ - f x xs (ListInd A (fn xs. C xs) c\<^sub>0 (fn x xs rec. f x xs rec) xs)" - -lemmas - [form] = ListF and - [intr, intro] = List_nil List_cons and - [elim "?xs"] = ListE and - [comp] = List_comp_nil List_comp_cons - -abbreviation "ListRec A C \ ListInd A (fn _. C)" - -Lemma list_cases [cases]: - assumes - "xs: List A" and - nil_case: "c\<^sub>0: C (nil A)" and - cons_case: "\x xs. \x: A; xs: List A\ \ f x xs: C (cons A x xs)" and - "\xs. xs: List A \ C xs: U i" - shows "C xs" - by (elim xs) (fact nil_case, rule cons_case) - - -section \Notation\ - -definition nil_i ("[]") - where [implicit]: "[] \ nil {}" - -definition cons_i (infixr "#" 120) - where [implicit]: "x # xs \ cons {} x xs" - -translations - "[]" \ "CONST List.nil A" - "x # xs" \ "CONST List.cons A x xs" -syntax - "_list" :: \args \ o\ ("[_]") -translations - "[x, xs]" \ "x # [xs]" - "[x]" \ "x # []" - - -section \Standard functions\ - -subsection \Head and tail\ - -Definition head: - assumes "A: U i" "xs: List A" - shows "Maybe A" -proof (cases xs) - show "none: Maybe A" by intro - show "\x. x: A \ some x: Maybe A" by intro -qed - -Definition tail: - assumes "A: U i" "xs: List A" - shows "List A" -proof (cases xs) - show "[]: List A" by intro - show "\xs. xs: List A \ xs: List A" . -qed - -definition head_i ("head") where [implicit]: "head xs \ List.head {} xs" -definition tail_i ("tail") where [implicit]: "tail xs \ List.tail {} xs" - -translations - "head" \ "CONST List.head A" - "tail" \ "CONST List.tail A" - -Lemma head_type [type]: - assumes "A: U i" "xs: List A" - shows "head xs: Maybe A" - unfolding head_def by typechk - -Lemma head_of_cons [comp]: - assumes "A: U i" "x: A" "xs: List A" - shows "head (x # xs) \ some x" - unfolding head_def by compute - -Lemma tail_type [type]: - assumes "A: U i" "xs: List A" - shows "tail xs: List A" - unfolding tail_def by typechk - -Lemma tail_of_cons [comp]: - assumes "A: U i" "x: A" "xs: List A" - shows "tail (x # xs) \ xs" - unfolding tail_def by compute - -subsection \Append\ - -Definition app: - assumes "A: U i" "xs: List A" "ys: List A" - shows "List A" - apply (elim xs) - \<^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" - -translations "app" \ "CONST List.app A" - -subsection \Map\ - -Definition map: - assumes "A: U i" "B: U i" "f: A \ B" "xs: List A" - shows "List B" -proof (elim xs) - show "[]: List B" by intro - next fix x ys - assuming "x: A" "ys: List B" - show "f x # ys: List B" by typechk -qed - -definition map_i ("map") where [implicit]: "map \ List.map {} {}" - -translations "map" \ "CONST List.map A B" - -Lemma map_type [type]: - assumes "A: U i" "B: U i" "f: A \ B" "xs: List A" - shows "map f xs: List B" - unfolding map_def by typechk - - -subsection \Reverse\ - -Definition rev: - assumes "A: U i" "xs: List A" - shows "List A" - apply (elim xs) - \<^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 {}" - -translations "rev" \ "CONST List.rev A" - -Lemma rev_type [type]: - assumes "A: U i" "xs: List A" - shows "rev xs: List A" - unfolding rev_def by typechk - -Lemma rev_nil [comp]: - assumes "A: U i" - shows "rev (nil A) \ nil A" - unfolding rev_def by compute - - -end diff --git a/spartan/lib/Maybe.thy b/spartan/lib/Maybe.thy deleted file mode 100644 index 452acc2..0000000 --- a/spartan/lib/Maybe.thy +++ /dev/null @@ -1,75 +0,0 @@ -chapter \Maybe type\ - -theory Maybe -imports Prelude - -begin - -text \Defined as a sum.\ - -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+ - -Definition 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 "C m" - using assms[unfolded Maybe_def none_def some_def, type] - apply (elim m) - apply fact - apply (elim, fact) - done - -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 C c\<^sub>0 f (none A) \ c\<^sub>0" - using assms - unfolding Maybe_def MaybeInd_def none_def some_def - by compute - -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 C c\<^sub>0 f (some A a) \ f a" - using assms - unfolding Maybe_def MaybeInd_def none_def some_def - by compute - -lemmas - [form] = MaybeF and - [intr, intro] = Maybe_none Maybe_some and - [comp] = Maybe_comp_none Maybe_comp_some and - MaybeE [elim "?m"] = MaybeInd[rotated 4] -lemmas - Maybe_cases [cases] = MaybeE - -abbreviation "MaybeRec A C \ MaybeInd A (K C)" - -definition none_i ("none") where [implicit]: "none \ Maybe.none {}" -definition some_i ("some") where [implicit]: "some a \ Maybe.some {} a" - -translations - "none" \ "CONST Maybe.none A" - "some a" \ "CONST Maybe.some A a" - - -end diff --git a/spartan/lib/Prelude.thy b/spartan/lib/Prelude.thy deleted file mode 100644 index 56adbfc..0000000 --- a/spartan/lib/Prelude.thy +++ /dev/null @@ -1,151 +0,0 @@ -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 - [intr] = Sum_inl Sum_inr and - [intro] = 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 - [intr, intro] = 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" - using assms[unfolded Bool_def true_def false_def, type] - by (elim x) (elim, fact)+ - -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 compute - -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 compute - -lemmas - [form] = BoolF and - [intr, intro] = 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 "!x \ ifelse (K Bool) x false true" - - -end -- cgit v1.2.3