2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
12 (* $Id: orderings.ml 9869 2009-06-11 22:52:38Z denes $ *)
14 module OT = struct type t = string let compare = Pervasives.compare end
15 module HC = Map.Make(OT)
17 type leaf = int * string
19 let cache = ref HC.empty
25 cache := HC.add s (!num,s) !cache;
33 let problem_file = ref "no-file-given";;
34 let tptppath = ref "/";;
35 let seconds = ref 300;;
38 print_endline ("% SZS status Timeout for " ^
39 Filename.basename !problem_file)
42 module type LeafComparer =
44 val cmp : leaf -> leaf -> int
48 module MakeBlob(C:LeafComparer) : Terms.Blob
49 with type t = leaf and type input = Ast.term = struct
52 let compare a b = C.cmp a b
56 let rec embed m = function
57 | Ast.Variable name ->
58 (try m, List.assoc name m
60 let t = Terms.Var ~-(List.length m) in
62 | Ast.Constant name -> m, Terms.Leaf (hash name)
63 | Ast.Function (name,args) ->
66 (fun x _ m -> embed m x) m args
68 m, Terms.Node (Terms.Leaf (hash name):: args)
71 let vars, ty = embed [] ty in
72 let _, bo = embed vars bo in
73 let bo = Terms.Node (bo :: List.map snd (List.rev vars)) in
76 let embed t = snd(embed [] t);;
81 let success_msg bag l (pp : ?margin:int -> leaf Terms.unit_clause -> string) =
82 print_endline ("% SZS status Unsatisfiable for " ^
83 Filename.basename !problem_file);
84 print_endline ("% SZS output start CNFRefutation for " ^
85 Filename.basename !problem_file);
88 let (cl,_,_) = Terms.get_from_bag x bag in
89 print_endline (pp ~margin:max_int
91 print_endline ("% SZS output end CNFRefutation for " ^
92 Filename.basename !problem_file)
95 let start_msg passives g_passives (pp : leaf Terms.unit_clause -> string) =
96 let prefix = string_of_int (Unix.getpid ()) in
97 let prerr_endline s = prerr_endline (prefix ^ ": " ^ s) in
98 prerr_endline "Facts:";
99 List.iter (fun x -> prerr_endline (" " ^ pp x)) passives;
100 prerr_endline "Goal:";
101 prerr_endline (" " ^ pp g_passives);
102 prerr_endline "Order:";
103 prerr_endline " ...fixme...";
104 prerr_endline "Strategy:";
105 prerr_endline " ...fixme...";
108 let report_error s = prerr_endline (string_of_int (Unix.getpid())^": "^s);;
110 module Main(C:LeafComparer) = struct
111 let main goal hypotheses =
112 let module B = MakeBlob(C) in
113 let module Pp = Pp.Pp(B) in
114 let module P = Paramod.Paramod(B) in
115 let bag = Terms.empty_bag, 0 in
116 let bag, g_passives = P.mk_goal bag goal in
118 HExtlib.list_mapi_acc (fun x _ b -> P.mk_passive b x) bag hypotheses
120 start_msg passives g_passives Pp.pp_unit_clause;
123 ~max_steps:max_int bag ~g_passives:[g_passives] ~passives
125 | P.Error s -> report_error s; 3
126 | P.Unsatisfiable ((bag,_,l)::_) ->
127 success_msg bag l Pp.pp_unit_clause; 0
128 | P.Unsatisfiable ([]) ->
129 report_error "Unsatisfiable but no solution output"; 3
136 let print_endline s = prerr_endline (string_of_int p ^ ": " ^ s) in
139 print_endline ("status Unsatisfiable for " ^
140 Filename.basename !problem_file);
142 print_endline ("status Timeout for " ^
143 Filename.basename !problem_file);
145 print_endline ("status GaveUp for " ^
146 Filename.basename !problem_file);
148 print_endline ("status Error for " ^
149 Filename.basename !problem_file);
150 | Unix.WEXITED _ -> assert false
151 | Unix.WSIGNALED s -> print_endline ("killed by signal " ^ string_of_int s)
152 | Unix.WSTOPPED _ -> print_endline "stopped"
156 List.iter (fun pid -> try Unix.kill pid 9 with _ -> ()) l
160 let childs = ref [] in
162 Sys.signal 24 (Sys.Signal_handle
163 (fun _ -> fail_msg (); killall !childs; exit 1))
166 Sys.signal Sys.sigalrm
167 (Sys.Signal_handle (fun _ -> fail_msg (); killall !childs; exit 1))
170 "--tptppath", Arg.String (fun p -> tptppath := p),
171 ("[path] TPTP lib root, default " ^ !tptppath);
172 "--timeout", Arg.Int (fun p -> seconds := p),
173 ("[seconds] timeout, default " ^ string_of_int !seconds);
174 ] (fun x -> problem_file := x) "
175 Matitaprover is the first order automatic prover that equips the
176 Matita interactive theorem prover (http://matita.cs.unibo.it).
178 Developed by A.Asperti, M.Denes and E.Tassi, released under GPL-2.1
180 If --tptppath is given, instead of the problem file you can just give the
181 problem name with the .p suffix (e.g. BOO001-1.p)
183 If --tptppath is not given, included files (i.e. axiom sets) are searched
184 in the current directory only.
186 usage: matitaprover [options] problemfile";
187 let hypotheses, goals = Tptp_cnf.parse ~tptppath:!tptppath !problem_file in
188 let goal = match goals with [x] -> x | _ -> assert false in
189 let _ = Unix.alarm !seconds in
193 let pid = Unix.fork () in
194 if pid = 0 then (exit (f ())) else pid)
197 let module M = Main(struct let cmp (a,_) (b,_) = compare a b end) in
198 M.main goal hypotheses)
201 let module M = Main(struct let cmp (a,_) (b,_) = compare b a end) in
202 M.main goal hypotheses)
205 if List.length !childs = 0 then
206 (fail_msg (); exit 1)
208 match Unix.wait () with
209 | p, (Unix.WEXITED 0 as s) ->
211 killall !childs; exit 0;
214 childs := List.filter ((<>)p) !childs; aux ()