X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fbinaries%2Ftptp2grafite%2Fmain.ml;h=871ff7b56a6299f0a497f913dfed177e9b978f68;hb=5f53c5415d0bde33509eb53db7ef230819266420;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..871ff7b56 100644 --- a/helm/software/components/binaries/tptp2grafite/main.ml +++ b/helm/software/components/binaries/tptp2grafite/main.ml @@ -1,12 +1,24 @@ module GA = GrafiteAst;; +module LA = LexiconAst;; module PT = CicNotationPt;; module A = Ast;; +let floc = HExtlib.dummy_floc;; + +let universe = "Univ" ;; + +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 -> [] | A.Function (name,l) -> - (name,List.length l) :: List.flatten (List.map collect_arities_from_term l) + (name,List.length l)::List.flatten (List.map collect_arities_from_term l) ;; let rec collect_fv_from_term = function @@ -25,7 +37,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 +52,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,85 +72,149 @@ 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)) ;; -let build_ctx_for_arities arities t = +let build_ctx_for_arities univesally arities t = + let binder = if univesally then `Forall else `Exists in let rec aux = function | [] -> t | (name,nargs)::tl -> PT.Binder - (`Forall, - (PT.Ident (name,None),Some (mk_arrow "A" nargs)), + (binder, + (mk_ident name,Some (mk_arrow universe nargs)), aux tl) in aux arities ;; -let convert_atom a = +let convert_atom universally 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.Eq (l,r) + | 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 universe;convert_term l;convert_term r] in - build_ctx_for_arities (List.map (fun x -> (x,0)) (collect_fv_from_atom a)) (aux a) + build_ctx_for_arities universally + (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 assert_formulae_is_1eq_negated f = let atom = atom_of_formula f in - let t = convert_atom atom in + match atom with + | A.Eq (l,r) -> failwith "Negated formula is not negated" + | A.NotEq (l,r) -> () + | _ -> failwith "Not a unit equality formula" +;; + +let rec convert_formula fv no_arities context f = + let atom = atom_of_formula f in + let t = convert_atom (fv = []) atom in let rec build_ctx n = function | [] -> t | hp::tl -> PT.Binder (`Forall, - (PT.Ident ("H" ^ string_of_int n,None), - Some (convert_formula true [] hp)), + (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 - build_ctx_for_arities arities (build_ctx 0 context) + let arities = if no_arities then [] else collect_arities atom context in + build_ctx_for_arities true arities (build_ctx 0 context) +;; + +let check_if_atom_is_negative = function + | A.True | A.False | A.Proposition _ | A.Predicate _ -> assert false + | A.Eq _ -> false + | A.NotEq _ -> true +;; + +let check_if_formula_is_negative = function + | A.Disjunction _ -> assert false + | A.NegAtom a -> not (check_if_atom_is_negative a) + | A.Atom a -> check_if_atom_is_negative a ;; 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 when not (check_if_formula_is_negative f) -> + statements, f::context | A.Negated_conjecture -> + assert_formulae_is_1eq_negated f; + let fv = collect_fv_from_formulae f in + if fv <> [] then + prerr_endline ("FREE VARIABLES: " ^ String.concat "," fv); let f = PT.Binder (`Forall, - (PT.Ident ("A",None),Some (PT.Sort `Set)), - convert_formula false context f) + (mk_ident universe,Some (PT.Sort `Set)), + convert_formula fv 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))))] @ + (if fv <> [] then + (List.flatten + (List.map + (fun _ -> + [GA.Executable(floc,GA.Tactical(floc, GA.Tactic(floc, + GA.Exists floc),Some (GA.Branch floc))); + GA.Executable(floc,GA.Tactical(floc, + GA.Pos (floc,[2]),None))]) + fv)) + else [])@ + [GA.Executable(floc,GA.Tactical(floc, GA.Tactic(floc, + GA.Auto (floc,None,None,Some "paramodulation",None)), + Some (GA.Dot(floc))))]@ + (if fv <> [] then + (List.flatten + (List.map + (fun _ -> + [GA.Executable(floc,GA.Tactical(floc, GA.Shift floc, None)); + GA.Executable(floc,GA.Tactical(floc, GA.Skip floc,Some + (GA.Merge floc)))]) + fv)) + else [])@ + [GA.Executable(floc,GA.Tactical(floc, GA.Try(floc, + GA.Tactic (floc, GA.Assumption floc)), Some (GA.Dot(floc)))); + GA.Executable(floc,GA.Command(floc, GA.Qed(floc)))], context | A.Definition | A.Lemma @@ -202,12 +284,41 @@ let _ = ([],[]) statements in let pp t = - (* for a correct pp we should disambiguate the term... *) - let term_pp = CicNotationPp.pp_term in + (* ZACK: setting width to 80 will trigger a bug of BoxPp.render_to_string + * which will show up using the following command line: + * ./tptp2grafite -tptppath ~tassi/TPTP-v3.1.1 GRP170-1 *) + let width = max_int in + let term_pp content_term = + let pres_term = TermContentPres.pp_ast content_term in + let dummy_tbl = Hashtbl.create 1 in + let markup = CicNotationPres.render dummy_tbl pres_term in + let s = BoxPp.render_to_string width markup in + Pcre.substitute + ~pat:"\\\\forall [Ha-z][a-z0-9_]*" ~subst:(fun x -> "\n" ^ x) s + in + CicNotationPp.set_pp_term term_pp; 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,"logic/equality.ma")))] + in + List.iter pp extra_statements_start; + List.iter + (fun (n,s) -> + print_endline + (LexiconAstPp.pp_command + (LA.Alias(floc, + LA.Ident_alias(n,s))) ^ ".")) + [(*("eq","cic:/Coq/Init/Logic/eq.ind#xpointer(1/1)"); + ("trans_eq","cic:/Coq/Init/Logic/trans_eq.con"); + ("eq_ind_r","cic:/Coq/Init/Logic/eq_ind_r.con"); + ("eq_ind","cic:/Coq/Init/Logic/eq_ind.con"); + ("sym_eq","cic:/Coq/Init/Logic/sym_eq.con"); + ("refl_equal","cic:/Coq/Init/Logic/eq.ind#xpointer(1/1/1)") *)]; List.iter pp grafite_ast_statements; exit 0