From 60f32406e8c9712c0689d54a3dd4f8e17d310d52 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Mon, 25 May 2020 18:50:59 +0200 Subject: Lists + more reorganizing --- spartan/core/Spartan.thy | 9 ++++-- spartan/data/List.thy | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) (limited to 'spartan') diff --git a/spartan/core/Spartan.thy b/spartan/core/Spartan.thy index b4f7772..50002a6 100644 --- a/spartan/core/Spartan.thy +++ b/spartan/core/Spartan.thy @@ -18,6 +18,11 @@ section \Preamble\ declare [[eta_contract=false]] +syntax "_dollar" :: \logic \ logic \ logic\ (infixr "$" 3) +translations "a $ b" \ "a (b)" + +abbreviation (input) K where "K x \ \_. x" + section \Metatype setup\ @@ -118,8 +123,8 @@ axiomatization where p: \x: A. B x; A: U i; \x. x : A \ B x: U i; - \p. p: \x: A. B x \ C p: U i; - \x y. \x: A; y: B x\ \ f x y: C + \x y. \x: A; y: B x\ \ f x y: C ; + \p. p: \x: A. B x \ C p: U i \ \ SigInd A (\x. B x) (\p. C p) f p: C p" and Sig_comp: "\ diff --git a/spartan/data/List.thy b/spartan/data/List.thy index 71a879b..323ef7e 100644 --- a/spartan/data/List.thy +++ b/spartan/data/List.thy @@ -3,4 +3,83 @@ imports Spartan 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; l: List A\ \ cons A x l: List A" and + + ListE: "\ + xs: List A; + c\<^sub>0: C (nil A); + \x xs c. \x: A; xs: List A; c: C xs\ \ f x xs c: C (cons A x xs); + \xs. xs: List A \ C xs: U i + \ \ ListInd A (\xs. C xs) c\<^sub>0 (\x xs c. f x xs c) xs: C xs" and + + List_comp_nil: "\ + c\<^sub>0: C (nil A); + \x xs c. \x: A; xs: List A; c: C xs\ \ f x xs c: C (cons A x xs); + \xs. xs: List A \ C xs: U i + \ \ ListInd A (\xs. C xs) c\<^sub>0 (\x xs c. f x xs c) (nil A) \ c\<^sub>0" and + + List_comp_cons: "\ + xs: List A; + c\<^sub>0: C (nil A); + \x xs c. \x: A; xs: List A; c: C xs\ \ f x xs c: C (cons A x xs); + \xs. xs: List A \ C xs: U i + \ \ + ListInd A (\xs. C xs) c\<^sub>0 (\x xs c. f x xs c) (cons A x xs) \ + f x xs (ListInd A (\xs. C xs) c\<^sub>0 (\x xs c. f x xs c) xs)" + +lemmas + [intros] = ListF List_nil List_cons and + [elims "?xs"] = ListE and + [comps] = List_comp_nil List_comp_cons + +abbreviation "ListRec A C \ ListInd A (K C)" + + +section \Implicit notation\ + +definition nil_i ("[]") + where [implicit]: "[] \ nil ?" + +definition cons_i (infixr "#" 50) + where [implicit]: "x # l \ cons ? x l" + + +section \Standard functions\ + +definition "tail A \ \xs: List A. ListRec A (List A) (nil A) (\x xs _. xs) xs" + +definition "map A B \ \f: A \ B. \xs: List A. + ListRec A (List B) (nil B) (\x _ c. cons B (f `x) c) xs" + +definition tail_i ("tail") + where [implicit]: "tail xs \ List.tail ? xs" + +definition map_i ("map") + where [implicit]: "map \ List.map ? ?" + +Lemma tail_type [typechk]: + assumes "A: U i" "xs: List A" + shows "tail xs: List A" + unfolding tail_def by typechk + +Lemma map_type [typechk]: + assumes "A: U i" "B: U i" "f: A \ B" "xs: List A" + shows "map f xs: List B" + unfolding map_def by typechk + + end -- cgit v1.2.3