]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/binaries/tptp2grafite/main.ml
- metas_of_term moved to cicUtil
[helm.git] / helm / software / components / binaries / tptp2grafite / main.ml
index cbdddf851c9d2a9233e68f5c9465429ffd01c0a9..18fa713a9a05b1f48b71ae81528652018ce28453 100644 (file)
@@ -4,6 +4,15 @@ module PT = CicNotationPt;;
 module A = Ast;;
 let floc = HExtlib.dummy_floc;;
 
+let kw = [
+ "and","myand"
+];;
+
+let mk_ident s =
+  PT.Ident ((try List.assoc s kw with Not_found -> s),None)
+;;
+
+
 let rec collect_arities_from_term = function
   | A.Constant name -> [name,0]
   | A.Variable name -> []
@@ -42,11 +51,17 @@ let collect_fv_from_atom a =
   HExtlib.list_uniq (List.sort compare (aux a))
 ;;  
 
+let collect_fv_from_formulae = function
+  | A.Disjunction _ -> assert false
+  | A.NegAtom a 
+  | A.Atom a -> collect_fv_from_atom a
+;;
+
 let rec convert_term = function
-  | A.Variable x -> PT.Ident (x,None)
-  | A.Constant x -> PT.Ident (x,None)
+  | A.Variable x -> mk_ident x
+  | A.Constant x -> mk_ident x
   | A.Function (name, args) -> 
-      PT.Appl (PT.Ident (name,None) :: List.map convert_term args)
+      PT.Appl (mk_ident name :: List.map convert_term args)
 ;;
 
 let atom_of_formula = function
@@ -56,11 +71,11 @@ let atom_of_formula = function
 ;;
   
 let rec mk_arrow component = function
-  | 0 -> PT.Ident (component,None)
+  | 0 -> mk_ident component
   | n -> 
       PT.Binder 
         (`Forall,
-          ((PT.Ident ("_",None)),Some (PT.Ident (component,None))),
+          ((mk_ident "_"),Some (mk_ident component)),
           mk_arrow component (n-1))
 ;;
 
@@ -70,7 +85,7 @@ let build_ctx_for_arities arities t =
     | (name,nargs)::tl ->
         PT.Binder 
           (`Forall,
-            (PT.Ident (name,None),Some (mk_arrow "A" nargs)),
+            (mk_ident name,Some (mk_arrow "A" nargs)),
             aux tl)
   in
   aux arities
@@ -79,13 +94,14 @@ let build_ctx_for_arities arities t =
 let convert_atom a = 
   let aux = function
   | A.Proposition _ -> assert false
-  | A.Predicate (name,params) -> assert false
-  | A.True -> PT.Ident ("True",None)
-  | A.False -> PT.Ident ("False",None)
+  | A.Predicate (name,params) -> 
+      prerr_endline ("Predicate is unsupported: " ^ name);
+      assert false
+  | A.True -> mk_ident "True"
+  | A.False -> mk_ident "False"
   | A.Eq (l,r) 
   | A.NotEq (l,r) -> (* removes the negation *)
-      PT.Appl [
-        PT.Ident ("eq",None); PT.Ident ("A",None); convert_term l; convert_term r]
+      PT.Appl [mk_ident "eq";mk_ident "A";convert_term l;convert_term r]
   in
   build_ctx_for_arities (List.map (fun x -> (x,0)) (collect_fv_from_atom a)) (aux a)
 ;;
@@ -104,7 +120,7 @@ let rec convert_formula no_arities context f =
     | hp::tl -> 
         PT.Binder 
           (`Forall,
-            (PT.Ident ("H" ^ string_of_int n,None), 
+            (mk_ident ("H" ^ string_of_int n), 
                        Some (convert_formula true [] hp)), 
             build_ctx (n+1) tl)
   in
@@ -134,17 +150,23 @@ let convert_ast statements context = function
       | A.Hypothesis ->
           statements, f::context
       | A.Negated_conjecture ->
+          if collect_fv_from_formulae f <> [] then
+            prerr_endline "CONTIENE FV";
           let f = 
             PT.Binder 
              (`Forall,
-               (PT.Ident ("A",None),Some (PT.Sort `Set)), 
+               (mk_ident "A",Some (PT.Sort `Set)), 
                convert_formula false context f)
           in
           let o = PT.Theorem (`Theorem,name,f,None) in
           statements @ [
-            GA.Executable(
-              floc,GA.Command(
-                floc,GA.Obj(floc,o)))],
+            GA.Executable(floc,GA.Command(floc,GA.Obj(floc,o)));
+            GA.Executable(floc,GA.Tactical(floc, GA.Tactic(floc,
+              GA.Intros (floc,None,[])),Some (GA.Dot(floc))));
+            GA.Executable(floc,GA.Tactical(floc, GA.Tactic(floc,
+              GA.Auto (floc,None,None,Some "paramodulation",None)),
+                Some (GA.Dot(floc))));
+            GA.Executable(floc,GA.Command(floc, GA.Qed(floc)))],
           context
       | A.Definition 
       | A.Lemma 
@@ -215,7 +237,7 @@ let _ =
   in
   let pp t = 
     (* for a correct pp we should disambiguate the term... *)
-    let term_pp = CicNotationPp.pp_term in 
+    let term_pp = CicNotationPp.pp_term in
     let lazy_term_pp = fun x -> assert false in
     let obj_pp = CicNotationPp.pp_obj in
     print_endline 
@@ -226,19 +248,10 @@ let _ =
       GA.Set(floc,"baseuri","cic:/matita/TPTP/" ^ !inputfile)));
     GA.Executable(floc,GA.Command(floc, GA.Include(floc,"legacy/coq.ma")))]
   in
-  let extra_statements_end = [
-    GA.Executable(floc,GA.Tactical(floc, GA.Tactic(floc,
-      GA.Intros (floc,None,[])),Some (GA.Dot(floc))));
-    GA.Executable(floc,GA.Tactical(floc, GA.Tactic(floc,
-      GA.Auto (floc,None,None,Some "paramodulation",None)),
-      Some (GA.Dot(floc))));
-    GA.Executable(floc,GA.Command(floc, GA.Qed(floc)))]
-  in 
   List.iter pp extra_statements_start;
   print_endline
     (LexiconAstPp.pp_command 
       (LA.Alias(floc,
         LA.Ident_alias("eq","cic:/Coq/Init/Logic/eq.ind#xpointer(1/1)"))) ^ ".");
   List.iter pp grafite_ast_statements;
-  List.iter pp extra_statements_end;
   exit 0