package dolmen
A parser library for automated deduction
Install
Dune Dependency
Authors
Maintainers
Sources
dolmen-0.8.1.tbz
sha256=80fc33ae81817a79c6e6b2f6c01c4cfcc0af02bfe4d2d1b87cf70b84cdde3928
sha512=3a44a99bce871161bc70cf909c813e9e6c91c590873cbc163c69b2ec90ab5be65bf0bf45430bc8d00d85d75cf0af004b06b8f5f1c9d4d47c8a30ab9f28762c04
doc/src/dolmen.std/statement.ml.html
Source file statement.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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
(* This file is free software, part of dolmen. See file "LICENSE" for more information. *) (* Type definitions *) type term = Term.t type location = Loc.t type abstract = { id : Id.t; ty : term; loc : location; } type inductive = { id : Id.t; vars : term list; cstrs : (Id.t * term list) list; loc : location; attrs : term list; } type record = { id : Id.t; vars : term list; fields : (Id.t * term) list; loc : location; attrs : term list; } type decl = | Abstract of abstract | Record of record | Inductive of inductive type def = { id : Id.t; loc : location; vars : term list; params : term list; ret_ty : term; body : term; } type 'a group = { contents : 'a list; recursive : bool; } type defs = def group type decls = decl group (* Description of statements. *) type descr = | Pack of t list | Pop of int | Push of int | Reset_assertions | Plain of term | Prove of term list | Clause of term list | Antecedent of term | Consequent of term | Include of string | Set_logic of string | Get_info of string | Set_info of term | Get_option of string | Set_option of term | Defs of def group | Decls of decl group | Get_proof | Get_unsat_core | Get_unsat_assumptions | Get_model | Get_value of term list | Get_assignment | Get_assertions | Echo of string | Reset | Exit (* Statements are wrapped in a record to have a location. *) and t = { id : Id.t option; descr : descr; attrs : term list; loc : location; } (* Dummy location *) let no_loc = Loc.no_loc (* (* Debug printing *) let pp_abstract b (i : abstract) = Printf.bprintf b "Abstract %a: %a\n" Id.pp i.id Term.pp i.ty let pp_inductive b (i : inductive) = Printf.bprintf b "Inductive(%d): %a, %a\n" (List.length i.cstrs) Id.pp i.id (Misc.pp_list ~pp_sep:Buffer.add_string ~sep:" " ~pp:Term.pp) i.vars; Misc.pp_list ~pp_sep:Buffer.add_string ~sep:"\n" ~pp:(fun b (cstr, l) -> Printf.bprintf b "%a: %a" Id.pp cstr (Misc.pp_list ~pp_sep:Buffer.add_string ~sep:" " ~pp:Term.pp) l ) b i.cstrs let pp_record b (i : record) = Printf.bprintf b "Record: %a, %a:\n { %a}\n" Id.pp i.id (Misc.pp_list ~pp_sep:Buffer.add_string ~sep:" " ~pp:Term.pp) i.vars (Misc.pp_list ~pp_sep:Buffer.add_string ~sep:";\n" ~pp:(fun b (id, ty) -> Printf.bprintf b "%a: %a" Id.pp id Term.pp ty )) i.fields let pp_decl b = function | Abstract a -> pp_abstract b a | Record r -> pp_record b r | Inductive i -> pp_inductive b i let pp_def b (d : def) = Printf.bprintf b "def: %a = %a" Id.pp d.id Term.pp d.body let pp_group pp b (d: _ group) = let aux = Misc.pp_list ~pp_sep:Buffer.add_string ~sep:"\n" ~pp in if d.recursive then Printf.bprintf b "rec (\n%a)" aux d.contents else aux b d.contents let rec pp_descr b = function | Pack l -> Printf.bprintf b "pack(%d):\n" (List.length l); Misc.pp_list ~pp_sep:Buffer.add_char ~sep:'\n' ~pp b l | Pop i -> Printf.bprintf b "pop: %d" i | Push i -> Printf.bprintf b "push: %d" i | Reset_assertions -> Printf.bprintf b "reset assertions" | Plain t -> Printf.bprintf b "plain: %a" Term.pp t | Prove [] -> Printf.bprintf b "Prove" | Prove l -> Printf.bprintf b "Prove assuming: %a" (Misc.pp_list ~pp_sep:Buffer.add_string ~sep:" && " ~pp:Term.pp) l | Clause l -> Printf.bprintf b "clause: %a" (Misc.pp_list ~pp_sep:Buffer.add_string ~sep:" || " ~pp:Term.pp) l | Antecedent t -> Printf.bprintf b "antecedent: %a" Term.pp t | Consequent t -> Printf.bprintf b "consequent: %a" Term.pp t | Include f -> Printf.bprintf b "include: %s" f | Set_logic s -> Printf.bprintf b "set-logic: %s" s | Get_info s -> Printf.bprintf b "get-info: %s" s | Set_info t -> Printf.bprintf b "set-info: %a" Term.pp t | Get_option s -> Printf.bprintf b "get-option: %s" s | Set_option t -> Printf.bprintf b "set-option: %a" Term.pp t | Defs p -> pp_group pp_def b p | Decls p -> pp_group pp_decl b p | Get_proof -> Printf.bprintf b "get-proof" | Get_unsat_core -> Printf.bprintf b "get-unsat-core" | Get_unsat_assumptions -> Printf.bprintf b "get-unsat-assumptions" | Get_model -> Printf.bprintf b "get-model" | Get_value l -> Printf.bprintf b "get-value(%d):\n" (List.length l); Misc.pp_list ~pp_sep:Buffer.add_string ~sep:"\n" ~pp:Term.pp b l | Get_assignment -> Printf.bprintf b "get-assignment" | Get_assertions -> Printf.bprintf b "get-assertions" | Echo s -> Printf.bprintf b "echo: %s" s | Reset -> Printf.bprintf b "reset" | Exit -> Printf.bprintf b "exit" and pp b = function { descr; _ } -> Printf.bprintf b "%a" pp_descr descr *) (* Pretty printing *) let print_abstract fmt (a : abstract) = Format.fprintf fmt "@[<hov 2>abstract:@ %a :@ %a@]" Id.print a.id Term.print a.ty let print_inductive fmt (i : inductive) = Format.fprintf fmt "@[<hv 2>Inductive(%d) %a(@[<hov>%a@]) =@ %a@]" (List.length i.cstrs) Id.print i.id (Misc.print_list ~print_sep:Format.fprintf ~sep:",@ " ~print:Term.print) i.vars (Misc.print_list ~print_sep:Format.fprintf ~sep:"@ " ~print:(fun fmt (cstr, l) -> Format.fprintf fmt "| %a : @[<hov>%a@]" Id.print cstr ( Misc.print_list ~print_sep:Format.fprintf ~sep:"@ " ~print:Term.print ) l)) i.cstrs let print_record fmt (r : record) = Format.fprintf fmt "@[<hv 2>Record %a(%a) = {@ %a}@]" Id.print r.id (Misc.print_list ~print_sep:Format.fprintf ~sep:",@ " ~print:Term.print) r.vars (Misc.print_list ~print_sep:Format.fprintf ~sep:";@ " ~print:(fun fmt (f, ty) -> Format.fprintf fmt "%a : %a" Id.print f Term.print ty )) r.fields let print_decl fmt = function | Abstract a -> print_abstract fmt a | Record r -> print_record fmt r | Inductive i -> print_inductive fmt i let print_def fmt ({ id; loc = _; vars; params; body; ret_ty = _; } : def) = match vars @ params with | [] -> Format.fprintf fmt "@[<hov 2>def:@ %a =@ %a@]" Id.print id Term.print body | l -> Format.fprintf fmt "@[<hov 2>def:@ %a(%a) =@ %a@]" Id.print id (Misc.print_list ~print_sep:Format.fprintf ~sep:",@ " ~print:Term.print) l Term.print body let print_group print fmt (d: _ group) = let aux = Misc.print_list ~print_sep:Format.fprintf ~sep:"@ " ~print in if d.recursive then Format.fprintf fmt "@[<v 2>rec@ %a@]" aux d.contents else aux fmt d.contents let rec print_descr fmt = function | Pack l -> Format.fprintf fmt "@[<hov 2>pack(%d):@ %a@]" (List.length l) (Misc.print_list ~print_sep:Format.fprintf ~sep:"@ " ~print) l | Pop i -> Format.fprintf fmt "pop: %d" i | Push i -> Format.fprintf fmt "push: %d" i | Reset_assertions -> Format.fprintf fmt "reset assertions" | Plain t -> Format.fprintf fmt "@[<hov 2>plain: %a@]" Term.print t | Prove [] -> Format.fprintf fmt "prove" | Prove l -> Format.fprintf fmt "@[<hov 2>prove-assuming:@ %a@]" (Misc.print_list ~print_sep:Format.fprintf ~sep:" &&@ " ~print:Term.print) l | Clause l -> Format.fprintf fmt "@[<hov 2>clause:@ %a@]" (Misc.print_list ~print_sep:Format.fprintf ~sep:" ||@ " ~print:Term.print) l | Antecedent t -> Format.fprintf fmt "@[<hov 2>antecedent:@ %a@]" Term.print t | Consequent t -> Format.fprintf fmt "@[<hov 2>consequent:@ %a@]" Term.print t | Include f -> Format.fprintf fmt "@[<hov 2>include:@ %s@]" f | Set_logic s -> Format.fprintf fmt "@[<hov 2>set-logic:@ %s@]" s | Get_info s -> Format.fprintf fmt "@[<hov 2>get-info:@ %s@]" s | Set_info t -> Format.fprintf fmt "@[<hov 2>set-info:@ %a@]" Term.print t | Get_option s -> Format.fprintf fmt "@[<hov 2>get-option:@ %s@]" s | Set_option t -> Format.fprintf fmt "@[<hov 2>set-option:@ %a@]" Term.print t | Defs d -> print_group print_def fmt d | Decls d -> print_group print_decl fmt d | Get_proof -> Format.fprintf fmt "get-proof" | Get_unsat_core -> Format.fprintf fmt "get-unsat-core" | Get_unsat_assumptions -> Format.fprintf fmt "get-unsat-assumptions" | Get_model -> Format.fprintf fmt "get-model" | Get_value l -> Format.fprintf fmt "@[<hov 2>get-value(%d):@ %a@]" (List.length l) (Misc.print_list ~print_sep:Format.fprintf ~sep:"@ " ~print:Term.print) l | Get_assignment -> Format.fprintf fmt "get-assignment" | Get_assertions -> Format.fprintf fmt "get-assertions" | Echo s -> Format.fprintf fmt "echo: %s" s | Reset -> Format.fprintf fmt "reset" | Exit -> Format.fprintf fmt "exit" and print_attrs fmt = function | [] -> () | l -> Format.fprintf fmt "@[<hov>{ %a }@]@ " (Format.pp_print_list Term.print) l and print fmt = function { descr; attrs; _ } -> Format.fprintf fmt "%a%a" print_attrs attrs print_descr descr (** Annotations *) let annot = Term.apply (* Internal shortcut. *) let mk ?id ?(loc=Loc.no_loc) ?(attrs=[]) descr = { id; descr; loc; attrs; } (* Pack *) let pack ?id ?loc ?attrs l = mk ?id ?loc ?attrs (Pack l) (* Push/Pop *) let pop ?loc i = mk ?loc (Pop i) let push ?loc i = mk ?loc (Push i) let reset_assertions ?loc () = mk ?loc Reset_assertions (* Assumptions and fact checking *) let prove ?loc () = mk ?loc (Prove []) let mk_clause ?loc ?attrs l = mk ?loc ?attrs (Clause l) let consequent ?loc ?attrs t = mk ?loc ?attrs (Consequent t) let antecedent ?loc ?attrs t = mk ?loc ?attrs (Antecedent t) (* Options statements *) let set_logic ?loc s = mk ?loc (Set_logic s) let get_info ?loc s = mk ?loc (Get_info s) let set_info ?loc t = mk ?loc (Set_info t) let get_option ?loc s = mk ?loc (Get_option s) let set_option ?loc t = mk ?loc (Set_option t) (* Definitions, i.e given identifier, with arguments, is equal to given term *) (* Return values *) let get_proof ?loc () = mk ?loc Get_proof let get_unsat_core ?loc () = mk ?loc Get_unsat_core let get_unsat_assumptions ?loc () = mk ?loc Get_unsat_assumptions let get_model ?loc () = mk ?loc Get_model let get_value ?loc l = mk ?loc (Get_value l) let get_assignment ?loc () = mk ?loc Get_assignment let get_assertions ?loc () = mk ?loc Get_assertions (* Scripts statement *) let echo ?loc s = mk ?loc (Echo s) let reset ?loc () = mk ?loc Reset let exit ?loc () = mk ?loc Exit (* decl/def *) let def ?(loc=no_loc) id ~vars ~params ret_ty body = { id; vars; params; ret_ty; body; loc; } let group ~recursive contents = { recursive; contents; } let abstract ?(loc=no_loc) id ty = Abstract { id; ty; loc; } let record ?(attrs=[]) ?(loc=no_loc) id vars fields = Record { id; vars; fields; loc; attrs; } let inductive ?(attrs=[]) ?(loc=no_loc) id vars cstrs = Inductive { id; vars; cstrs; loc; attrs; } (* grouping of decls/defs *) let mk_decls ?loc ?attrs ~recursive decls = mk ?loc ?attrs (Decls { recursive; contents = decls; }) let group_decls ?loc ?attrs ~recursive l = let decls, others = List.fold_left (fun (decls, others) s -> match s with | { descr = Decls d; _ } -> List.rev_append d.contents decls, others | _ -> decls, s :: others ) ([], []) l in let new_decls = mk_decls ?loc ?attrs ~recursive (List.rev decls) in match others with | [] -> new_decls | l -> pack ?loc (new_decls :: List.rev l) let mk_defs ?loc ?attrs ~recursive defs = mk ?loc ?attrs (Defs { recursive; contents = defs; }) let group_defs ?loc ?attrs ~recursive l = let defs, others = List.fold_left (fun (defs, others) s -> match s with | { descr = Defs d; _ } -> List.rev_append d.contents defs, others | _ -> defs, s :: others ) ([], []) l in let new_defs = mk_defs ?loc ?attrs ~recursive (List.rev defs) in match others with | [] -> new_defs | l -> pack ?loc (new_defs :: List.rev l) (* Alt-ergo wrappers *) let logic ?loc ~ac ids ty = let attrs = if ac then [Term.const ?loc Id.ac_symbol] else [] in let ty = match Term.fv ty with | [] -> ty | vars -> let l = List.map (fun x -> Term.colon ?loc (Term.const ?loc x) (Term.tType ?loc ()) ) vars in Term.pi ?loc l ty in let l = List.map (fun id -> abstract ?loc id ty) ids in mk_decls ?loc ~attrs ~recursive:true l let abstract_type ?loc id vars = let ty = Term.pi ?loc vars (Term.tType ?loc ()) in mk_decls ?loc ~recursive:false [abstract ?loc id ty] let record_type ?loc id vars fields = mk_decls ?loc ~recursive:false [ record ?loc id vars fields] let algebraic_type ?loc id vars cstrs = mk_decls ?loc ~recursive:false [inductive ?loc id vars cstrs] let rec_types ?loc l = group_decls ?loc ~recursive:true l let axiom ?loc id t = mk ~id ?loc (Antecedent t) let case_split ?loc id t = let attrs = [Term.const ?loc Id.case_split] in mk ~id ?loc ~attrs (Antecedent t) let prove_goal ?loc id t = mk ~id ?loc @@ Pack [ mk ~id ?loc (Consequent t); mk (Prove []); ] let rewriting ?loc id l = mk ~id ?loc @@ Pack (List.map (fun t -> antecedent ?loc (Term.add_attr (Term.const Id.rwrt_rule) t) ) l) let theory ?loc id extends l = let attrs = [ Term.colon ?loc (Term.const ?loc Id.theory_decl) (Term.colon ?loc (Term.const ?loc id) (Term.const ?loc extends)) ] in mk ?loc ~attrs (Pack l) (* Dimacs&iCNF wrappers *) let p_cnf ?loc nbvar nbclause = let i = Term.int ?loc (string_of_int nbvar) in let j = Term.int ?loc (string_of_int nbclause) in let attrs = [Term.colon ?loc i j] in mk ?loc ~attrs (Set_logic "dimacs") let p_inccnf ?loc () = mk ?loc (Set_logic "icnf") let clause ?loc l = mk_clause ?loc l let assumption ?loc l = mk ?loc (Prove l) (* Smtlib wrappers *) let check_sat ?loc l = mk ?loc (Prove l) let assert_ ?loc t = antecedent ?loc t let type_decl ?loc id n = let ty = Term.fun_ty ?loc (Misc.replicate n @@ Term.tType ()) @@ Term.tType () in mk_decls ?loc ~recursive:false [abstract ?loc id ty] let fun_decl ?loc id vars l t' = let ty = Term.fun_ty ?loc l t' in let ty = match vars with | [] -> ty | vars -> Term.pi ?loc vars ty in mk_decls ?loc ~recursive:false [abstract ?loc id ty] let type_def ?loc id vars body = let vars = List.map (fun id -> Term.colon (Term.const id) @@ Term.tType ()) vars in let ret_ty = Term.tType ?loc () in mk_defs ?loc ~recursive:false [def ?loc id ~vars ~params:[] ret_ty body] let datatypes ?loc l = let l' = List.map (fun (id, vars, cstrs) -> inductive ?loc id vars cstrs ) l in mk_decls ?loc ~recursive:true l' let fun_def ?loc id vars params ret_ty body = mk_defs ?loc ~recursive:false [ def ?loc id ~vars ~params ret_ty body ] let pred_def ?loc id vars params body = let attrs = [Term.const ?loc Id.predicate_def] in let ret_ty = Term.prop ?loc () in mk_defs ?loc ~attrs ~recursive:false [ def ?loc id ~vars ~params ret_ty body ] let funs_def_rec ?loc l = let contents = List.map (fun (id, vars, params, ret_ty, body) -> def ?loc id ~vars ~params ret_ty body ) l in mk_defs ?loc ~recursive:true contents (* Wrappers for Zf *) let import ?loc s = mk ?loc (Include s) let defs ?loc ?attrs l = group_defs ?loc ?attrs ~recursive:true l let rewrite ?loc ?attrs t = antecedent ?loc ?attrs (Term.add_attr (Term.const Id.rwrt_rule) t) let goal ?loc ?attrs t = mk ?loc ?attrs (Pack [ consequent ?loc t; prove ?loc (); ]) let assume ?loc ?attrs t = antecedent ?loc ?attrs t let lemma ?loc ?attrs t = antecedent ?loc ?attrs t let decl ?loc ?attrs id ty = mk_decls ?loc ?attrs ~recursive:true [abstract ?loc id ty] let definition ?loc ?attrs s ty l = mk ?loc ?attrs (Pack ( decl ?loc s ty :: List.map (assume ?loc) l )) let inductive ?loc ?attrs id vars cstrs = mk_decls ?loc ~recursive:true [inductive ?loc ?attrs id vars cstrs] let data ?loc ?attrs l = (* this is currently only used for mutually recursive datatypes *) group_decls ?loc ?attrs ~recursive:true l (* Wrappers for tptp *) let include_ ?loc s l = let attrs = List.map Term.const l in mk ?loc ~attrs (Include s) let tptp ?loc ?annot kind id role body = let attrs = Term.apply (Term.const Id.tptp_role) [Term.const Id.(mk Attr role)] :: Term.apply (Term.const Id.tptp_kind) [Term.const Id.(mk Attr kind)] :: match annot with | None -> [] | Some t -> [t] in let descr = match role with | "axiom" | "hypothesis" | "definition" | "lemma" | "theorem" | "assumption" | "negated_conjecture" -> begin match body with | `Term t -> Antecedent t | `Clause (_, l) -> Clause l end | "conjecture" -> begin match body with | `Term t -> Consequent t | `Clause _ -> Format.eprintf "WARNING: conjecture in a cnf context"; Pack [] end | "type" -> begin match body with | `Term { Term.term = Term.Colon ({ Term.term = Term.Symbol s; _ }, ty ) ; _ } -> Decls { recursive = false; contents = [abstract ?loc s ty]; } | _ -> Format.eprintf "WARNING: unexpected type declaration@."; Pack [] end | "plain" -> begin match body with | `Term t | `Clause (t, _) -> Plain t end | "unknown" | "fi_domain" | "fi_functors" | "fi_predicates" -> Pack [] | _ -> Format.eprintf "WARNING: unknown tptp formula role: '%s'@." role; Pack [] in mk ~id ?loc ~attrs descr let tpi ?loc ?annot id role t = tptp ?loc ?annot "tpi" id role (`Term t) let thf ?loc ?annot id role t = tptp ?loc ?annot "thf" id role (`Term t) let tff ?loc ?annot id role t = tptp ?loc ?annot "tff" id role (`Term t) let fof ?loc ?annot id role t = tptp ?loc ?annot "fof" id role (`Term t) let cnf ?loc ?annot id role t = let l = match t with | { Term.term = Term.App ({ Term.term = Term.Builtin Term.Or; _ }, l); _ } -> l | _ -> [t] in tptp ?loc ?annot "cnf" id role (`Clause (t, l))
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>