Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rectification Campaign II: Restrictions, etc. #230

Merged
merged 64 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
64c89c8
not sure if needed
jonsterling Aug 14, 2018
213e08c
fix another potentially subtle bug
jonsterling Aug 14, 2018
adb8022
first pass at deleting box modality
jonsterling Aug 14, 2018
cabae7d
add files that I forgot to check in (Kind.mli, Lvl.mli)
jonsterling Aug 14, 2018
19c5abc
remove locks, tick constant, etc.
jonsterling Aug 14, 2018
e205cba
delete bad idea, push_restriction
jonsterling Aug 14, 2018
0c0e819
adding explicit support for definitions, don't use "singleton types" …
jonsterling Aug 14, 2018
ebdfc1c
dead code
jonsterling Aug 14, 2018
26672d1
fancy typechecking algorithm with judgmental restriction
jonsterling Aug 14, 2018
b60085e
start keeping track of which of Evan's brutal examples work
jonsterling Aug 14, 2018
18a56fb
add evan's brutal stuff to the makefile :)
jonsterling Aug 14, 2018
f4df7db
do not try to support subtyping between a restriction type & non-rest…
jonsterling Aug 14, 2018
1ec2ce6
Revert "do not try to support subtyping between a restriction type & …
jonsterling Aug 14, 2018
fcc741e
start adding more info to tactic input (just adding record for now)
jonsterling Aug 14, 2018
d4930fa
minor code cleanup
jonsterling Aug 14, 2018
8d930fb
code simplification
jonsterling Aug 14, 2018
f44b4c5
potential switcharoo ???
jonsterling Aug 14, 2018
3d05532
trying to get less owned by things being backwards ??
jonsterling Aug 14, 2018
375dd34
pretty printing for debugging
jonsterling Aug 15, 2018
46943e7
more partial fixing of resolution bugs
jonsterling Aug 15, 2018
f30b783
more debuggable clause lookup
jonsterling Aug 15, 2018
11ff3c6
debugging
jonsterling Aug 15, 2018
7337f54
turn off unused-variable error (MAKES DEBUGGING IMPOSSIBLE)
jonsterling Aug 15, 2018
af5f42b
some reasonable changes
jonsterling Aug 15, 2018
fa60b79
temporary stop checking boundaries of elim clauses until I rectify
jonsterling Aug 15, 2018
b56a4b6
think I may have fixed typechecking of elim
jonsterling Aug 15, 2018
31c81bf
minor fix
jonsterling Aug 15, 2018
943a280
first attempt to refine elim clause boundaries again
jonsterling Aug 15, 2018
08f0745
tentative fix to evan's other example
jonsterling Aug 15, 2018
0ffabba
remove comment
jonsterling Aug 15, 2018
259a407
fix another bug found by @ecavallo (keep 'em coming!)
jonsterling Aug 15, 2018
d414fe0
reformat some code to use Jon Sterling Thought
jonsterling Aug 15, 2018
be824ce
progress toward super advanced restriction-oriented elaborator
jonsterling Aug 15, 2018
f253007
explain Evan's other example
jonsterling Aug 15, 2018
37abe04
rename utility function
jonsterling Aug 15, 2018
d842fbb
don't let the user type in a restriction type
jonsterling Aug 15, 2018
bf0a3bc
tentative fancy printing of goals with restriction
jonsterling Aug 15, 2018
9bf4359
fix generation of tactics for missing cases in elim
jonsterling Aug 15, 2018
306d043
comment
jonsterling Aug 15, 2018
96b60e3
smart constructor to decrease some term annotation clutter
jonsterling Aug 15, 2018
b023579
minor cleanup
jonsterling Aug 15, 2018
bb9f634
better version of typechecking algorithm
jonsterling Aug 15, 2018
6bbf7de
NO MORE MANUAL ETA EXPANSION!!!!
jonsterling Aug 15, 2018
01bda5c
cleanup examples
jonsterling Aug 15, 2018
0325751
adding a basic auto tactic
jonsterling Aug 15, 2018
a09e864
oops, remove quit statement
jonsterling Aug 15, 2018
aa17701
one more
jonsterling Aug 15, 2018
f199ded
exercise eta and auto a little more
jonsterling Aug 16, 2018
69b75be
Close #212; close #237
jonsterling Aug 16, 2018
84d3375
cleanup refiner interface a little
jonsterling Aug 16, 2018
63b60ad
factor sigma-intro out of elaborator and into refiner
jonsterling Aug 16, 2018
3d24751
automatically do sigma-intro in auto
jonsterling Aug 16, 2018
88e3df2
formatting
jonsterling Aug 16, 2018
2cd0212
Elaborator: don't invoke normalizer to apply frames to terms
jonsterling Aug 16, 2018
cdf0efe
add more stuff to torus example, note bug #240
jonsterling Aug 17, 2018
69bf48d
Resolve #240
jonsterling Aug 17, 2018
b99bac4
add "normalize" command (/cc @mortberg)
jonsterling Aug 17, 2018
edced45
finish up proof of torus ~ s1 × s1
jonsterling Aug 17, 2018
ee3804e
add links to other versions of the proof
jonsterling Aug 17, 2018
4893d69
resolve #238
jonsterling Aug 17, 2018
8daafc8
removing bad.red from source control
jonsterling Aug 17, 2018
d82643e
Oops, my fix didn't work. Just disable strict composition for now.
jonsterling Aug 17, 2018
40085ba
add a clarifying comment
jonsterling Aug 17, 2018
7df8692
remove bad.red from makefile
jonsterling Aug 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ examples:
${DUNE} exec -- redtt load-file nat.red
${DUNE} exec -- redtt load-file int.red
${DUNE} exec -- redtt load-file bool.red
${DUNE} exec -- redtt load-file bad.red
${DUNE} exec -- redtt load-file omega1s1-wip.red
${DUNE} exec -- redtt load-file torus.red
${DUNE} exec -- redtt load-file modal.red
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ and [cubicaltt](https://github.com/mortberg/cubicaltt).
supported) based on the [work of Evan Cavallo and Bob
Harper](https://arxiv.org/abs/1801.01568)

- experimental support for Fitch-style modal guarded recursion: □,
- experimental support for Fitch-style modal guarded recursion: ▷


Features we intend to add in the near future:
Expand Down
74 changes: 74 additions & 0 deletions bad.red
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import path

; Here are some tricky examples that Evan Cavallo came up with to expose bugs.

data O where
| obase
| oloop (y : O) @ i
[ i=0 ⇒ y
| i=1 ⇒ y
]

let thing0 (A : type) (B : (dim → A) → type) (p : dim → A) (b : B p) : B p =
let ty : dim → type = λ k →
let h : dim → A = λ l →
comp 0 l (p 0) [
| k=0 ⇒ λ z → p z
| k=1 ⇒ λ z → p z
]
in
B (λ l → h l)
in
(coe 0 1 b in ty)

let thing1 (A : type) (a : A) : Path A a a =
let bar =
thing0 A
(λ q → Path A (q 0) (q 1))
(λ _ → a)
(λ _ → a)

in
λ i -> bar i



let thing (A : type) (a,b : A) (p : Path A a b) : Path (Path A a b) p p =
λ i j →
let ty : dim → type = λ k →
let h : dim → A = λ l →
comp 0 l a [
| k=0 ⇒ λ z → p z
| k=1 ⇒ λ z → p z
]
in
Path (Path A (h 0) (h 1)) (λ l → h l) (λ l → h l)
in
(coe 0 1 (λ _ z → p z) in ty) i j

let experiment3 (A : type) (B : A -> type) (u : (a : A) -> B a) : Path ((a : A) -> B a) u u =
lam i ->
comp 0 1 u [
| i=0 => lam j -> u
| i=1 => lam j -> u
]



let experiment (A : type) (u : A)
: (p : Path A u u) -> (q : Path (Path A u u) p p) -> Path (Path A u u) p p
=
lam p q i ->
comp 0 1 (lam k -> p k) [
| i=0 => lam j k -> q j k
| i=1 => lam j k -> p k
]

; TODO: doesn't work yet, need elaborator support

;let experiment (A : type) (u : A) : Path A u u =
; lam i ->
; comp 0 1 ?cap [
; | i=0 => lam j -> ?left
; | i=1 => lam j -> ?right
; ]
54 changes: 0 additions & 54 deletions modal.red
Original file line number Diff line number Diff line change
Expand Up @@ -30,57 +30,3 @@ let stream/tl (xs : stream) : ✓ → stream =
let tts : _ =
fix xs : stream in
stream/cons tt xs


; To eliminate a box, write 'b !'; this elaborates to the core term `(open b).
let bool/constant (x : bool) : (b : □ bool) × Path _ x (b !) =
elim x [
| tt ⇒ < shut tt, λ _ → tt >
| ff ⇒ < shut ff, λ _ → ff >
]

let sequence : type = □ stream


let Next (A : type) (x : A) ✓ : A =
x

let sequence/cons (x : bool) (xs : sequence) : sequence =
shut
stream/cons
(bool/constant x .0 !)
(Next stream (xs !))
; this is suspicious: we use this Next in order to essentially
; weaken away the tick that we will not use, in order to get the right number
; of locks deleted. But this is proof-theoretically very strange.

; The proper solution to the problem above is to bind lock names in the syntax and in the context,
; analogous to tick names. This will make the calculus more baroque, but it will enable a
; deterministic version of the 'open' rule. The source term for the above would then be:
;
; λ α → stream/cons (bool/constant x .0 α) (λ β → xs α)
;
; Above, α is a lock name and β is a tick name; opening with the lock α
; would *delete* the tick β from the context (thinking backward), which is
; a tick weakening. the example would typecheck because there is no need for
; β in xs.
;
; For reference, the core-language term would look like the following:
;
; (shut [α]
; (stream/cons
; (open α (car (bool/constant x)))
; (next [β] (open α xs))))



let sequence/hd (xs : sequence) : bool =
stream/hd (xs !)

let sequence/tl (xs : sequence) : sequence =
shut
stream/tl (xs !) ∙


let law/k (A,B : type) (f : □ (A → B)) (x : □ A) : □ B =
shut f ! (x !)
9 changes: 9 additions & 0 deletions src/basis/Monad.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ struct
m >>= fun x ->
traverse f ms >>= fun xs ->
M.ret @@ x :: xs

let rec fold_left f acc xs =
match xs with
| [] ->
M.ret acc
| x :: xs ->
f acc x >>= fun a ->
fold_left f a xs

end
1 change: 1 addition & 0 deletions src/basis/Monad.mli
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ module Notation (M : S) : Notation with type 'a m := 'a M.m
module Util (M : S) :
sig
val traverse : ('a -> 'b) -> 'a M.m list -> 'a list M.m
val fold_left : ('a -> 'b -> 'a M.m) -> 'a -> 'b list -> 'a M.m
end

33 changes: 3 additions & 30 deletions src/core/Cx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ type cx =
env : Domain.env;
qenv : Quote.env;
ppenv : Pp.env;
rel : Restriction.t;
all_locks : int}
rel : Restriction.t}

type t = cx

Expand All @@ -39,31 +38,7 @@ let clear_locals cx =
qenv = Quote.Env.emp;
hyps = [];
ppenv = Pp.Env.emp;
env = Domain.Env.clear_locals cx.env;
all_locks = 0}
let ext_lock cx =
{cx with
sign = GlobalEnv.ext_lock cx.sign;
hyps = List.map (fun hyp -> {hyp with locked = true}) cx.hyps;
all_locks = cx.all_locks + 1}

let hyps_clear_locks hyps =
let rec go hyps =
match hyps with
| [] -> []
| hyp :: hyps ->
match hyp.classifier with
| `Tick -> hyp :: hyps (* Maybe not quite right *)
| _ ->
{hyp with locked = false} :: go hyps
in
go hyps

let clear_locks cx =
{cx with
sign = GlobalEnv.clear_locks cx.sign;
hyps = hyps_clear_locks cx.hyps;
all_locks = 0}
env = Domain.Env.clear_locals cx.env}

let kill_from_tick cx tgen =
match tgen with
Expand Down Expand Up @@ -144,7 +119,6 @@ let lookup i {hyps; _} =
hyp.classifier

let lookup_constant nm tw cx =
(* For constants, the only locks that are relevant are the global ones. Ignore the local locks. *)
GlobalEnv.lookup_ty cx.sign nm tw

let restrict cx r r' =
Expand Down Expand Up @@ -228,5 +202,4 @@ let init globals =
qenv = Quote.Env.emp;
hyps = [];
ppenv = Pp.Env.emp;
rel = GlobalEnv.restriction globals;
all_locks = 0}
rel = GlobalEnv.restriction globals}
5 changes: 1 addition & 4 deletions src/core/Cx.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ val qenv : t -> Quote.env

