Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file callProver.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250(* This file is free software, part of Logtk. See file "license" for more details. *)(** {1 Call external provers with TSTP} *)openLogtkmoduleA=Ast_tptpmoduleTT=Trace_tstpmoduleErr=CCResultmoduleST=STermtype'aor_error=('a,string)CCResult.ttypeuntyped=STerm.t(** {2 Description of provers} *)moduleProver=structtypet={name:string;(** name of the prover *)command:string;(** command to call prover*)unsat:stringlist;(** prover returned unsat *)sat:stringlist;(** prover returned sat *)}(** data useful to invoke a prover. The prover must read from
stdin. The command is interpolated using {! Buffer.add_substitude}, with
the given patterns:
- "timeout" is the timeout in seconds *)let__table:(string,t)Hashtbl.t=Hashtbl.create5letlookupname=Hashtbl.find__tablenameletlist_provers()=Hashtbl.fold(funn_acc->n::acc)__table[]letregisternameprover=ifHashtbl.mem__tablenametheninvalid_arg("prover already registered: "^name)elseHashtbl.add__tablenameproverletp_E={name="E";command="eprover --cpu-limit=${timeout} --auto -l0 --tstp-in --tstp-out";unsat=["SZS status Unsat";"SZS status Theorem"];sat=["SZS status Satisfiable";"SZS status CounterTheorem"];}letp_Eproof={p_Ewithname="Eproof";command="eproof_ram --cpu-limit=${timeout} -tAuto -xAuto -l0 --tstp-in --tstp-out";}letp_SPASS={name="SPASS";command="SPASS -TPTP -TimeLimit=${timeout} -Stdin";unsat=["Proof found"];sat=["Completion found"];}letp_Zenon={name="Zenon";command="zenon -itptp -p0 -max-time ${timeout}s -";unsat=["PROOF-FOUND"];sat=["NO-PROOF"];}letdefault=[p_E;p_SPASS]endletnamep=p.Prover.name(** {2 Run provers} *)typeresult=|Unsat|Sat|Unknown|Errorofstring(* among the strings in [patterns], find if one is a substring of [s] *)let_find_mempatternss=List.exists(funp->CCString.find~sub:ps>=0)patternsletcall_with_out?(timeout=30)?(args=[])~proverdecls=(* compute input to give to the prover *)letinput=CCFormat.sprintf"@[<v>%a@]"(Util.pp_list~sep:""(A.ppST.pp))declsin(* build command (add arguments to the end) *)letbuf=Buffer.create15inBuffer.add_substitutebuf(function|"timeout"->string_of_inttimeout|s->s)prover.Prover.command;List.iter(funarg->Buffer.add_charbuf' ';Buffer.add_stringbufarg)args;letcmd=Buffer.contentsbufinUtil.debugf2"run prover %s"(funk->kprover.Prover.name);Util.debugf4"command is: \"%s\""(funk->kcmd);Util.debugf4"obligation is: \"%s\""(funk->kinput);Err.((* run the prover *)Util.popen~cmd~input>>=funoutput->Util.debugf2"prover %s done"(funk->kprover.Prover.name);Util.debugf4"output: \"%s\""(funk->koutput);(* parse output *)letresult=if_find_memprover.Prover.unsatoutputthenUnsatelseif_find_memprover.Prover.satoutputthenSatelseUnknowninErr.return(result,output))letcall?timeout?args~proverdecls=Err.(call_with_out?timeout?args~proverdecls>>=fun(res,_)->returnres)letdecls_of_string~sourcestr=letlexbuf=Lexing.from_stringstrinParseLocation.set_filelexbufsource;Util_tptp.parse_lexbuflexbuf(* try to parse a proof. Returns a proof option *)letproof_of_declsdecls=letres=Trace_tstp.of_declsdeclsinmatchreswith|Err.Error_->None|Err.Okproof->Someproofletcall_proof?timeout?args~proverdecls=Err.(call_with_out?timeout?args~proverdecls>>=fun(res,output)->decls_of_string~source:("output of prover "^prover.Prover.name)output>>=Trace_tstp.of_decls>>=funproof->return(res,proof))moduleEprover=structtyperesult={answer:szs_answer;output:string;decls:untypedAst_tptp.tIter.toption;proof:Trace_tstp.toption;}andszs_answer=|Theorem|CounterSatisfiable|Unknownletstring_of_answer=function|Theorem->"Theorem"|CounterSatisfiable->"CounterSatisfiable"|Unknown->"Unknown"(* parse SZS answer *)letparse_answeroutput=ifCCString.mem~sub:"SZS status Theorem"outputthenTheoremelseifCCString.mem~sub:"SZS status CounterSatisfiable"outputthenCounterSatisfiableelseUnknown(* run eproof_ram on the given input. returns a result *)let_run_either?(opts=[])?(level=1)~prover~steps~input()=letlevel'=Printf.sprintf"-l%d"levelinletcommand=[prover;"--tstp-in";"--tstp-out";level';"-C";string_of_intsteps;"-xAuto";"-tAuto"]@optsinletcmd=String.concat" "commandinErr.(Util.popen~cmd~input>>=funoutput->(* parse answer *)letanswer=parse_answeroutputin(* read its output *)letdecls,proof=matchdecls_of_string~source:"E"outputwith|Err.Error_->None,None|Err.Oks->(* try to parse proof, if it's a theorem *)letproof=ifanswer=Theoremthenproof_of_declsselseNoneinSomes,proofinErr.return{answer;output;decls;proof})(* run eproof_ram on the given input. returns a result *)letrun_eproof~steps~input=_run_either~prover:"eproof_ram"~steps~input()(* run eprover on the given input. returns a result Lwt *)letrun_eprover?opts?level~steps~input()=_run_either~prover:"eprover"?opts?level~steps~input()(* explore the surrounding of this list of formulas, returning a
list of terms (clausal form) *)letdiscover?(opts=[])~stepsdecls=letcommand=["eprover";"--tstp-in";"--tstp-out";"-S";"--restrict-literal-comparisons";"-C";string_of_intsteps]@optsinletcmd=String.concat" "commandin(* build stdin *)letinput=CCFormat.sprintf"@[%a@]"(Util.pp_iter~sep:""(A.ppST.pp))declsinErr.((* call E *)Util.popen~cmd~input>>=funoutput->(* read its output *)decls_of_string~source:"E"output)letcnf?(opts=[])decls=letcommand=["eprover";"--tstp-in";"--tstp-out";"--cnf"]@optsinletcmd=String.concat" "commandin(* build stdin *)letinput=CCFormat.sprintf"@[%a@]"(Util.pp_iter~sep:""(A.ppST.pp))declsinErr.((* call E *)Util.popen~cmd~input>>=funoutput->(* read its output *)decls_of_string~source:"E"output)end