src/HOL/Tools/ATP/atp_translate.ML
changeset 46093 4bf24b90703c
parent 46071 1613933e412c
child 46301 e2e52c7d25c9
equal deleted inserted replaced
46092:287a3cefc21b 46093:4bf24b90703c
  1091       | Const (@{const_name HOL.eq}, Type (_, [@{typ bool}, _])) $ t1 $ t2 =>
  1091       | Const (@{const_name HOL.eq}, Type (_, [@{typ bool}, _])) $ t1 $ t2 =>
  1092         if eq_as_iff then do_conn bs AIff NONE t1 NONE t2 else do_term bs t
  1092         if eq_as_iff then do_conn bs AIff NONE t1 NONE t2 else do_term bs t
  1093       | _ => do_term bs t
  1093       | _ => do_term bs t
  1094   in do_formula [] end
  1094   in do_formula [] end
  1095 
  1095 
  1096 fun presimplify_term _ [] t = t
  1096 fun presimplify_term ctxt t =
  1097   | presimplify_term ctxt presimp_consts t =
  1097   t |> exists_Const (member (op =) Meson.presimplified_consts o fst) t
  1098     t |> exists_Const (member (op =) presimp_consts o fst) t
  1098        ? (Skip_Proof.make_thm (Proof_Context.theory_of ctxt)
  1099          ? (Skip_Proof.make_thm (Proof_Context.theory_of ctxt)
  1099           #> Meson.presimplify
  1100             #> Meson.presimplify ctxt
  1100           #> prop_of)
  1101             #> prop_of)
       
  1102 
  1101 
  1103 fun concealed_bound_name j = atp_weak_prefix ^ string_of_int j
  1102 fun concealed_bound_name j = atp_weak_prefix ^ string_of_int j
  1104 fun conceal_bounds Ts t =
  1103 fun conceal_bounds Ts t =
  1105   subst_bounds (map (Free o apfst concealed_bound_name)
  1104   subst_bounds (map (Free o apfst concealed_bound_name)
  1106                     (0 upto length Ts - 1 ~~ Ts), t)
  1105                     (0 upto length Ts - 1 ~~ Ts), t)
  1194       | freeze (Var ((s, i), T)) =
  1193       | freeze (Var ((s, i), T)) =
  1195         Free (atp_weak_prefix ^ s ^ "_" ^ string_of_int i, T)
  1194         Free (atp_weak_prefix ^ s ^ "_" ^ string_of_int i, T)
  1196       | freeze t = t
  1195       | freeze t = t
  1197   in t |> exists_subterm is_Var t ? freeze end
  1196   in t |> exists_subterm is_Var t ? freeze end
  1198 
  1197 
  1199 fun presimp_prop ctxt presimp_consts role t =
  1198 fun presimp_prop ctxt role t =
  1200   (let
  1199   (let
  1201      val thy = Proof_Context.theory_of ctxt
  1200      val thy = Proof_Context.theory_of ctxt
  1202      val t = t |> Envir.beta_eta_contract
  1201      val t = t |> Envir.beta_eta_contract
  1203                |> transform_elim_prop
  1202                |> transform_elim_prop
  1204                |> Object_Logic.atomize_term thy
  1203                |> Object_Logic.atomize_term thy
  1205      val need_trueprop = (fastype_of t = @{typ bool})
  1204      val need_trueprop = (fastype_of t = @{typ bool})
  1206    in
  1205    in
  1207      t |> need_trueprop ? HOLogic.mk_Trueprop
  1206      t |> need_trueprop ? HOLogic.mk_Trueprop
  1208        |> extensionalize_term ctxt
  1207        |> extensionalize_term ctxt
  1209        |> presimplify_term ctxt presimp_consts
  1208        |> presimplify_term ctxt
  1210        |> HOLogic.dest_Trueprop
  1209        |> HOLogic.dest_Trueprop
  1211    end
  1210    end
  1212    handle TERM _ => if role = Conjecture then @{term False} else @{term True})
  1211    handle TERM _ => if role = Conjecture then @{term False} else @{term True})
  1213   |> pair role
  1212   |> pair role
  1214 
  1213 
  1706 fun translate_formulas ctxt format prem_kind type_enc lam_trans presimp hyp_ts
  1705 fun translate_formulas ctxt format prem_kind type_enc lam_trans presimp hyp_ts
  1707                        concl_t facts =
  1706                        concl_t facts =
  1708   let
  1707   let
  1709     val thy = Proof_Context.theory_of ctxt
  1708     val thy = Proof_Context.theory_of ctxt
  1710     val trans_lams = trans_lams_from_string ctxt type_enc lam_trans
  1709     val trans_lams = trans_lams_from_string ctxt type_enc lam_trans
  1711     val presimp_consts = Meson.presimplified_consts ctxt
       
  1712     val fact_ts = facts |> map snd
  1710     val fact_ts = facts |> map snd
  1713     (* Remove existing facts from the conjecture, as this can dramatically
  1711     (* Remove existing facts from the conjecture, as this can dramatically
  1714        boost an ATP's performance (for some reason). *)
  1712        boost an ATP's performance (for some reason). *)
  1715     val hyp_ts =
  1713     val hyp_ts =
  1716       hyp_ts
  1714       hyp_ts
  1720       map (pair prem_kind) hyp_ts @ [(Conjecture, s_not_trueprop concl_t)]
  1718       map (pair prem_kind) hyp_ts @ [(Conjecture, s_not_trueprop concl_t)]
  1721       |> map (apsnd freeze_term)
  1719       |> map (apsnd freeze_term)
  1722       |> map2 (pair o rpair Local o string_of_int) (0 upto length hyp_ts)
  1720       |> map2 (pair o rpair Local o string_of_int) (0 upto length hyp_ts)
  1723     val ((conjs, facts), lam_facts) =
  1721     val ((conjs, facts), lam_facts) =
  1724       (conjs, facts)
  1722       (conjs, facts)
  1725       |> presimp
  1723       |> presimp ? pairself (map (apsnd (uncurry (presimp_prop ctxt))))
  1726          ? pairself (map (apsnd (uncurry (presimp_prop ctxt presimp_consts))))
       
  1727       |> (if lam_trans = no_lamsN then
  1724       |> (if lam_trans = no_lamsN then
  1728             rpair []
  1725             rpair []
  1729           else
  1726           else
  1730             op @
  1727             op @
  1731             #> preprocess_abstractions_in_terms trans_lams
  1728             #> preprocess_abstractions_in_terms trans_lams