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=cbdddf851c9d2a9233e68f5c9465429ffd01c0a9;hpb=7b1a37c0db4ca152017ef428f0483e8c6156de89;p=helm.git diff --git a/helm/software/components/binaries/tptp2grafite/main.ml b/helm/software/components/binaries/tptp2grafite/main.ml index cbdddf851..871ff7b56 100644 --- a/helm/software/components/binaries/tptp2grafite/main.ml +++ b/helm/software/components/binaries/tptp2grafite/main.ml @@ -4,11 +4,21 @@ 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 @@ -42,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 @@ -56,38 +72,41 @@ 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)) ;; -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 = @@ -96,20 +115,40 @@ let collect_arities atom ctx = (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 atom context in - build_ctx_for_arities arities (build_ctx 0 context) + 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 @@ -133,18 +172,49 @@ let convert_ast statements context = function | 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( - 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))))] @ + (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 @@ -214,8 +284,19 @@ 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 @@ -224,21 +305,20 @@ let _ = 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")))] + GA.Executable(floc,GA.Command(floc, GA.Include(floc,"logic/equality.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 + List.iter + (fun (n,s) -> + print_endline (LexiconAstPp.pp_command (LA.Alias(floc, - LA.Ident_alias("eq","cic:/Coq/Init/Logic/eq.ind#xpointer(1/1)"))) ^ "."); + 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; - List.iter pp extra_statements_end; exit 0