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.export/stt.ml.html
Source file stt.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(** Base module for translating lp proofs encoded in simple type theory. *) open Lplib open Extra open Common open Pos open Error open Parsing open Syntax open Core let log = Logger.make 'x' "xprt" "export" let log = log.pp module Qid = struct type t = Term.qident let compare = Stdlib.compare end module QidMap = Map.Make(Qid) (** Symbols necessary to encode STT. *) type builtin = Set | Prop | Arr | El | Imp | All | Prf | Eq | Or | And | Ex | Not let index_of_builtin = function | Set -> 0 | Prop -> 1 | Arr -> 2 | El -> 3 | Imp -> 4 | All -> 5 | Prf -> 6 | Eq -> 7 | Or -> 8 | And -> 9 | Ex -> 10 | Not -> 11 let nb_builtins = 12 let builtin_of_index = function | 0 -> Set | 1 -> Prop | 2 -> Arr | 3 -> El | 4 -> Imp | 5 -> All | 6 -> Prf | 7 -> Eq | 8 -> Or | 9 -> And | 10 -> Ex | 11 -> Not | _ -> assert false let _ = (* sanity check *) for i = 0 to nb_builtins - 1 do assert (index_of_builtin (builtin_of_index i) = i) done let index_of_name = function | "Set" -> Some 0 | "prop" -> Some 1 | "arr" -> Some 2 | "El" -> Some 3 | "imp" -> Some 4 | "all" -> Some 5 | "Prf" -> Some 6 | "eq" -> Some 7 | "or" -> Some 8 | "and" -> Some 9 | "ex" -> Some 10 | "not" -> Some 11 | _ -> None let name_of_index = function | 0 -> "Set" | 1 -> "prop" | 2 -> "arr" | 3 -> "El" | 4 -> "imp"| 5 -> "all" | 6 -> "Prf" | 7 -> "eq" | 8 -> "or" | 9 -> "and" | 10 -> "ex" | 11 -> "not" | _ -> assert false let _ = (* sanity check *) for i = 0 to nb_builtins - 1 do assert (index_of_name (name_of_index i) = Some i) done let builtin : Term.qident array = let path = ["STTfa"] in Array.init nb_builtins (fun i -> path, name_of_index i) let sym b = builtin.(index_of_builtin b) (** Set renaming map from file. *) let rmap = ref StrMap.empty let codom = ref StrSet.empty let add_renaming pos s1 s2 = let f = function | None -> Some s2 | Some s2' -> fatal pos "\"%s\" renamed to both \"%s\" and \"%s\"" s1 s2' s2 in if Logger.log_enabled() then log "rename %s into %s" s1 s2; rmap := StrMap.update s1 f !rmap; codom := StrSet.add s2 !codom let set_renaming : string -> unit = fun f -> let consume = function | {elt=P_builtin(string,{elt=(p,lp_id);pos=pos_id});pos} -> if p = [] then add_renaming pos lp_id string else fatal pos_id "Qualified identifier." | {pos;_} -> fatal pos "Invalid command." in Stream.iter consume (Parser.parse_file f) (** Set symbols whose declarations have to be erased. *) let mapping = ref QidMap.empty let add_mapping qid string = if Logger.log_enabled() then log "map %a to \"%s\"" Pretty.qident qid string; mapping := QidMap.add qid.elt string !mapping let set_mapping : string -> unit = fun f -> let consume = function | {elt=P_builtin(string,lp_qid);_} -> add_mapping lp_qid string | {pos;_} -> fatal pos "Invalid command." in Stream.iter consume (Parser.parse_file f) let current_mp = Stdlib.ref [] let is_mapped id = QidMap.mem ([],id) !mapping || QidMap.mem (!current_mp,id) !mapping (** Set encoding. *) let encoding = ref QidMap.empty let add_encoding qid b = encoding := QidMap.add qid b !encoding let set_encoding : string -> unit = fun f -> let found = Array.make nb_builtins false in let consume = function | {elt=P_builtin(n,({elt=qid;_} as lp_qid));pos} -> begin match index_of_name n with | Some i -> if Logger.log_enabled() then log "builtin \"%s\" = %a" n Pretty.qident lp_qid; builtin.(i) <- qid; found.(i) <- true; let b = builtin_of_index i in add_encoding qid b; if b = El || b = Prf then add_mapping lp_qid n | None -> fatal pos "Unknown builtin." end | {pos;_} -> fatal pos "Invalid command." in Stream.iter consume (Parser.parse_file f); Array.iteri (fun i b -> if not b then fatal None(*FIXME*) "Builtin %s undefined." (name_of_index i)) found let is_encoded id = QidMap.mem ([],id) !encoding || QidMap.mem (!current_mp,id) !encoding (** Map from symbol name to number of type variables (>0). A symbol with no entry is not polymorphic (arity =0). *) let tvs_map : int StrMap.t ref = ref StrMap.empty let set_tvs_map (fname:string): unit = let ic = open_in_bin fname in tvs_map := input_value ic; close_in ic (** Basic printing functions. We use Printf for efficiency reasons. *) let out = Printf.printf let char = output_char let newline oc = char oc '\n' let string = output_string let int oc i = string oc (string_of_int i) let prefix pre elt oc x = string oc pre; elt oc x let suffix elt suf oc x = elt oc x; string oc suf let list elt sep oc xs = match xs with | [] -> () | x::xs -> elt oc x; List.iter (prefix sep elt oc) xs (** Translation of identifiers. *) let check : (popt -> string -> unit) Stdlib.ref = ref (fun _ _ -> ()) let translate_ident {elt=s;pos}: string = try StrMap.find s !rmap with Not_found -> if StrSet.mem s !codom then s^"__alt__" else (!check pos s; s) let ident oc id = string oc (translate_ident id) let param_id oc idopt = match idopt with | Some id -> ident oc id | None -> char oc '_' let param_ids = list param_id " " let path_elt pos oc id = !check pos id; string oc id let path oc {elt;pos} = list (path_elt pos) "." oc elt let alias = Stdlib.ref StrMap.empty let rec qident oc {elt=((mp,id) as qid);pos} = match mp with | [] -> begin match QidMap.find_opt (!current_mp,id) !mapping with | None -> begin match QidMap.find_opt ([],id) !mapping with | None -> ident oc {elt=id;pos} | Some s -> string oc s end | Some s -> string oc s end | [p] -> begin match StrMap.find_opt p !alias with | Some mp -> qident oc {elt=(mp,id);pos} | None -> match QidMap.find_opt qid !mapping with | None -> path oc {elt=mp;pos}; char oc '.'; ident oc {elt=id;pos} | Some s -> string oc s end | _::mp -> begin match QidMap.find_opt (mp,id) !mapping with | None -> path oc {elt=mp;pos}; char oc '.'; ident oc {elt=id;pos} | Some s -> string oc s end (** Translation of terms. *) let stt = Stdlib.ref false let use_implicits = Stdlib.ref true let use_notations = Stdlib.ref false (* redefinition of p_get_args ignoring P_Wrap's. *) let p_get_args : p_term -> p_term * p_term list = fun t -> let rec p_get_args t acc = match t.elt with | P_Appl(t, u) -> p_get_args t (u::acc) | P_Wrap t -> p_get_args t acc | _ -> t, acc in p_get_args t [] let app t default cases = let h, ts = p_get_args t in if !stt then match h.elt with | P_Iden({elt;_},expl) -> begin match QidMap.find_opt elt !encoding with | None -> default h ts | Some builtin -> cases h ts expl builtin end | _ -> default h ts else default h ts let is_lem x = is_opaq x || is_priv x (** Set required file. *) let require = ref None let set_requiring : string -> unit = fun f -> require := Some f
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>