Skip to content

Commit

Permalink
at least it works
Browse files Browse the repository at this point in the history
  • Loading branch information
forked-from-1kasper committed Oct 23, 2023
1 parent 5d22b8b commit f8f56ba
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 39 deletions.
17 changes: 12 additions & 5 deletions library/data/equiv.anders
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ section
hcomp (Glue A φ [(φ = 1) → e 1=1]) ψ (λ (i : I), [(ψ = 1) → u i 1=1]) (ouc u₀)
end

def transportε (A B : U) (p : PathP (<_> U) A B) : A → B :=
λ (x : A), transp p 0 (transp (<_> A) 0 x)

def transportεIsEquiv (A B : U) (p : PathP (<_> U) A B) : isEquiv A B (transportε A B p) :=
(transp (<i> equiv A (p @ i)) 0 (idEquiv A)).2

def idtoeqv (A B : U) (p : PathP (<_> U) A B) : equiv A B :=
transp (<i> equiv A (p @ i)) 0 (idEquiv A)
(transportε A B p, transportεIsEquiv A B p)

def ua (A B : U) (e : equiv A B) : PathP (<_> U) A B :=
<i> Glue B (∂ i) [(i = 0) → (A, e), (i = 1) → (B, idEquiv B)]
Expand All @@ -84,9 +90,10 @@ propPi B (λ (y : B), isContr (fiber A B f y))
def idtoeqv→trans (A B : U) (p : PathP (<_> U) A B) : Path (A → B) (idtoeqv A B p).1 (trans A B p) :=
<i> λ (a : A), transp p 0 (transp (<_> A) i a)

def ideqv-compute (A B : U) (e : equiv A B) : Path (A → B) (idtoeqv A B (ua A B e)).1 e.1 :=
def ideqv-compute (A B : U) (e : equiv A B) : Path (A → B) (transportε A B (ua A B e)) e.1 :=
comp-Path (A → B) (idtoeqv A B (ua A B e)).1 (trans A B (ua A B e)) e.1 (idtoeqv→trans A B (ua A B e)) (ua-β A B e)

-- should “isEquiv” be opaque?
--def idtoeqv-ua (A B : U) (e : equiv A B) : Path (equiv A B) (idtoeqv A B (ua A B e)) e :=
--lemSig (A → B) (isEquiv A B) (isEquivProp A B) (idtoeqv A B (ua A B e)) e (ideqv-compute A B e)
opaque transportεIsEquiv

