]> matita.cs.unibo.it Git - helm.git/blob - helm/software/components/binaries/matitaprover/matitaprover.ml
...
[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) "
54 Matitaprover is the first order automatic prover that equips the 
55 Matita interactive theorem prover (http://matita.cs.unibo.it).
56
57 Developed by A.Asperti, M.Denes and E.Tassi, released under GPL-2.1
58
59 If --tptppath is given, instead of the problem file you can just give the 
60 problem name with the .p suffix (e.g. BOO001-1.p)
61
62 If --tptppath is not given, included files (i.e. axiom sets) are searched 
63 in the current directory only.
64
65 usage: matitaprover [options] problemfile";
66   let hypotheses, goals = Tptp_cnf.parse ~tptppath:!tptppath !problem_file in
67   let goal = match goals with [x] -> x | _ -> assert false in
68   let module B : Terms.Blob 
69   with type t = leaf and type input = Ast.term = struct
70         type t = leaf
71         let eq a b = a == b
72         let compare (a,_) (b,_) = Pervasives.compare a b
73         let eqP = hash "=="
74         let pp (_,a) =  a 
75         type input = Ast.term
76         let rec embed m = function
77             | Ast.Variable name ->
78                 (try m, List.assoc name m
79                  with Not_found -> 
80                     let t = Terms.Var ~-(List.length m) in
81                     (name,t)::m, t)
82             | Ast.Constant name -> m, Terms.Leaf (hash name)
83             | Ast.Function (name,args) -> 
84                 let m, args = 
85                   HExtlib.list_mapi_acc 
86                     (fun x _ m -> embed m x) m args
87                 in
88                 m, Terms.Node (Terms.Leaf (hash name):: args) 
89         ;;
90         let saturate bo ty = 
91           let vars, ty = embed [] ty in
92           let _, bo = embed vars bo in
93           let bo = Terms.Node (bo :: List.map snd (List.rev vars)) in
94           bo, ty
95         ;;
96         let embed t = snd(embed [] t);;
97
98   end
99   in
100   let module P = Paramod.Paramod(B) in
101   let module Pp = Pp.Pp(B) in
102   let bag = Terms.M.empty, 0 in
103   let bag, g_passives = P.mk_goal bag goal in
104   let bag, passives = 
105     HExtlib.list_mapi_acc (fun x _ b -> P.mk_passive b x) bag hypotheses 
106   in
107   prerr_endline "Order";
108   HC.iter 
109     (fun _ (w,x) -> prerr_endline (" " ^ x ^ " is " ^ string_of_int w)) !cache;
110   prerr_endline "Facts";
111   List.iter (fun x -> prerr_endline (" " ^ Pp.pp_unit_clause x)) passives;
112   prerr_endline "Goal";
113   prerr_endline (" " ^ Pp.pp_unit_clause g_passives);
114   let _ = Unix.alarm !seconds in
115   match P.paramod ~max_steps:max_int bag ~g_passives:[g_passives] ~passives with
116   | [] -> fail_msg ()
117   | (bag,_,l)::_ ->
118       print_endline ("% SZS status Unsatisfiable for " ^ 
119         Filename.basename !problem_file);
120       print_endline ("% SZS output start CNFRefutation for " ^ 
121         Filename.basename !problem_file);
122       flush stdout;
123       List.iter (fun x ->
124         print_endline (Pp.pp_unit_clause ~margin:max_int 
125           (fst(Terms.M.find x bag)))) l;
126       print_endline ("% SZS output end CNFRefutation for " ^ 
127         Filename.basename !problem_file);
128 ;;
129
130 main ()