src/HOL/Tools/ATP/atp_problem_generate.ML
changeset 47905 9b6afe0eb69c
parent 47810 9579464d00f9
child 47911 2168126446bb
equal deleted inserted replaced
47904:67663c968d70 47905:9b6afe0eb69c
  1160         |> (fn T_args => IConst (name, T, T_args))
  1160         |> (fn T_args => IConst (name, T, T_args))
  1161       | filt _ (IAbs (bound, tm)) = IAbs (bound, filt 0 tm)
  1161       | filt _ (IAbs (bound, tm)) = IAbs (bound, filt 0 tm)
  1162       | filt _ tm = tm
  1162       | filt _ tm = tm
  1163   in filt 0 end
  1163   in filt 0 end
  1164 
  1164 
  1165 fun iformula_from_prop ctxt type_enc eq_as_iff =
  1165 fun iformula_from_prop ctxt type_enc iff_for_eq =
  1166   let
  1166   let
  1167     val thy = Proof_Context.theory_of ctxt
  1167     val thy = Proof_Context.theory_of ctxt
  1168     fun do_term bs t atomic_Ts =
  1168     fun do_term bs t atomic_Ts =
  1169       iterm_from_term thy type_enc bs (Envir.eta_contract t)
  1169       iterm_from_term thy type_enc bs (Envir.eta_contract t)
  1170       |>> (introduce_proxies_in_iterm type_enc
  1170       |>> (introduce_proxies_in_iterm type_enc
  1201       | @{const HOL.conj} $ t1 $ t2 => do_conn bs AAnd pos t1 pos t2
  1201       | @{const HOL.conj} $ t1 $ t2 => do_conn bs AAnd pos t1 pos t2
  1202       | @{const HOL.disj} $ t1 $ t2 => do_conn bs AOr pos t1 pos t2
  1202       | @{const HOL.disj} $ t1 $ t2 => do_conn bs AOr pos t1 pos t2
  1203       | @{const HOL.implies} $ t1 $ t2 =>
  1203       | @{const HOL.implies} $ t1 $ t2 =>
  1204         do_conn bs AImplies (Option.map not pos) t1 pos t2
  1204         do_conn bs AImplies (Option.map not pos) t1 pos t2
  1205       | Const (@{const_name HOL.eq}, Type (_, [@{typ bool}, _])) $ t1 $ t2 =>
  1205       | Const (@{const_name HOL.eq}, Type (_, [@{typ bool}, _])) $ t1 $ t2 =>
  1206         if eq_as_iff then do_conn bs AIff NONE t1 NONE t2 else do_term bs t
  1206         if iff_for_eq then do_conn bs AIff NONE t1 NONE t2 else do_term bs t
  1207       | _ => do_term bs t
  1207       | _ => do_term bs t
  1208   in do_formula [] end
  1208   in do_formula [] end
  1209 
  1209 
  1210 fun presimplify_term thy t =
  1210 fun presimplify_term thy t =
  1211   if exists_Const (member (op =) Meson.presimplified_consts o fst) t then
  1211   if exists_Const (member (op =) Meson.presimplified_consts o fst) t then
  1250       |> presimplify_term thy
  1250       |> presimplify_term thy
  1251       |> HOLogic.dest_Trueprop
  1251       |> HOLogic.dest_Trueprop
  1252   end
  1252   end
  1253   handle TERM _ => @{const True}
  1253   handle TERM _ => @{const True}
  1254 
  1254 
  1255 fun make_formula ctxt type_enc eq_as_iff name stature kind t =
  1255 (* Satallax prefers "=" to "<=>" (for definitions) and Metis (CNF) requires "="
  1256   let
  1256    for obscure technical reasons. *)
       
  1257 fun should_use_iff_for_eq CNF _ = false
       
  1258   | should_use_iff_for_eq (THF _) format = not (is_type_enc_higher_order format)
       
  1259   | should_use_iff_for_eq _ _ = true
       
  1260 
       
  1261 fun make_formula ctxt format type_enc iff_for_eq name stature kind t =
       
  1262   let
       
  1263     val iff_for_eq = iff_for_eq andalso should_use_iff_for_eq format type_enc
  1257     val (iformula, atomic_Ts) =
  1264     val (iformula, atomic_Ts) =
  1258       iformula_from_prop ctxt type_enc eq_as_iff (SOME (kind <> Conjecture)) t
  1265       iformula_from_prop ctxt type_enc iff_for_eq (SOME (kind <> Conjecture)) t
  1259                          []
  1266                          []
  1260       |>> close_iformula_universally
  1267       |>> close_iformula_universally
  1261   in
  1268   in
  1262     {name = name, stature = stature, kind = kind, iformula = iformula,
  1269     {name = name, stature = stature, kind = kind, iformula = iformula,
  1263      atomic_types = atomic_Ts}
  1270      atomic_types = atomic_Ts}
  1264   end
  1271   end
  1265 
  1272 
  1266 (* Satallax prefers "=" to "<=>" *)
  1273 fun make_fact ctxt format type_enc iff_for_eq ((name, stature), t) =
  1267 fun is_format_eq_as_iff FOF = true
  1274   case t |> make_formula ctxt format type_enc iff_for_eq name stature Axiom of
  1268   | is_format_eq_as_iff (TFF _) = true
       
  1269   | is_format_eq_as_iff (DFG _) = true
       
  1270   | is_format_eq_as_iff _ = false
       
  1271 
       
  1272 fun make_fact ctxt format type_enc eq_as_iff ((name, stature), t) =
       
  1273   case t |> make_formula ctxt type_enc
       
  1274                          (eq_as_iff andalso is_format_eq_as_iff format) name
       
  1275                          stature Axiom of
       
  1276     formula as {iformula = AAtom (IConst ((s, _), _, _)), ...} =>
  1275     formula as {iformula = AAtom (IConst ((s, _), _, _)), ...} =>
  1277     if s = tptp_true then NONE else SOME formula
  1276     if s = tptp_true then NONE else SOME formula
  1278   | formula => SOME formula
  1277   | formula => SOME formula
  1279 
  1278 
  1280 fun s_not_prop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t
  1279 fun s_not_prop (@{const Trueprop} $ t) = @{const Trueprop} $ s_not t
  1285 *)
  1284 *)
  1286 
  1285 
  1287 fun make_conjecture ctxt format type_enc =
  1286 fun make_conjecture ctxt format type_enc =
  1288   map (fn ((name, stature), (kind, t)) =>
  1287   map (fn ((name, stature), (kind, t)) =>
  1289           t |> kind = Conjecture ? s_not
  1288           t |> kind = Conjecture ? s_not
  1290             |> make_formula ctxt type_enc (is_format_eq_as_iff format) name
  1289             |> make_formula ctxt format type_enc true name stature kind)
  1291                             stature kind)
       
  1292 
  1290 
  1293 (** Finite and infinite type inference **)
  1291 (** Finite and infinite type inference **)
  1294 
  1292 
  1295 fun tvar_footprint thy s ary =
  1293 fun tvar_footprint thy s ary =
  1296   (case unprefix_and_unascii const_prefix s of
  1294   (case unprefix_and_unascii const_prefix s of