val clear_locals : t -> t

(* Modal left adjoints *)
val ext_lock : t -> t
val clear_locks : t -> t

(* Modal *)
val kill_from_tick : t -> Domain.tick_gen -> t

val ext_ty : t -> nm:string option -> value -> t * value
Expand Down
7 changes: 0 additions & 7 deletions src/core/Domain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ and pp_con fmt : con -> unit =
Format.fprintf fmt "<dfix>"
| DFixLine _ ->
Format.fprintf fmt "<dfix-line>"
| BoxModality _ ->
Format.fprintf fmt "<box-modality>"
| Shut _ ->
Format.fprintf fmt "<shut>"
| Data lbl ->
Uuseg_string.pp_utf_8 fmt lbl
| Intro info ->
Expand Down Expand Up @@ -236,9 +232,6 @@ and pp_neu fmt neu =
| FixLine _ ->
Format.fprintf fmt "<fix-line>"

| Open _ ->
Format.fprintf fmt "<open>"

and pp_elim_clauses fmt clauses =
let pp_sep fmt () = Format.fprintf fmt "@ " in
Format.pp_print_list ~pp_sep pp_elim_clause fmt clauses
Expand Down
6 changes: 0 additions & 6 deletions src/core/DomainData.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type tick_gen =
[`Lvl of string option * int | `Global of Name.t ]

