src/HOL/Tools/res_hol_clause.ML
changeset 19198 e6f1ff40ba99
parent 19130 b23479b80828
child 19354 aebf9dddccd7
equal deleted inserted replaced
19197:92404b5c20ad 19198:e6f1ff40ba99
    14 val include_min_comb = ref false;
    14 val include_min_comb = ref false;
    15 
    15 
    16 val const_typargs = ref (Library.K [] : (string*typ -> typ list));
    16 val const_typargs = ref (Library.K [] : (string*typ -> typ list));
    17 
    17 
    18 fun init thy = (include_combS:=false;include_min_comb:=false;const_typargs := Sign.const_typargs thy);
    18 fun init thy = (include_combS:=false;include_min_comb:=false;const_typargs := Sign.const_typargs thy);
       
    19 
       
    20 
    19 
    21 
    20 (**********************************************************************)
    22 (**********************************************************************)
    21 (* convert a Term.term with lambdas into a Term.term with combinators *) 
    23 (* convert a Term.term with lambdas into a Term.term with combinators *) 
    22 (**********************************************************************)
    24 (**********************************************************************)
    23 
    25 
   484     in
   486     in
   485 	make_clause(cls_id,ax_name,Axiom,
   487 	make_clause(cls_id,ax_name,Axiom,
   486 		    lits',ctypes_sorts,ctvar_lits,ctfree_lits)
   488 		    lits',ctypes_sorts,ctvar_lits,ctfree_lits)
   487     end;
   489     end;
   488 
   490 
       
   491 fun make_axiom_clauses_terms [] = []
       
   492   | make_axiom_clauses_terms ((tm,(name,id))::tms) =
       
   493     let val cls = make_axiom_clause tm (name,id)
       
   494 	val clss = make_axiom_clauses_terms tms
       
   495     in
       
   496 	if isTaut cls then clss else (cls::clss)
       
   497     end;
   489 
   498 
   490 fun make_conjecture_clause n t =
   499 fun make_conjecture_clause n t =
   491     let val t' = comb_of t
   500     let val t' = comb_of t
   492 	val (lits,ctypes_sorts) = literals_of_term t'
   501 	val (lits,ctypes_sorts) = literals_of_term t'
   493 	val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux ctypes_sorts
   502 	val (ctvar_lits,ctfree_lits) = ResClause.add_typs_aux ctypes_sorts
   725 fun hash_literal (Literal(true,pred)) = hash_combterm(pred,0w0)
   734 fun hash_literal (Literal(true,pred)) = hash_combterm(pred,0w0)
   726   | hash_literal (Literal(false,pred)) = Word.notb(hash_combterm(pred,0w0));
   735   | hash_literal (Literal(false,pred)) = Word.notb(hash_combterm(pred,0w0));
   727 
   736 
   728 fun hash_clause clause = xor_words (map hash_literal (get_literals clause));
   737 fun hash_clause clause = xor_words (map hash_literal (get_literals clause));
   729 
   738 
       
   739 (**********************************************************************)
       
   740 (* write clauses to files                                             *)
       
   741 (**********************************************************************)
       
   742 
       
   743 fun read_in [] = []
       
   744   | read_in (f1::fs) =
       
   745     let val lines = read_in fs
       
   746 	val input = TextIO.openIn f1
       
   747 	fun reading () =
       
   748 	    let val nextline = TextIO.inputLine input
       
   749 	    in
       
   750 		if nextline = "" then (TextIO.closeIn input; [])
       
   751 		else nextline::(reading ())
       
   752 	    end
       
   753     in
       
   754 	((reading ()) @ lines)
       
   755     end;
       
   756 
       
   757  
       
   758 fun get_helper_clauses (full,partial,const,untyped) =
       
   759     let val (helper1,noS,inclS) = case !typ_level of T_FULL => (warning "Fully-typed HOL"; full)
       
   760 						   | T_PARTIAL => (warning "Partially-typed HOL"; partial)
       
   761 						   | T_CONST => (warning "Const-only-typed HOL"; const)
       
   762 						   | T_NONE => (warning "Untyped HOL"; untyped)
       
   763 	val needed_helpers = if !include_combS then (warning "Include combinator S"; [helper1,inclS]) else
       
   764 			     if !include_min_comb then (warning "Include min combinators"; [helper1,noS])
       
   765 			     else (warning "No combinator is used"; [helper1])
       
   766     in
       
   767 	read_in needed_helpers
       
   768     end;
       
   769 
       
   770 
       
   771 (* write TPTP format to a single file *)
       
   772 (* when "get_helper_clauses" is called, "include_combS" and "include_min_comb" should have correct values already *)
       
   773 fun tptp_write_file terms filename (axclauses,classrel_clauses,arity_clauses) helpers =
       
   774     let val clss = make_conjecture_clauses terms
       
   775 	val axclauses' = make_axiom_clauses_terms axclauses
       
   776 	val (tptp_clss,tfree_litss) = ListPair.unzip (map clause2tptp clss)
       
   777 	val tfree_clss = map ResClause.tptp_tfree_clause (foldl (op union_string) [] tfree_litss)
       
   778 	val out = TextIO.openOut filename
       
   779 	val helper_clauses = get_helper_clauses helpers
       
   780     in
       
   781 	List.app (curry TextIO.output out o #1 o clause2tptp) axclauses';
       
   782 	ResClause.writeln_strs out tfree_clss;
       
   783 	ResClause.writeln_strs out tptp_clss;
       
   784 	List.app (curry TextIO.output out o ResClause.tptp_classrelClause) classrel_clauses;
       
   785 	List.app (curry TextIO.output out o ResClause.tptp_arity_clause) arity_clauses;
       
   786 	List.app (curry TextIO.output out) helper_clauses;
       
   787 	TextIO.closeOut out
       
   788     end;
       
   789 
   730 end
   790 end