X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fbinaries%2Ftptp2grafite%2Fmain.ml;h=18fa713a9a05b1f48b71ae81528652018ce28453;hb=551b90466538e44c85b2f739e47b89140c0bce67;hp=0ecee127eb2d623c6d2d78a940c608abb3e334cd;hpb=372dd23aa25ac67965f5427f7b56aa7d1f465138;p=helm.git diff --git a/helm/software/components/binaries/tptp2grafite/main.ml b/helm/software/components/binaries/tptp2grafite/main.ml index 0ecee127e..18fa713a9 100644 --- a/helm/software/components/binaries/tptp2grafite/main.ml +++ b/helm/software/components/binaries/tptp2grafite/main.ml @@ -1,6 +1,17 @@ module GA = GrafiteAst;; +module LA = LexiconAst;; 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] @@ -25,7 +36,7 @@ let collect_arities_from_atom a = | A.Eq (t1,t2) -> collect_arities_from_term t1 @ collect_arities_from_term t2 | A.NotEq (t1,t2) -> collect_arities_from_term t1 @ collect_arities_from_term t2 in - HExtlib.list_uniq (List.sort (fun (a,_) (b,_) -> compare a b) (aux a)) + aux a ;; let collect_fv_from_atom a = @@ -40,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 @@ -54,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.Variable (PT.FreshVar "_")),Some (PT.Ident (component,None))), + ((mk_ident "_"),Some (mk_ident component)), mk_arrow component (n-1)) ;; @@ -68,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 @@ -77,17 +94,24 @@ 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) ;; +let collect_arities atom ctx = + let atoms = atom::(List.map atom_of_formula ctx) in + HExtlib.list_uniq (List.sort (fun (a,_) (b,_) -> compare a b) + (List.flatten (List.map collect_arities_from_atom atoms))) +;; + let rec convert_formula no_arities context f = let atom = atom_of_formula f in let t = convert_atom atom in @@ -96,43 +120,53 @@ 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 - let arities = if no_arities then [] else collect_arities_from_atom atom in + let arities = if no_arities then [] else collect_arities atom context in build_ctx_for_arities arities (build_ctx 0 context) ;; let convert_ast statements context = function | A.Comment s -> let s = String.sub s 1 (String.length s - 1) in - if s.[String.length s - 1] = '\n' then - s.[String.length s - 1] <- '\000'; - statements @ [GA.Comment (HExtlib.dummy_floc,GA.Note (HExtlib.dummy_floc,s))], + let s = + if s.[String.length s - 1] = '\n' then + String.sub s 0 (String.length s - 1) + else + s + in + statements @ [GA.Comment (floc,GA.Note (floc,s))], context | A.Inclusion (s,_) -> statements @ [ GA.Comment ( - HExtlib.dummy_floc, GA.Note ( - HExtlib.dummy_floc,"Inclusion of: " ^ s))], context + floc, GA.Note ( + floc,"Inclusion of: " ^ s))], context | A.AnnotatedFormula (name,kind,f,_,_) -> match kind with | A.Axiom | 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( - HExtlib.dummy_floc,GA.Command( - HExtlib.dummy_floc,GA.Obj(HExtlib.dummy_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 @@ -203,11 +237,21 @@ 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 (GrafiteAstPp.pp_statement ~term_pp ~lazy_term_pp ~obj_pp t) in + let extra_statements_start = [ + GA.Executable(floc,GA.Command(floc, + GA.Set(floc,"baseuri","cic:/matita/TPTP/" ^ !inputfile))); + GA.Executable(floc,GA.Command(floc, GA.Include(floc,"legacy/coq.ma")))] + 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; exit 0