def idtoeqv-ua (A B : U) (e : equiv A B) : Path (equiv A B) (idtoeqv A B (ua A B e)) e :=
lemSig (A → B) (isEquiv A B) (isEquivProp A B) (idtoeqv A B (ua A B e)) e (ideqv-compute A B e)
2 changes: 1 addition & 1 deletion share/anders-vscode/syntaxes/anders.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"name": "comment.line.double-dash.anders"
},
{
"match": "(?<=^|[\\s()\\[\\]])(token|unsafe|macro|macrovariables|prefix|postfix|infix|infixr|infixl|#eval|#infer|#macroexpand|option|axiom|postulate|def|definition|theorem|lemma|corollary|proposition|import|with|begin|section|end|variables|let|in)(?=$|[\\s()\\[\\]])",
"match": "(?<=^|[\\s()\\[\\]])(token|unsafe|macro|macrovariables|prefix|postfix|infix|infixr|infixl|#eval|#infer|#macroexpand|option|opaque|axiom|postulate|def|definition|theorem|lemma|corollary|proposition|import|with|begin|section|end|variables|let|in)(?=$|[\\s()\\[\\]])",
"name": "keyword.other.anders"
},
{
Expand Down
1 change: 1 addition & 0 deletions src/frontend/decl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let rec checkLine conf = function
| Infer e -> Printf.printf "INFER: %s\n" (Prettyprinter.showExp (infer e)); flush_all (); conf
| Eval e -> Printf.printf "EVAL: %s\n" (Prettyprinter.showExp (eval e)); flush_all (); conf
| Operator (op, prec, is) -> List.iter (fun i -> Parser.operators := Dict.add i (op, prec) !Parser.operators) is; conf
| Opaque x -> opaque x; conf
| Decl d ->
if !Prefs.verbose then begin
Printf.printf "Checking: %s\n" (getDeclName d); flush_all ()
Expand Down
32 changes: 16 additions & 16 deletions src/frontend/module.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,28 @@ type command =
| Command of string * exp

type decl =
| Def of string * exp option * exp
| Ext of string * exp * string
| Def of string * exp option * exp
| Ext of string * exp * string
| Axiom of string * exp

type associativity = Left | Right | Neither
type operator = Infix of associativity | Prefix | Postfix

type line =
| Operator of operator * float * string list
| Import of string list
| Plugin of string
| Option of string * string
| Variables of tele list
| Operator of operator * float * string list
| Import of string list
| Plugin of string
| Option of string * string
| Opaque of string
| Variables of tele list
| Macrovariables of string list
| Token of string list
| Macro of bool * syntax * syntax
| Macroexpand of syntax
| Decl of decl
| Infer of exp
| Eval of exp
| Section | End
| Skip
| Eof
| Token of string list
| Macro of bool * syntax * syntax
| Macroexpand of syntax
| Decl of decl
| Infer of exp
| Eval of exp
| Section | End | Skip | Eof

type content = line list
type file = content
Expand Down Expand Up @@ -86,6 +85,7 @@ let showLine = function
| Plugin p -> Printf.sprintf "plugin %s" p
| Option (opt, value) -> Printf.sprintf "option %s %s" opt value
| Decl d -> showDecl d
| Opaque x -> Printf.sprintf "opaque %s" x
| Section -> "section" | End -> "end"
| Variables xs -> Printf.sprintf "variables%s" (showTeles xs)
| Macrovariables is -> Printf.sprintf "macrovariables %s" (String.concat " " is)
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ let ws = str isWhitespace >> eps
let nl = str (fun c -> c = '\n' || c = '\r') >> eps
let keywords = ["def"; "definition"; "theorem"; "lemma"; "proposition"; "macro"; "import";
"prefix"; "postfix"; "infixl"; "infixr"; "infix"; "postulate"; "axiom";
"macrovariables"; "option"; "unsafe"; "variables"; "section"; "end";
"macrovariables"; "option"; "opaque"; "unsafe"; "variables"; "section"; "end";
"token"; "#macroexpand"; "#infer"; "#eval"; "--"; "{-"; "-}"]
let reserved = ['('; ')'; '['; ']'; '<'; '>'; '\n'; '\t'; '\r'; ' '; '.'; ',']

Expand Down Expand Up @@ -543,9 +543,10 @@ let tokens = token "token" >> ws >> sepBy1 ws ident >>= fun is -> pure (
let variables = token "variables" >> ws >> binders >>= fun bs -> pure (Variables bs)
let import = token "import" >> ws >> sepBy1 ws ident >>= fun fs -> pure (Import fs)
let options = token "option" >> ws >> ident >>= fun i -> ws >> ident >>= fun v -> pure (Option (i, v))
let opaque = token "opaque" >> ws >> ident >>= fun x -> pure (Opaque x)
let section = (token "section" >> pure Section) <|> (token "end" >> pure End)

let commands = import <|> variables <|> options <|> operator <|> macroexpand <|> infer <|> eval <|> macrovariables <|> tokens
let commands = import <|> variables <|> options <|> opaque <|> operator <|> macroexpand <|> infer <|> eval <|> macrovariables <|> tokens
let cmdeof = eof >> pure Eof
let cmdline = def <|> axm <|> macro <|> commands <|> section <|> comment <|> cmdeof
let cmd = optional ws >> cmdline
Expand Down
1 change: 1 addition & 0 deletions src/frontend/radio.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ let transmit mesg =
let def p t e = transmit (Def (p, t, e))
let assign p t e = transmit (Assign (p, t, e))
let assume p t = transmit (Assume (p, t))
let opaque x = transmit (Opaque x)

let set p x = transmit (Set (p, x))
let wipe () = transmit Wipe
Expand Down
26 changes: 19 additions & 7 deletions src/kernel/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,28 @@ and app (f, x) = match f, x with

and evalSystem ctx = bimap (getDef ctx) (fun mu t -> eval (faceEnv mu ctx) t)

and getType ctx x = match Env.find_opt x ctx.local, Env.find_opt x !(ctx.global) with
and evalTerm ctx = function
| Exp e -> eval ctx e
| Value v -> v

and getType ctx x =
match Env.find_opt x ctx.local, Env.find_opt x !(ctx.global) with
| Some (t, _), _ -> t
| _, Some (t, _) -> t
| _, Some t -> evalTerm ctx t.typval
| _, _ -> raise (Internal (VariableNotFound x))

and getDef ctx x = match Env.find_opt x ctx.local, Env.find_opt x !(ctx.global) with
| Some (_, v), _ -> v
| _, Some (_, Value v) -> v
| _, Some (t, Exp e) -> let v = eval ctx e in upGlobal ctx x t (Value v); v
| _, _ -> raise (Internal (VariableNotFound x))
and getGlobalDef ctx x =
match Env.find_opt x !(ctx.global) with
| None -> raise (Internal (VariableNotFound x))
| Some t ->
if t.opaque then Var (x, evalTerm ctx t.typval)
else match t.defval with
| Value v -> v
| Exp e -> let v = eval ctx e in upGlobal ctx x { t with defval = Value v }; v

and getDef ctx x = match Env.find_opt x ctx.local with
| Some (_, v) -> v
| None -> getGlobalDef ctx x

and appFormulaE ctx e i = eval ctx (EAppFormula (e, i))

Expand Down
10 changes: 7 additions & 3 deletions src/kernel/chm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ let proto : req -> resp = function
| Def (x, t0, e0) -> promote (fun () ->
let t = freshExp t0 in let e = freshExp e0 in
isType (infer ctx t); let t' = eval ctx t in
check ctx e t'; assign ctx x t' (getTerm e); OK)
check ctx e t'; assign ctx x (Value t') (getTerm e); OK)
| Opaque x -> let y = ident x in
promote (fun () -> match Env.find_opt y !(ctx.global) with
| Some t -> upGlobal ctx y { t with opaque = true }; OK
| None -> Error (VariableNotFound y))
| Assign (x, t0, e0) -> promote (fun () ->
let t = freshExp t0 in isType (infer ctx t);
assign ctx x (eval ctx t) (getTerm (freshExp e0)); OK)
assign ctx x (Value (eval ctx t)) (getTerm (freshExp e0)); OK)
| Assume (x, t0) -> promote (fun () -> let t = freshExp t0 in
isType (infer ctx t); let t' = eval ctx t in
assign ctx x t' (Value (Var (ident x, t'))); OK)
assign ctx x (Value t') (Value (Var (ident x, t'))); OK)
| Erase x -> ctx.global := Env.remove (ident x) !(ctx.global); OK
| Wipe -> ctx.global := Env.empty; OK
| Set (p, x) ->
Expand Down
8 changes: 5 additions & 3 deletions src/kernel/term.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ and clos = ident * (value -> value)

