package lambdapi
All checked builds pass sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Proof assistant for the λΠ-calculus modulo rewriting
Install
dune-project
Dependency
Authors
Maintainers
Sources
lambdapi-4.0.0.tbz
sha256=0e2e73e0ea0c674f1263bf85ed3453ed3d6084d38eea29974a03ba9e382d29d7
sha512=2831db57fcd09206687a92fc9ee7d363e87bcec5167949e9c8161d41c63d5887b9f3556bfd63a7a9a0c12e5a5dc61a397baf4f496ebdb2a2fce122142c05e7a1
doc/src/lambdapi.core/builtin.ml.html
Source file builtin.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259(** Registering and checking builtin symbols. *) open Lplib open Base open Extra open Timed open Common open Error open Pos open Term open Sig_state open Sign (** [get ss pos path name] returns the symbol mapped to the builtin [name] in [path] if any. If the symbol cannot be found then [Fatal] is raised. *) let get : sig_state -> popt -> Path.t -> string -> sym = fun ss pos p s -> match p with | [] -> (* Symbol in scope. *) begin try StrMap.find s ss.builtins with Not_found -> fatal pos "Unknown builtin \"%s\"." s end | [m] when StrMap.mem m ss.alias_path -> (* Aliased module path. *) begin (* The signature must be loaded (alias is mapped). *) let sign = try Path.Map.find (StrMap.find m ss.alias_path) !loaded with _ -> assert false (* Should not happen. *) in (* Look for the symbol. *) try StrMap.find s !(sign.sign_builtins) with Not_found -> fatal pos "Unknown builtin \"%a.%s\"." Path.pp p s end | _ -> (* Fully-qualified symbol. *) begin (* Check that the signature was required (or is the current one). *) if p <> ss.signature.sign_path then if not (Path.Map.mem p !(ss.signature.sign_deps)) then fatal pos "No module %a required." Path.pp p; (* The signature must have been loaded. *) let sign = try Path.Map.find p !loaded with Not_found -> assert false (* Should not happen. *) in (* Look for the symbol. *) try StrMap.find s !(sign.sign_builtins) with Not_found -> fatal pos "Unknown builtin \"%a.%s\"." Path.pp p s end (** Type of functions checking the validity of a builtin symbol in a given signature state. The [pos] argument is used for error reporting. *) type check = sig_state -> popt -> sym -> unit let no_check _ _ _ = () (** Hash-table used to record checking functions for builtins. *) let htbl : (string, check) Hashtbl.t = Hashtbl.create 17 (** [check name] returns the registered check function for [name]. *) let check (name:string): check = try Hashtbl.find htbl name with Not_found -> fatal_msg "Bug: undeclared builtin \"%s\".@." name; assert false (** [register name check] registers the checking function [check], for the builtin symbols named [name]. When the check is run, [check] receives as argument a position for error reporting as well as the map of every builtin symbol in scope. It is expected to raise the [Fatal] exception to signal an error. Note that this function should not be called using a [name] for which a check has already been registered. *) let register (name:string) (check:check): unit = if Hashtbl.mem htbl name then (fatal_msg "Bug: builtin \"%s\" already declared.@." name; assert false) else Hashtbl.add htbl name check (** [register_expected_type name build pp] registers a checking function that checks the type of a symbol defining the builtin [name] against a type constructed using the given [build] function. *) let register_expected_type : term eq -> term pp -> string -> (sig_state -> popt -> term) -> unit = fun eq pp name mk_type -> let check ss pos sym = let actual = !(sym.sym_type) in let expected = mk_type ss pos in if not (eq actual expected) then fatal pos "%a is not convertible to %a." pp actual pp expected in register name check (** Declare and check the types of builtins. *) module M = struct type t = {state:sig_state; pos:popt} let mk_config ss pos = {state = ss; pos} let builtin s c = mk_Symb (get c.state c.pos [] s) (* String builtin. *) let str = builtin "String" let _ = register "String" no_check (* Builtins for decimal notation. *) let _ = register "+1" no_check; register "0" no_check; register "1" no_check; register "2" no_check; register "3" no_check; register "4" no_check; register "5" no_check; register "6" no_check; register "7" no_check; register "8" no_check; register "9" no_check; register "10" no_check; register "+" no_check; register "*" no_check; register "pos_one" no_check; register "pos_double" no_check; register "pos_succ_double" no_check; register "int_zero" no_check; register "int_positive" no_check; register "int_negative" no_check; register "-" no_check let typ _c = mk_Type let arr f g c = mk_Arro(f c, g c) let app f g c = mk_Appl(f c, g c) let var x _c = mk_Vari x let prod f g c = mk_Prod(f c, let x = new_var "x" in bind_var x (g x c)) let apps = List.fold_left app let register_typ s f = register_expected_type (Eval.eq_modulo []) Print.term s (fun ss pos -> f (mk_config ss pos)) (* Prop and P builtins. *) let prop = builtin "Prop" let prf = builtin "Prf" let _ = register_typ "Prop" typ; register_typ "Prf" (arr prop typ) (* Set and T builtins. *) let set = builtin "Set" let elt = app (builtin "El") let _ = register_typ "Set" typ; register_typ "El" (arr set typ) (* Additional builtins for why3 tactic. *) let _ = let unary = arr prop prop in let binary = arr prop unary in (* Π a:Set, (El a → Prop) → Prop *) let quant = prod set (fun a -> arr (arr (elt (var a)) prop) prop) in register_typ "bot" prop; register_typ "top" prop; register_typ "not" unary; register_typ "or" binary; register_typ "and" binary; register_typ "imp" binary; register_typ "eqv" binary; register_typ "ex" quant; register_typ "all" quant (* Additional builtins for rewrite tactic. *) let eq = builtin "eq" let encoded_arr = builtin "arr" let _ = (* Π a:Set, El a → El a → Prop *) register_typ "eq" (prod set (fun a -> arr (elt (var a)) (arr (elt (var a)) prop))); (* Π a:Set, Π x:El a, Prf (eq a x x) *) register_typ "refl" (prod set (fun a -> prod (elt (var a)) (fun x -> app prf (apps eq [var a; var x; var x])))); (* Π a:Set, Π x:El a, Π y:El a, Prf (eq a x y) → Π p:T a → Prop, Prf (p y) → Prf (p x) *) register_typ "eqind" (prod set (fun a -> prod (elt (var a)) (fun x -> prod (elt (var a)) (fun y -> arr (app prf (apps eq [var a; var x; var y])) (prod (arr (elt (var a)) prop) (fun p -> arr (app prf (app (var p) (var y))) (app prf (app (var p) (var x))))))))); (* Set → Set → Set *) register_typ "arr" (arr set (arr set set)); (* Π a b:Set, Π f g:El (arr a b), (Π x:El a, Prf (eq b (f x) (g x))) → Prf (eq (arr a b) f g) *) register_typ "funExt" (prod set (fun a -> prod set (fun b -> let ab = apps encoded_arr [var a; var b] in prod (elt ab) (fun f -> prod (elt ab) (fun g -> arr (prod (elt (var a)) (fun x -> app prf (apps eq [ var b ; app (var f) (var x) ; app (var g) (var x) ]))) (app prf (apps eq [ab; var f; var g]))))))) (* Additional builtins for eval tactic. *) let tac = builtin "Tactic" let lvl = builtin "Level" let univ = app (builtin "Univ") let eps l u = app (app (builtin "Type") l) u let _ = register_typ "Level" typ; register_typ "Univ" (arr lvl typ); register_typ "Type" (prod lvl (fun l -> arr (univ (var l)) typ)); register_typ "Tactic" typ; let t1 = prod lvl (fun l -> prod (univ (var l)) (fun a -> arr (eps (var l) (var a)) tac)) in let t2 = prod lvl (fun l -> prod (univ (var l)) (fun a -> arr (arr (eps (var l) (var a)) tac) tac)) in register_typ "admit" tac; register_typ "all_hyps" (arr t1 tac); register_typ "apply" t1; register_typ "assume" (arr str t2); register_typ "assumption" tac; register_typ "change" t1; register_typ "compose" (arr tac (arr tac tac)); register_typ "fail" tac; register_typ "first_hyp" (arr t1 tac); register_typ "focus" (arr str tac); register_typ "generalize" t1; register_typ "have" (arr str t1); register_typ "induction" tac; register_typ "orelse" (arr tac (arr tac tac)); register_typ "print" (arr str tac); register_typ "refine" (arr str tac); register_typ "reflexivity" tac; register_typ "remove" t1; register_typ "repeat" (arr tac tac); register_typ "rewrite" (arr str (arr str t1)); register_typ "set" (arr str t1); register_typ "simplify" tac; register_typ "simplify rule off" tac; register_typ "solve" tac; register_typ "symmetry" tac; register_typ "try" (arr tac tac); register_typ "why3" tac end
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>