src/HOL/Tools/res_hol_clause.ML
changeset 18276 c62ec94e326e
parent 18200 9d476d1054d7
child 18356 443717b3a9ad
equal deleted inserted replaced
18275:86cefba6d325 18276:c62ec94e326e
     8 structure ResHolClause =
     8 structure ResHolClause =
     9 
     9 
    10 struct
    10 struct
    11 
    11 
    12 
    12 
       
    13 val include_combS = ref false;
       
    14 val include_min_comb = ref false;
    13 
    15 
    14 
    16 
    15 (**********************************************************************)
    17 (**********************************************************************)
    16 (* convert a Term.term with lambdas into a Term.term with combinators *) 
    18 (* convert a Term.term with lambdas into a Term.term with combinators *) 
    17 (**********************************************************************)
    19 (**********************************************************************)
    37 
    39 
    38 (*******************************************)
    40 (*******************************************)
    39 fun lam2comb (Abs(x,tp,Bound 0)) _ = 
    41 fun lam2comb (Abs(x,tp,Bound 0)) _ = 
    40     let val tpI = Type("fun",[tp,tp])
    42     let val tpI = Type("fun",[tp,tp])
    41     in 
    43     in 
       
    44 	include_min_comb:=true;
    42 	Const("COMBI",tpI) 
    45 	Const("COMBI",tpI) 
    43     end
    46     end
    44   | lam2comb (Abs(x,t1,Const(c,t2))) _ = 
    47   | lam2comb (Abs(x,t1,Const(c,t2))) _ = 
    45     let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
    48     let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
    46     in 
    49     in 
       
    50 	include_min_comb:=true;
    47 	Const("COMBK",tK) $ Const(c,t2) 
    51 	Const("COMBK",tK) $ Const(c,t2) 
    48     end
    52     end
    49   | lam2comb (Abs(x,t1,Free(v,t2))) _ =
    53   | lam2comb (Abs(x,t1,Free(v,t2))) _ =
    50     let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
    54     let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
    51     in
    55     in
       
    56 	include_min_comb:=true;
    52 	Const("COMBK",tK) $ Free(v,t2)
    57 	Const("COMBK",tK) $ Free(v,t2)
    53     end
    58     end
    54   | lam2comb (Abs(x,t1,Var(ind,t2))) _=
    59   | lam2comb (Abs(x,t1,Var(ind,t2))) _=
    55     let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
    60     let val tK = Type("fun",[t2,Type("fun",[t1,t2])])
    56     in
    61     in
       
    62 	include_min_comb:=true;
    57 	Const("COMBK",tK) $ Var(ind,t2)
    63 	Const("COMBK",tK) $ Var(ind,t2)
    58     end
    64     end
    59   | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds =
    65   | lam2comb (t as (Abs(x,t1,P$(Bound 0)))) Bnds =
    60     let val nfreeP = not(is_free P 0)
    66     let val nfreeP = not(is_free P 0)
    61 	val tr = Term.type_of1(t1::Bnds,P)
    67 	val tr = Term.type_of1(t1::Bnds,P)
    65 	      let val tI = Type("fun",[t1,t1])
    71 	      let val tI = Type("fun",[t1,t1])
    66 		  val P' = lam2comb (Abs(x,t1,P)) Bnds
    72 		  val P' = lam2comb (Abs(x,t1,P)) Bnds
    67 		  val tp' = Term.type_of1(Bnds,P')
    73 		  val tp' = Term.type_of1(Bnds,P')
    68 		  val tS = Type("fun",[tp',Type("fun",[tI,tr])])
    74 		  val tS = Type("fun",[tp',Type("fun",[tI,tr])])
    69 	      in
    75 	      in
       
    76 		  include_min_comb:=true;
       
    77 		  include_combS:=true;
    70 		  Const("COMBS",tS) $ P' $ Const("COMBI",tI)
    78 		  Const("COMBS",tS) $ P' $ Const("COMBI",tI)
    71 	      end)
    79 	      end)
    72     end
    80     end
    73 	    
    81 	    
    74   | lam2comb (t as (Abs(x,t1,P$Q))) Bnds =
    82   | lam2comb (t as (Abs(x,t1,P$Q))) Bnds =
    77     in
    85     in
    78 	if(nfreeP andalso nfreeQ) then (
    86 	if(nfreeP andalso nfreeQ) then (
    79 	    let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])])
    87 	    let val tK = Type("fun",[tpq,Type("fun",[t1,tpq])])
    80 		val PQ' = decre_bndVar(P $ Q)
    88 		val PQ' = decre_bndVar(P $ Q)
    81 	    in 
    89 	    in 
       
    90 		include_min_comb:=true;
    82 		Const("COMBK",tK) $ PQ'
    91 		Const("COMBK",tK) $ PQ'
    83 	    end)
    92 	    end)
    84 	else (
    93 	else (
    85 	      if nfreeP then (
    94 	      if nfreeP then (
    86 			       let val Q' = lam2comb (Abs(x,t1,Q)) Bnds
    95 			       let val Q' = lam2comb (Abs(x,t1,Q)) Bnds
    87 				   val P' = decre_bndVar P
    96 				   val P' = decre_bndVar P
    88 				   val tp = Term.type_of1(Bnds,P')
    97 				   val tp = Term.type_of1(Bnds,P')
    89 				   val tq' = Term.type_of1(Bnds, Q')
    98 				   val tq' = Term.type_of1(Bnds, Q')
    90 				   val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])])
    99 				   val tB = Type("fun",[tp,Type("fun",[tq',Type("fun",[t1,tpq])])])
    91 			       in
   100 			       in
       
   101 				   include_min_comb:=true;
    92 				   Const("COMBB",tB) $ P' $ Q' 
   102 				   Const("COMBB",tB) $ P' $ Q' 
    93 			       end)
   103 			       end)
    94 	      else (
   104 	      else (
    95 		    if nfreeQ then (
   105 		    if nfreeQ then (
    96 				    let val P' = lam2comb (Abs(x,t1,P)) Bnds
   106 				    let val P' = lam2comb (Abs(x,t1,P)) Bnds
    97 					val Q' = decre_bndVar Q
   107 					val Q' = decre_bndVar Q
    98 					val tq = Term.type_of1(Bnds,Q')
   108 					val tq = Term.type_of1(Bnds,Q')
    99 					val tp' = Term.type_of1(Bnds, P')
   109 					val tp' = Term.type_of1(Bnds, P')
   100 					val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])])
   110 					val tC = Type("fun",[tp',Type("fun",[tq,Type("fun",[t1,tpq])])])
   101 				    in
   111 				    in
       
   112 					include_min_comb:=true;
   102 					Const("COMBC",tC) $ P' $ Q'
   113 					Const("COMBC",tC) $ P' $ Q'
   103 				    end)
   114 				    end)
   104 		    else(
   115 		    else(
   105 			 let val P' = lam2comb (Abs(x,t1,P)) Bnds
   116 			 let val P' = lam2comb (Abs(x,t1,P)) Bnds
   106 			     val Q' = lam2comb (Abs(x,t1,Q)) Bnds
   117 			     val Q' = lam2comb (Abs(x,t1,Q)) Bnds
   107 			     val tp' = Term.type_of1(Bnds,P')
   118 			     val tp' = Term.type_of1(Bnds,P')
   108 			     val tq' = Term.type_of1(Bnds,Q')
   119 			     val tq' = Term.type_of1(Bnds,Q')
   109 			     val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])])
   120 			     val tS = Type("fun",[tp',Type("fun",[tq',Type("fun",[t1,tpq])])])
   110 			 in
   121 			 in
       
   122 			     include_min_comb:=true;
       
   123 			     include_combS:=true;
   111 			     Const("COMBS",tS) $ P' $ Q'
   124 			     Const("COMBS",tS) $ P' $ Q'
   112 			 end)))
   125 			 end)))
   113     end
   126     end
   114   | lam2comb (t as (Abs(x,t1,_))) _ = raise LAM2COMB (t);
   127   | lam2comb (t as (Abs(x,t1,_))) _ = raise LAM2COMB (t);
   115 
   128 
   194 
   207 
   195 (*********************************************************************)
   208 (*********************************************************************)
   196 (* convert a clause with type Term.term to a clause with type clause *)
   209 (* convert a clause with type Term.term to a clause with type clause *)
   197 (*********************************************************************)
   210 (*********************************************************************)
   198 
   211 
   199 
       
   200 fun isFalse (Literal(pol,Bool(CombConst(c,_)))) =
   212 fun isFalse (Literal(pol,Bool(CombConst(c,_)))) =
   201     (pol andalso c = "c_False") orelse
   213     (pol andalso c = "c_False") orelse
   202     (not pol andalso c = "c_True")
   214     (not pol andalso c = "c_True")
   203   | isFalse _ = false;
   215   | isFalse _ = false;
   204 
   216 
   347 (* convert clause into ATP specific formats:                          *)
   359 (* convert clause into ATP specific formats:                          *)
   348 (* TPTP used by Vampire and E                                         *)
   360 (* TPTP used by Vampire and E                                         *)
   349 (**********************************************************************)
   361 (**********************************************************************)
   350 
   362 
   351 val keep_types = ref true;
   363 val keep_types = ref true;
   352 val include_combS = ref false;
       
   353 
       
   354 
   364 
   355 val type_wrapper = "typeinfo";
   365 val type_wrapper = "typeinfo";
   356 
   366 
   357 fun put_type (c,t) = 
   367 fun put_type (c,t) = 
   358     if !keep_types then type_wrapper ^ (ResClause.paren_pack [c,t])
   368     if !keep_types then type_wrapper ^ (ResClause.paren_pack [c,t])