]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/binaries/matitaprover/tptp_cnf.ml
Various architectural changes
[helm.git] / helm / software / components / binaries / matitaprover / tptp_cnf.ml
index ffac7658523f917e298a51b7536a807130f732c7..06f777ff64a51830cd0e7b26462973960f975e3d 100644 (file)
@@ -1,29 +1,32 @@
 
-let trans_atom ~neg = function 
+let trans_atom = function 
   | Ast.True | Ast.False | Ast.Predicate _ | Ast.Proposition _ -> assert false
-  | Ast.Eq _ when neg -> assert false
-  | Ast.Eq (a,b) -> Ast.Function ("==",[Ast.Constant "_"; a; b])
-  | Ast.NotEq (a,b) when neg -> Ast.Function ("==",[Ast.Constant "_"; a; b])
-  | Ast.NotEq _ -> assert false
+  | Ast.Eq (a,b) -> true, Ast.Function ("==",[Ast.Constant "_"; a; b])
+  | Ast.NotEq (a,b) -> false, Ast.Function ("==",[Ast.Constant "_"; a; b])
 ;;
 
-let trans_formulae ~neg = function
-  | Ast.Disjunction _ -> assert false
-  | Ast.Atom a -> trans_atom ~neg a
+let rec trans_formulae (nlit,plit) = function
+  | Ast.Disjunction (a,b) ->
+         trans_formulae (trans_formulae (nlit,plit) b) a
+  | Ast.Atom a ->
+         let is_positive,lit = trans_atom a in
+         if is_positive then (nlit,lit::plit) else (lit::nlit,plit)
   | Ast.NegAtom _ -> assert false
 ;;
 
+let trans_formulae = trans_formulae ([],[]);;
+
 
 (* HELPERS *)
 let resolve ~tptppath s = 
   let resolved_name = 
+    if HExtlib.is_regular s then s else
     if tptppath = "/" then s else
-      if Filename.check_suffix s ".p" then
-        (assert (String.length s > 5);
-        let prefix = String.sub s 0 3 in
-        tptppath ^ "/Problems/" ^ prefix ^ "/" ^ s)
-      else
-        tptppath ^ "/" ^ s
+    if Filename.check_suffix s ".p" then
+     (assert (String.length s > 5);
+     let prefix = String.sub s 0 3 in
+     tptppath ^ "/Problems/" ^ prefix ^ "/" ^ s)
+    else tptppath ^ "/" ^ s
   in
   if HExtlib.is_regular resolved_name then
     resolved_name
@@ -50,11 +53,11 @@ let parse ~tptppath filename =
     let rec aux p n = function
       | [] -> p,n
       | Ast.Comment _ :: tl -> aux p n tl
-      | Ast.AnnotatedFormula (name, (Ast.Axiom | Ast.Hypothesis), f,_,_) :: tl->
-          aux (p@[Ast.Constant name,trans_formulae ~neg:false f]) n tl
-      | Ast.AnnotatedFormula (name, Ast.Negated_conjecture, f,_,_) :: tl ->
-          assert (n = []);
-          aux p (n@[Ast.Constant name, trans_formulae ~neg:true f]) tl
+      | Ast.AnnotatedFormula (name, 
+          (Ast.Axiom | Ast.Hypothesis|Ast.Negated_conjecture), f,_,_) :: tl->
+          let (nlit,plit) = trans_formulae f in
+             if plit = [] then aux p (n@[Ast.Constant name,(nlit,plit)]) tl
+             else aux (p@[Ast.Constant name,(nlit,plit)]) n tl
       | _ -> prerr_endline "bad syntax"; assert false
     in
       aux [] [] statements