type term = Exp of exp | Value of value

type decl = { typval : term; defval : term; opaque : bool }

type ctx =
{ local : (value * value) Env.t;
global : (value * term) Env.t ref }
global : decl Env.t ref }

(* Implementation *)

Expand All @@ -103,12 +105,12 @@ exception IncompatibleFaces

let upVar p x ctx = match p with Irrefutable -> ctx | _ -> Env.add p x ctx
let upLocal ctx p t v = { ctx with local = upVar p (t, v) ctx.local }
let upGlobal ctx p t v = ctx.global := upVar p (t, v) !(ctx.global)
let upGlobal ctx p t = ctx.global := upVar p t !(ctx.global)

let assign ctx x t e =
if Env.mem (ident x) !(ctx.global)
then raise (Internal (AlreadyDeclared x))
else upGlobal ctx (ident x) t e
else upGlobal ctx (ident x) { typval = t; defval = e; opaque = false }

let freshVar ns n = match Env.find_opt n ns with Some x -> x | None -> n
let mapFace fn phi = Env.fold (fun p d -> Env.add (fn p) d) phi Env.empty
Expand Down
3 changes: 2 additions & 1 deletion src/language/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ struct
| '\x21' -> let x = string () in let (t, e) = exp2 () in Assign (x, t, e)
| '\x22' -> let x = string () in let t = exp () in Assume (x, t)
| '\x23' -> Erase (string ())
| '\x24' -> Wipe
| '\x24' -> Opaque (string ())
| '\x25' -> Wipe
| '\x30' -> let p = string () in let x = string () in Set (p, x)
| '\x31' -> Version
| '\x32' -> Ping
Expand Down
3 changes: 2 additions & 1 deletion src/language/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ struct
| Assign (x, t, e) -> W.put '\x21'; string x; exp2 t e
| Assume (x, t) -> W.put '\x22'; string x; exp t
| Erase x -> W.put '\x23'; string x
| Wipe -> W.put '\x24'
| Opaque x -> W.put '\x24'; string x
| Wipe -> W.put '\x25'
| Set (p, x) -> W.put '\x30'; string p; string x
| Version -> W.put '\x31'
| Ping -> W.put '\x32'
Expand Down
1 change: 1 addition & 0 deletions src/language/spec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type req =
| Assign of string * exp * exp
| Assume of string * exp
| Erase of string
| Opaque of string
| Wipe
(* configuration *)
| Set of string * string
Expand Down

0 comments on commit f8f56ba

Please sign in to comment.