type tick =
| TickConst
| TickGen of tick_gen


Expand Down Expand Up @@ -44,9 +43,6 @@ type con =
| DFix of {ty : value; clo : clo}
| DFixLine of {x : atom; ty : value; clo : clo}

| BoxModality of value
| Shut of value

| Data of Desc.data_label
| Intro of
{dlbl : Desc.data_label;
Expand Down Expand Up @@ -87,8 +83,6 @@ and neu =
| Fix of tick_gen * value * clo
| FixLine of atom * tick_gen * value * clo

| Open of neu

and nf = {ty : value; el : value}

and abs = value IAbs.abs
Expand Down
16 changes: 2 additions & 14 deletions src/core/GlobalEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type t =
{rel : Restriction.t;
data_decls : (Tm.tm, Tm.tm Desc.Boundary.term) Desc.desc StringTable.t;
table : (entry param * lock_info) T.t;
lock : int -> bool;
killed : int -> bool;
under_tick : int -> bool;
len : int}
Expand All @@ -26,7 +25,6 @@ let emp () =
{table = T.empty;
data_decls = StringTable.empty;
rel = Restriction.emp ();
lock = (fun _ -> false);
killed = (fun _ -> false);
under_tick = (fun _ -> false);
len = 0}
Expand Down Expand Up @@ -73,15 +71,6 @@ let ext_dim (sg : t) nm : t =
ext_ sg ~constant:false nm `I


let ext_lock (sg : t) : t =
{sg with
lock = fun i -> if i < sg.len then true else sg.lock i}

let clear_locks (sg : t) : t =
{sg with
lock = (fun i -> if sg.under_tick i then sg.lock i else false)}


let rec index_of pred xs =
match xs with
| [] -> failwith "index_of"
Expand All @@ -97,9 +86,8 @@ let kill_from_tick (sg : t) nm : t =

let lookup_entry sg nm tw =
let prm, linfo = T.find nm sg.table in
let locked = sg.lock linfo.birth in
let killed = sg.killed linfo.birth in
if not linfo.constant && (locked || killed) then
if not linfo.constant && killed then
failwith "GlobalEnv.lookup_entry: not accessible (modal!!)"
else
match prm, tw with
Expand Down Expand Up @@ -142,7 +130,7 @@ let pp fmt sg =
| `Tw _ ->
Format.fprintf fmt "%a[twin]"
Name.pp nm
| (`Tick | `I | `P _) ->
| (`Tick | `I | `P _ | `Def _) ->
Format.fprintf fmt "%a"
Name.pp nm
in
Expand Down
2 changes: 0 additions & 2 deletions src/core/GlobalEnv.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ val ext : t -> Name.t -> entry param -> t
val ext_meta : t -> Name.t -> entry param -> t
val ext_dim : t -> Name.t -> t
val ext_tick : t -> Name.t -> t
val ext_lock : t -> t
val restrict : Tm.tm -> Tm.tm -> t -> t
val clear_locks : t -> t
val kill_from_tick : t -> Name.t -> t


Expand Down
4 changes: 4 additions & 0 deletions src/core/Kind.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type t = [`Reg | `Kan | `Pre]

val lte : t -> t -> bool
val pp : t Pp.t0
6 changes: 6 additions & 0 deletions src/core/Lvl.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type t = [`Omega | `Const of int]

val greater : t -> t -> bool
val lte : t -> t -> bool
val shift : int -> t -> t
val pp : t Pp.t0
Loading