src/HOL/Tools/res_hol_clause.ML
changeset 19720 f68f6f958a1d
parent 19491 cd6c71c57f53
child 19724 20d76a40e362
equal deleted inserted replaced
19719:837025cc6317 19720:f68f6f958a1d
   503 
   503 
   504 
   504 
   505 (**********************************************************************)
   505 (**********************************************************************)
   506 (* convert clause into ATP specific formats:                          *)
   506 (* convert clause into ATP specific formats:                          *)
   507 (* TPTP used by Vampire and E                                         *)
   507 (* TPTP used by Vampire and E                                         *)
       
   508 (* DFG used by SPASS                                                  *)
   508 (**********************************************************************)
   509 (**********************************************************************)
   509 
   510 
   510 val type_wrapper = "typeinfo";
   511 val type_wrapper = "typeinfo";
   511 
   512 
   512 datatype type_level = T_FULL | T_PARTIAL | T_CONST | T_NONE;
   513 datatype type_level = T_FULL | T_PARTIAL | T_CONST | T_NONE;
   627 
   628 
   628 fun string_of_type_clsname (cls_id,ax_name,idx) = 
   629 fun string_of_type_clsname (cls_id,ax_name,idx) = 
   629     string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
   630     string_of_clausename (cls_id,ax_name) ^ "_tcs" ^ (Int.toString idx);
   630 
   631 
   631 
   632 
       
   633 (* tptp format *)
       
   634 
   632 fun tptp_literal (Literal(pol,pred)) =
   635 fun tptp_literal (Literal(pol,pred)) =
   633     let val pred_string = string_of_combterm true pred
   636     let val pred_string = string_of_combterm true pred
   634 	val pol_str = if pol then "++" else "--"
   637 	val pol_str = if pol then "++" else "--"
   635     in
   638     in
   636 	pol_str ^ pred_string
   639 	pol_str ^ pred_string
   659 	val cls_str = ResClause.gen_tptp_cls(cls_id,ax_name,knd,lits_str)
   662 	val cls_str = ResClause.gen_tptp_cls(cls_id,ax_name,knd,lits_str)
   660     in
   663     in
   661 	(cls_str,ctfree_lits)
   664 	(cls_str,ctfree_lits)
   662     end;
   665     end;
   663 
   666 
       
   667 
       
   668 (* dfg format *)
       
   669 fun dfg_literal (Literal(pol,pred)) = ResClause.dfg_sign pol (string_of_combterm true pred);
       
   670 
       
   671 fun dfg_clause_aux (Clause{literals, ctypes_sorts, ...}) = 
       
   672   let val lits = map dfg_literal literals
       
   673       val (tvar_lits,tfree_lits) = ResClause.add_typs_aux ctypes_sorts
       
   674       val tvar_lits_strs = 
       
   675 	  case !typ_level of T_NONE => [] 
       
   676 			    | _ => map ResClause.dfg_of_typeLit tvar_lits
       
   677       val tfree_lits =
       
   678           case !typ_level of T_NONE => []
       
   679 			    | _ => map ResClause.dfg_of_typeLit tfree_lits 
       
   680   in
       
   681       (tvar_lits_strs @ lits, tfree_lits)
       
   682   end; 
       
   683 
       
   684 fun get_uvars (CombConst(_,_,_)) vars = vars
       
   685   | get_uvars (CombFree(_,_)) vars = vars
       
   686   | get_uvars (CombVar(v,tp)) vars = (v::vars)
       
   687   | get_uvars (CombApp(P,Q,tp)) vars = get_uvars P (get_uvars Q vars)
       
   688   | get_uvars (Bool(c)) vars = get_uvars c vars;
       
   689 
       
   690 
       
   691 fun get_uvars_l (Literal(_,c)) = get_uvars c [];
       
   692 
       
   693 fun dfg_vars (Clause {literals,...}) = ResClause.union_all (map get_uvars_l literals);
       
   694  
       
   695 fun clause2dfg (cls as Clause{axiom_name,clause_id,kind,ctypes_sorts,...}) =
       
   696     let val (lits,tfree_lits) = dfg_clause_aux cls 
       
   697         val vars = dfg_vars cls
       
   698         val tvars = ResClause.get_tvar_strs ctypes_sorts
       
   699 	val knd = name_of_kind kind
       
   700 	val lits_str = commas lits
       
   701 	val cls_str = ResClause.gen_dfg_cls(clause_id, axiom_name, knd, lits_str, tvars@vars) 
       
   702     in (cls_str, tfree_lits) end;
       
   703 
       
   704 
       
   705 fun init_funcs_tab funcs = 
       
   706     case !typ_level of T_CONST => Symtab.update ("hEXTENT", 2) (Symtab.update ("fequal",1) funcs)
       
   707 		     | T_FULL => Symtab.update ("typeinfo",2) (Symtab.update ("hEXTENT",0) (Symtab.update ("fequal",0) funcs))
       
   708 		     | _ => Symtab.update ("hEXTENT",0) (Symtab.update ("fequal",0) funcs);
       
   709 
       
   710 
       
   711 fun add_funcs (CombConst(c,_,tvars),funcs) = 
       
   712     (case !typ_level of T_CONST => foldl ResClause.add_foltype_funcs (Symtab.update(c,length tvars) funcs) tvars
       
   713 		     | _ => foldl ResClause.add_foltype_funcs (Symtab.update(c,0) funcs) tvars)
       
   714   | add_funcs (CombFree(_,ctp),funcs) = ResClause.add_foltype_funcs (ctp,funcs) 
       
   715   | add_funcs (CombVar(_,ctp),funcs) = ResClause.add_foltype_funcs (ctp,funcs)
       
   716   | add_funcs (CombApp(P,Q,_),funcs) = add_funcs(P,add_funcs (Q,funcs))
       
   717   | add_funcs (Bool(t),funcs) = add_funcs (t,funcs);
       
   718 
       
   719 
       
   720 fun add_literal_funcs (Literal(_,c), funcs) = add_funcs (c,funcs);
       
   721 
       
   722 fun add_clause_funcs (Clause {literals, ...}, funcs) =
       
   723     foldl add_literal_funcs funcs literals
       
   724     handle Symtab.DUP a => raise ERROR ("function " ^ a ^ " has multiple arities")
       
   725 
       
   726 fun funcs_of_clauses clauses arity_clauses =
       
   727     Symtab.dest (foldl ResClause.add_arityClause_funcs 
       
   728                        (foldl add_clause_funcs (init_funcs_tab Symtab.empty) clauses)
       
   729                        arity_clauses)
       
   730 
       
   731 fun preds_of clsrel_clauses arity_clauses = 
       
   732     Symtab.dest
       
   733 	(foldl ResClause.add_classrelClause_preds 
       
   734 	       (foldl ResClause.add_arityClause_preds
       
   735 		      (Symtab.update ("hBOOL",1) Symtab.empty)
       
   736 		      arity_clauses)
       
   737 	       clsrel_clauses)
   664 
   738 
   665 
   739 
   666 (**********************************************************************)
   740 (**********************************************************************)
   667 (* clause equalities and hashing functions                            *)
   741 (* clause equalities and hashing functions                            *)
   668 (**********************************************************************)
   742 (**********************************************************************)
   730 
   804 
   731 (**********************************************************************)
   805 (**********************************************************************)
   732 (* write clauses to files                                             *)
   806 (* write clauses to files                                             *)
   733 (**********************************************************************)
   807 (**********************************************************************)
   734 
   808 
       
   809 (* tptp format *)
       
   810 
   735 fun read_in fs = map (File.read o File.unpack_platform_path) fs; 
   811 fun read_in fs = map (File.read o File.unpack_platform_path) fs; 
   736 
   812 
   737 fun get_helper_clauses_tptp () =
   813 fun get_helper_clauses_tptp () =
   738     let val tlevel = case !typ_level of T_FULL => (warning "Fully-typed HOL"; "~~/src/HOL/Tools/atp-inputs/full_")
   814     let val tlevel = case !typ_level of T_FULL => (warning "Fully-typed HOL"; "~~/src/HOL/Tools/atp-inputs/full_")
   739 				      | T_PARTIAL => (warning "Partially-typed HOL"; "~~/src/HOL/Tools/atp-inputs/par_")
   815 				      | T_PARTIAL => (warning "Partially-typed HOL"; "~~/src/HOL/Tools/atp-inputs/par_")
   765 	List.app (curry TextIO.output out o ResClause.tptp_arity_clause) arity_clauses;
   841 	List.app (curry TextIO.output out o ResClause.tptp_arity_clause) arity_clauses;
   766 	List.app (curry TextIO.output out) helper_clauses;
   842 	List.app (curry TextIO.output out) helper_clauses;
   767 	TextIO.closeOut out
   843 	TextIO.closeOut out
   768     end;
   844     end;
   769 
   845 
       
   846 
       
   847 (* dfg format *)
       
   848 fun get_helper_clauses_dfg () = 
       
   849     let val tlevel = case !typ_level of T_FULL => (warning "Fully-typed HOL"; "~~/src/HOL/Tools/atp-inputs/full_")
       
   850 				      | T_PARTIAL => (warning "Partially-typed HOL"; "~~/src/HOL/Tools/atp-inputs/par_")
       
   851 				      | T_CONST => (warning "Const-only-typed HOL"; "~~/src/HOL/Tools/atp-inputs/const_")
       
   852 				      | T_NONE => (warning "Untyped HOL"; "~~/src/HOL/Tools/atp-inputs/u_")
       
   853 	val helpers = if !include_combS then (warning "Include combinator S"; ["helper1.dfg","comb_inclS.dfg"]) else
       
   854 		      if !include_min_comb then (warning "Include min combinators"; ["helper1.dfg","comb_noS.dfg"])
       
   855 		      else (warning "No combinator is used"; ["helper1.dfg"])
       
   856 	val t_helpers = map (curry (op ^) tlevel) helpers
       
   857     in
       
   858 	read_in t_helpers
       
   859     end;
       
   860 
       
   861 
       
   862 fun dfg_write_file  thms filename (axclauses,classrel_clauses,arity_clauses) =
       
   863     let val _ = Output.debug ("Preparing to write the DFG file " ^ filename) 
       
   864 	val conjectures = make_conjecture_clauses thms
       
   865 	val axclauses' = make_axiom_clauses axclauses
       
   866 	val (dfg_clss,tfree_litss) = ListPair.unzip (map clause2dfg conjectures)
       
   867 	val clss = conjectures @ axclauses'
       
   868 	val funcs = funcs_of_clauses clss arity_clauses
       
   869 	and preds = preds_of classrel_clauses arity_clauses
       
   870 	and probname = Path.pack (Path.base (Path.unpack filename))
       
   871 	val (axstrs,_) =  ListPair.unzip (map clause2dfg axclauses')
       
   872 	val tfree_clss = map ResClause.dfg_tfree_clause (ResClause.union_all tfree_litss)
       
   873 	val out = TextIO.openOut filename
       
   874 	val helper_clauses = get_helper_clauses_dfg ()
       
   875     in
       
   876 	TextIO.output (out, ResClause.string_of_start probname); 
       
   877 	TextIO.output (out, ResClause.string_of_descrip probname); 
       
   878 	TextIO.output (out, ResClause.string_of_symbols (ResClause.string_of_funcs funcs) (ResClause.string_of_preds preds)); 
       
   879 	TextIO.output (out, "list_of_clauses(axioms,cnf).\n");
       
   880 	ResClause.writeln_strs out axstrs;
       
   881 	List.app (curry TextIO.output out o ResClause.dfg_classrelClause) classrel_clauses;
       
   882 	List.app (curry TextIO.output out o ResClause.dfg_arity_clause) arity_clauses;
       
   883 	ResClause.writeln_strs out helper_clauses;
       
   884 	TextIO.output (out, "end_of_list.\n\nlist_of_clauses(conjectures,cnf).\n");
       
   885 	ResClause.writeln_strs out tfree_clss;
       
   886 	ResClause.writeln_strs out dfg_clss;
       
   887 	TextIO.output (out, "end_of_list.\n\nend_problem.\n");
       
   888 	TextIO.closeOut out
       
   889     end;
       
   890 
   770 end
   891 end