]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/binaries/matitaprover/matitaprover.ml
timeouts are passed as arguments, so that tptpprover can
[helm.git] / helm / software / components / binaries / matitaprover / matitaprover.ml
1 (*
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.                     
5     ||I||                                                                
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_______________________________________________________________ *)
11
12 (* $Id: orderings.ml 9869 2009-06-11 22:52:38Z denes $ *)
13
14 module OT = struct type t = string  let compare = Pervasives.compare end 
15 module HC = Map.Make(OT)
16
17 type leaf = int * string
18
19 let cache = ref HC.empty 
20 let num = ref 100
21
22 let hash s = 
23   try HC.find s !cache
24   with Not_found ->
25           cache := HC.add s (!num,s) !cache;
26           decr num;
27           HC.find s !cache
28 ;;
29
30 hash "==";;
31 hash "_";;
32
33 let problem_file = ref "no-file-given";;
34 let tptppath = ref "./";;
35 let seconds = ref 300;;
36
37 let fail_msg () =
38       print_endline ("% SZS status Timeout for " ^ 
39         Filename.basename !problem_file)
40 ;;
41
42 let main () =
43   let _ =
44     Sys.signal 24 (Sys.Signal_handle (fun _ -> fail_msg (); exit 1)) in
45   let _ =
46     Sys.signal Sys.sigalrm 
47       (Sys.Signal_handle (fun _ -> fail_msg (); exit 1)) in
48   Arg.parse [
49    "--tptppath", Arg.String (fun p -> tptppath := p), 
50      ("[path]  TPTP lib root, default " ^ !tptppath);
51    "--timeout", Arg.Int (fun p -> seconds := p), 
52      ("[seconds]  timeout, default " ^ string_of_int !seconds);
53    ] (fun x -> problem_file := x) "matitaprover [problemfile]";
54   let hypotheses, goals = Tptp_cnf.parse ~tptppath:!tptppath !problem_file in
55   let goal = match goals with [x] -> x | _ -> assert false in
56   let module B : Terms.Blob with type t = leaf and type input = Ast.term = struct
57         type t = leaf
58         let eq a b = a == b
59         let compare (a,_) (b,_) = Pervasives.compare a b
60         let eqP = hash "=="
61         let pp (_,a) =  a 
62         type input = Ast.term
63         let rec embed m = function
64             | Ast.Variable name ->
65                 (try m, List.assoc name m
66                  with Not_found -> 
67                     let t = Terms.Var ~-(List.length m) in
68                     (name,t)::m, t)
69             | Ast.Constant name -> m, Terms.Leaf (hash name)
70             | Ast.Function (name,args) -> 
71                 let m, args = 
72                   HExtlib.list_mapi_acc 
73                     (fun x _ m -> embed m x) m args
74                 in
75                 m, Terms.Node (Terms.Leaf (hash name):: args) 
76         ;;
77         let saturate bo ty = 
78           let vars, ty = embed [] ty in
79           let _, bo = embed vars bo in
80           let bo = Terms.Node (bo :: List.map snd (List.rev vars)) in
81           bo, ty
82         ;;
83         let embed t = snd(embed [] t);;
84
85   end
86   in
87   let module P = Paramod.Paramod(B) in
88   let module Pp = Pp.Pp(B) in
89   let bag = Terms.M.empty, 0 in
90   let bag, g_passives = P.mk_goal bag goal in
91   let bag, passives = 
92     HExtlib.list_mapi_acc (fun x _ b -> P.mk_passive b x) bag hypotheses 
93   in
94   prerr_endline "Order";
95   HC.iter 
96     (fun _ (w,x) -> prerr_endline (" " ^ x ^ " is " ^ string_of_int w)) !cache;
97   prerr_endline "Facts";
98   List.iter (fun x -> prerr_endline (" " ^ Pp.pp_unit_clause x)) passives;
99   prerr_endline "Goal";
100   prerr_endline (" " ^ Pp.pp_unit_clause g_passives);
101   let _ = Unix.alarm !seconds in
102   match P.paramod ~max_steps:max_int bag ~g_passives:[g_passives] ~passives with
103   | [] -> fail_msg ()
104   | (bag,_,l)::_ ->
105       print_endline ("% SZS status Unsatisfiable for " ^ 
106         Filename.basename !problem_file);
107       print_endline ("% SZS output start CNFRefutation for " ^ 
108         Filename.basename !problem_file);
109       flush stdout;
110       List.iter (fun x ->
111         print_endline (Pp.pp_unit_clause ~margin:max_int 
112           (fst(Terms.M.find x bag)))) l;
113       print_endline ("% SZS output end CNFRefutation for " ^ 
114         Filename.basename !problem_file);
115 ;;
116
117 main ()