src/HOL/Tools/res_clause.ML
changeset 17764 fde495b9e24b
parent 17745 38b4d8bf2627
child 17775 2679ba74411f
equal deleted inserted replaced
17763:6f933b702f44 17764:fde495b9e24b
    30   val make_hypothesis_clause : Term.term -> clause
    30   val make_hypothesis_clause : Term.term -> clause
    31   val get_axiomName : clause ->  string
    31   val get_axiomName : clause ->  string
    32   val isTaut : clause -> bool
    32   val isTaut : clause -> bool
    33   val num_of_clauses : clause -> int
    33   val num_of_clauses : clause -> int
    34 
    34 
    35   val dfg_clauses2str : string list -> string
       
    36   val clause2dfg : clause -> string * string list
    35   val clause2dfg : clause -> string * string list
    37   val clauses2dfg : clause list -> string -> clause list -> clause list ->
    36   val clauses2dfg : clause list -> string -> clause list -> clause list ->
    38 	   (string * int) list -> (string * int) list -> string
    37 	   (string * int) list -> (string * int) list -> string
    39   val tfree_dfg_clause : string -> string
    38   val tfree_dfg_clause : string -> string
    40 
    39 
    41   val tptp_arity_clause : arityClause -> string
    40   val tptp_arity_clause : arityClause -> string
    42   val tptp_classrelClause : classrelClause -> string
    41   val tptp_classrelClause : classrelClause -> string
    43   val tptp_clause : clause -> string list
    42   val tptp_clause : clause -> string list
    44   val tptp_clauses2str : string list -> string
       
    45   val clause2tptp : clause -> string * string list
    43   val clause2tptp : clause -> string * string list
    46   val tfree_clause : string -> string
    44   val tfree_clause : string -> string
    47   val schematic_var_prefix : string
    45   val schematic_var_prefix : string
    48   val fixed_var_prefix : string
    46   val fixed_var_prefix : string
    49   val tvar_prefix : string
    47   val tvar_prefix : string
   291 	  val (ts, funcslist) = ListPair.unzip ts_funcs
   289 	  val (ts, funcslist) = ListPair.unzip ts_funcs
   292 	  val ts' = ResLib.flat_noDup ts
   290 	  val ts' = ResLib.flat_noDup ts
   293 	  val funcs' = ResLib.flat_noDup funcslist
   291 	  val funcs' = ResLib.flat_noDup funcslist
   294 	  val t = make_fixed_type_const a
   292 	  val t = make_fixed_type_const a
   295       in    
   293       in    
   296 	  ((t ^ paren_pack folTyps), (ts', (t, length Ts)::funcs') )
   294 	  ((t ^ paren_pack folTyps), (ts', (t, length Ts)::funcs'))
   297       end
   295       end
   298   | type_of (TFree (a, s)) = 
   296   | type_of (TFree (a, s)) = 
   299       let val t = make_fixed_type_var a
   297       let val t = make_fixed_type_var a
   300       in (t, ([((FOLTFree a),s)],[(t,0)]) ) end
   298       in (t, ([((FOLTFree a),s)],[(t,0)])) end
   301   | type_of (TVar (v, s)) = (make_schematic_type_var v, ([((FOLTVar v),s)], []))
   299   | type_of (TVar (v, s)) = (make_schematic_type_var v, ([((FOLTVar v),s)], []))
   302 
   300 
   303 
   301 
   304 fun maybe_type_of c T =
   302 fun maybe_type_of c T =
   305  if no_types_needed c then ("",([],[])) else type_of T;
   303  if no_types_needed c then ("",([],[])) else type_of T;
   615 	 val nargs = length args
   613 	 val nargs = length args
   616 	 val tvars = get_TVars nargs
   614 	 val tvars = get_TVars nargs
   617 	 val conclLit = make_TConsLit(true,(res,tcons,tvars))
   615 	 val conclLit = make_TConsLit(true,(res,tcons,tvars))
   618          val tvars_srts = ListPair.zip (tvars,args)
   616          val tvars_srts = ListPair.zip (tvars,args)
   619 	 val tvars_srts' = ResLib.flat_noDup(map pack_sort tvars_srts)
   617 	 val tvars_srts' = ResLib.flat_noDup(map pack_sort tvars_srts)
   620          val false_tvars_srts' = ResLib.pair_ins false tvars_srts'
   618          val false_tvars_srts' = map (pair false) tvars_srts'
   621 	 val premLits = map make_TVarLit false_tvars_srts'
   619 	 val premLits = map make_TVarLit false_tvars_srts'
   622      in
   620      in
   623 	 make_arity_clause (cls_id,Axiom,conclLit,premLits)
   621 	 make_arity_clause (cls_id,Axiom,conclLit,premLits)
   624      end;
   622      end;
   625     
   623     
   771 
   769 
   772 fun uvar_name (UVar(a,_)) = a
   770 fun uvar_name (UVar(a,_)) = a
   773 |   uvar_name (Fun (a,_,_)) = raise CLAUSE("Not a variable", Const(a,dummyT));
   771 |   uvar_name (Fun (a,_,_)) = raise CLAUSE("Not a variable", Const(a,dummyT));
   774 
   772 
   775 fun mergelist [] = []
   773 fun mergelist [] = []
   776 |   mergelist (x::xs ) = x @ mergelist xs
   774 |   mergelist (x::xs) = x @ mergelist xs
   777 
   775 
   778 fun dfg_vars (Clause cls) =
   776 fun dfg_vars (Clause cls) =
   779     let val lits = #literals cls
   777     let val lits = #literals cls
   780         val folterms = mergelist(map dfg_folterms lits)
   778         val folterms = mergelist(map dfg_folterms lits)
   781     in 
   779     in 
   859 fun string_of_start name = "%------------------------------------------------------------------------------\nbegin_problem(" ^ name ^ ").\n\n";
   857 fun string_of_start name = "%------------------------------------------------------------------------------\nbegin_problem(" ^ name ^ ").\n\n";
   860 
   858 
   861 
   859 
   862 fun string_of_end () = "end_problem.\n%------------------------------------------------------------------------------";
   860 fun string_of_end () = "end_problem.\n%------------------------------------------------------------------------------";
   863 
   861 
   864 val delim = "\n";
       
   865 val dfg_clauses2str = ResLib.list2str_sep delim; 
       
   866      
       
   867 
   862 
   868 fun clause2dfg cls =
   863 fun clause2dfg cls =
   869     let val (lits,tfree_lits) = dfg_clause_aux cls 
   864     let val (lits,tfree_lits) = dfg_clause_aux cls 
   870             (*"lits" includes the typing assumptions (TVars)*)
   865             (*"lits" includes the typing assumptions (TVars)*)
   871 	val cls_id = get_clause_id cls
   866 	val cls_id = get_clause_id cls
   888 
   883 
   889 
   884 
   890 fun gen_dfg_file probname axioms conjectures funcs preds = 
   885 fun gen_dfg_file probname axioms conjectures funcs preds = 
   891     let val axstrs_tfrees = (map clause2dfg axioms)
   886     let val axstrs_tfrees = (map clause2dfg axioms)
   892 	val (axstrs, atfrees) = ListPair.unzip axstrs_tfrees
   887 	val (axstrs, atfrees) = ListPair.unzip axstrs_tfrees
   893         val axstr = ResLib.list2str_sep delim axstrs
   888         val axstr = (space_implode "\n" axstrs) ^ "\n\n"
   894         val conjstrs_tfrees = (map clause2dfg conjectures)
   889         val conjstrs_tfrees = (map clause2dfg conjectures)
   895 	val (conjstrs, atfrees) = ListPair.unzip conjstrs_tfrees
   890 	val (conjstrs, atfrees) = ListPair.unzip conjstrs_tfrees
   896         val tfree_clss = map tfree_dfg_clause (ResLib.flat_noDup atfrees) 
   891         val tfree_clss = map tfree_dfg_clause (ResLib.flat_noDup atfrees) 
   897         val conjstr = ResLib.list2str_sep delim (tfree_clss@conjstrs)
   892         val conjstr = (space_implode "\n" (tfree_clss@conjstrs)) ^ "\n\n"
   898         val funcstr = string_of_funcs funcs
   893         val funcstr = string_of_funcs funcs
   899         val predstr = string_of_preds preds
   894         val predstr = string_of_preds preds
   900     in
   895     in
   901        (string_of_start probname) ^ (string_of_descrip ()) ^ 
   896        (string_of_start probname) ^ (string_of_descrip ()) ^ 
   902        (string_of_symbols funcstr predstr ) ^  
   897        (string_of_symbols funcstr predstr) ^  
   903        (string_of_axioms axstr) ^
   898        (string_of_axioms axstr) ^
   904        (string_of_conjectures conjstr) ^ (string_of_end ())
   899        (string_of_conjectures conjstr) ^ (string_of_end ())
   905     end;
   900     end;
   906    
   901    
   907 fun clauses2dfg [] probname axioms conjectures funcs preds = 
   902 fun clauses2dfg [] probname axioms conjectures funcs preds = 
  1040 
  1035 
  1041 
  1036 
  1042 fun tfree_clause tfree_lit =
  1037 fun tfree_clause tfree_lit =
  1043     "input_clause(" ^ "tfree_tcs," ^ "conjecture" ^ ",[" ^ tfree_lit ^ "]).";
  1038     "input_clause(" ^ "tfree_tcs," ^ "conjecture" ^ ",[" ^ tfree_lit ^ "]).";
  1044 
  1039 
  1045 val delim = "\n";
       
  1046 val tptp_clauses2str = ResLib.list2str_sep delim; 
       
  1047      
       
  1048 
  1040 
  1049 fun tptp_of_arLit (TConsLit(b,(c,t,args))) =
  1041 fun tptp_of_arLit (TConsLit(b,(c,t,args))) =
  1050       let val pol = if b then "++" else "--"
  1042       let val pol = if b then "++" else "--"
  1051 	  val  arg_strs = (case args of [] => "" | _ => paren_pack args)
  1043 	  val  arg_strs = (case args of [] => "" | _ => paren_pack args)
  1052       in 
  1044       in