src/HOL/Tools/ATP/atp_translate.ML
changeset 45202 62b8bcf24773
parent 45168 0e8e662013f9
child 45299 ee584ff987c3
equal deleted inserted replaced
45201:154242732ef8 45202:62b8bcf24773
  1163       | freeze (Var ((s, i), T)) =
  1163       | freeze (Var ((s, i), T)) =
  1164         Free (atp_weak_prefix ^ s ^ "_" ^ string_of_int i, T)
  1164         Free (atp_weak_prefix ^ s ^ "_" ^ string_of_int i, T)
  1165       | freeze t = t
  1165       | freeze t = t
  1166   in t |> exists_subterm is_Var t ? freeze end
  1166   in t |> exists_subterm is_Var t ? freeze end
  1167 
  1167 
  1168 fun presimp_prop ctxt presimp_consts t =
  1168 fun presimp_prop ctxt presimp_consts role t =
  1169   let
  1169   (let
  1170     val thy = Proof_Context.theory_of ctxt
  1170      val thy = Proof_Context.theory_of ctxt
  1171     val t = t |> Envir.beta_eta_contract
  1171      val t = t |> Envir.beta_eta_contract
  1172               |> transform_elim_prop
  1172                |> transform_elim_prop
  1173               |> Object_Logic.atomize_term thy
  1173                |> Object_Logic.atomize_term thy
  1174     val need_trueprop = (fastype_of t = @{typ bool})
  1174      val need_trueprop = (fastype_of t = @{typ bool})
  1175   in
  1175    in
  1176     t |> need_trueprop ? HOLogic.mk_Trueprop
  1176      t |> need_trueprop ? HOLogic.mk_Trueprop
  1177       |> Raw_Simplifier.rewrite_term thy (Meson.unfold_set_const_simps ctxt) []
  1177        |> Raw_Simplifier.rewrite_term thy (Meson.unfold_set_const_simps ctxt) []
  1178       |> extensionalize_term ctxt
  1178        |> extensionalize_term ctxt
  1179       |> presimplify_term ctxt presimp_consts
  1179        |> presimplify_term ctxt presimp_consts
  1180       |> perhaps (try (HOLogic.dest_Trueprop))
  1180        |> HOLogic.dest_Trueprop
  1181   end
  1181    end
       
  1182    handle TERM _ => if role = Conjecture then @{term False} else @{term True})
       
  1183   |> pair role
  1182 
  1184 
  1183 (* making fact and conjecture formulas *)
  1185 (* making fact and conjecture formulas *)
  1184 fun make_formula ctxt format type_enc eq_as_iff name loc kind t =
  1186 fun make_formula ctxt format type_enc eq_as_iff name loc kind t =
  1185   let
  1187   let
  1186     val (iformula, atomic_types) =
  1188     val (iformula, atomic_types) =
  1197     formula as {iformula = AAtom (IConst ((s, _), _, _)), ...} =>
  1199     formula as {iformula = AAtom (IConst ((s, _), _, _)), ...} =>
  1198     if s = tptp_true then NONE else SOME formula
  1200     if s = tptp_true then NONE else SOME formula
  1199   | formula => SOME formula
  1201   | formula => SOME formula
  1200 
  1202 
  1201 fun s_not_trueprop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t
  1203 fun s_not_trueprop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t
  1202   | s_not_trueprop t = s_not t
  1204   | s_not_trueprop t =
       
  1205     if fastype_of t = @{typ bool} then s_not t else @{prop False} (* too meta *)
  1203 
  1206 
  1204 fun make_conjecture ctxt format type_enc =
  1207 fun make_conjecture ctxt format type_enc =
  1205   map (fn ((name, loc), (kind, t)) =>
  1208   map (fn ((name, loc), (kind, t)) =>
  1206           t |> kind = Conjecture ? s_not_trueprop
  1209           t |> kind = Conjecture ? s_not_trueprop
  1207             |> make_formula ctxt format type_enc (format <> CNF) name loc kind)
  1210             |> make_formula ctxt format type_enc (format <> CNF) name loc kind)
  1657       |> map (apsnd freeze_term)
  1660       |> map (apsnd freeze_term)
  1658       |> map2 (pair o rpair Local o string_of_int) (0 upto length hyp_ts)
  1661       |> map2 (pair o rpair Local o string_of_int) (0 upto length hyp_ts)
  1659     val ((conjs, facts), lambdas) =
  1662     val ((conjs, facts), lambdas) =
  1660       if preproc then
  1663       if preproc then
  1661         conjs @ facts
  1664         conjs @ facts
  1662         |> map (apsnd (apsnd (presimp_prop ctxt presimp_consts)))
  1665         |> map (apsnd (uncurry (presimp_prop ctxt presimp_consts)))
  1663         |> preprocess_abstractions_in_terms trans_lambdas
  1666         |> preprocess_abstractions_in_terms trans_lambdas
  1664         |>> chop (length conjs)
  1667         |>> chop (length conjs)
  1665       else
  1668       else
  1666         ((conjs, facts), [])
  1669         ((conjs, facts), [])
  1667     val conjs = conjs |> make_conjecture ctxt format type_enc
  1670     val conjs = conjs |> make_conjecture ctxt format type_enc