src/HOL/Tools/ATP/atp_problem_generate.ML
changeset 51920 16f3b9d4e515
parent 51717 9e7d1c139569
child 51921 bbbacaef19a6
equal deleted inserted replaced
51919:097b191d1f0d 51920:16f3b9d4e515
   549     fun ary (Type (@{type_name fun}, [_, T])) = 1 + ary T
   549     fun ary (Type (@{type_name fun}, [_, T])) = 1 + ary T
   550       | ary _ = 0
   550       | ary _ = 0
   551   in ary oo robust_const_type end
   551   in ary oo robust_const_type end
   552 
   552 
   553 (* This function only makes sense if "T" is as general as possible. *)
   553 (* This function only makes sense if "T" is as general as possible. *)
   554 fun robust_const_typargs thy (s, T) =
   554 fun robust_const_type_args thy (s, T) =
   555   if s = app_op_name then
   555   if s = app_op_name then
   556     let val (T1, T2) = T |> domain_type |> dest_funT in [T1, T2] end
   556     let val (T1, T2) = T |> domain_type |> dest_funT in [T1, T2] end
   557   else if String.isPrefix old_skolem_const_prefix s then
   557   else if String.isPrefix old_skolem_const_prefix s then
   558     [] |> Term.add_tvarsT T |> rev |> map TVar
   558     [] |> Term.add_tvarsT T |> rev |> map TVar
   559   else if String.isPrefix lam_lifted_prefix s then
   559   else if String.isPrefix lam_lifted_prefix s then
   571       val (P', P_atomics_Ts) = iterm_from_term thy type_enc bs P
   571       val (P', P_atomics_Ts) = iterm_from_term thy type_enc bs P
   572       val (Q', Q_atomics_Ts) = iterm_from_term thy type_enc bs Q
   572       val (Q', Q_atomics_Ts) = iterm_from_term thy type_enc bs Q
   573     in (IApp (P', Q'), union (op =) P_atomics_Ts Q_atomics_Ts) end
   573     in (IApp (P', Q'), union (op =) P_atomics_Ts Q_atomics_Ts) end
   574   | iterm_from_term thy type_enc _ (Const (c, T)) =
   574   | iterm_from_term thy type_enc _ (Const (c, T)) =
   575     (IConst (`(make_fixed_const (SOME type_enc)) c, T,
   575     (IConst (`(make_fixed_const (SOME type_enc)) c, T,
   576              robust_const_typargs thy (c, T)),
   576              robust_const_type_args thy (c, T)),
   577      atomic_types_of T)
   577      atomic_types_of T)
   578   | iterm_from_term _ _ _ (Free (s, T)) =
   578   | iterm_from_term _ _ _ (Free (s, T)) =
   579     (IConst (`make_fixed_var s, T, []), atomic_types_of T)
   579     (IConst (`make_fixed_var s, T, []), atomic_types_of T)
   580   | iterm_from_term _ type_enc _ (Var (v as (s, _), T)) =
   580   | iterm_from_term _ type_enc _ (Var (v as (s, _), T)) =
   581     (if String.isPrefix Meson_Clausify.new_skolem_var_prefix s then
   581     (if String.isPrefix Meson_Clausify.new_skolem_var_prefix s then
   868                 if keep (member (op =) in_U_vars U_var,
   868                 if keep (member (op =) in_U_vars U_var,
   869                          member (op =) out_U_vars U_var) then
   869                          member (op =) out_U_vars U_var) then
   870                   T
   870                   T
   871                 else
   871                 else
   872                   dummyT
   872                   dummyT
   873               val U_args = (s, U) |> robust_const_typargs thy
   873               val U_args = (s, U) |> robust_const_type_args thy
   874             in map (filt o apfst dest_TVar) (U_args ~~ T_args) end
   874             in map (filt o apfst dest_TVar) (U_args ~~ T_args) end
   875             handle TYPE _ => T_args
   875             handle TYPE _ => T_args
   876         val noninfer_type_args = gen_type_args (not o fst) (chop_fun ary)
   876         val noninfer_type_args = gen_type_args (not o fst) (chop_fun ary)
   877         val constr_infer_type_args = gen_type_args fst strip_type
   877         val constr_infer_type_args = gen_type_args fst strip_type
   878         val level = level_of_type_enc type_enc
   878         val level = level_of_type_enc type_enc
  1085                                                 quote s)) parse_mangled_type))
  1085                                                 quote s)) parse_mangled_type))
  1086     |> fst
  1086     |> fst
  1087 
  1087 
  1088 fun unmangled_const_name s =
  1088 fun unmangled_const_name s =
  1089   (s, s) |> unaliased_uncurried |> fst |> space_explode mangled_type_sep
  1089   (s, s) |> unaliased_uncurried |> fst |> space_explode mangled_type_sep
       
  1090 
  1090 fun unmangled_const s =
  1091 fun unmangled_const s =
  1091   let val ss = unmangled_const_name s in
  1092   let val ss = unmangled_const_name s in
  1092     (hd ss, map unmangled_type (tl ss))
  1093     (hd ss, map unmangled_type (tl ss))
  1093   end
  1094   end
       
  1095 
       
  1096 val unmangled_invert_const = invert_const o hd o unmangled_const_name
  1094 
  1097 
  1095 fun introduce_proxies_in_iterm type_enc =
  1098 fun introduce_proxies_in_iterm type_enc =
  1096   let
  1099   let
  1097     fun tweak_ho_quant ho_quant T [IAbs _] = IConst (`I ho_quant, T, [])
  1100     fun tweak_ho_quant ho_quant T [IAbs _] = IConst (`I ho_quant, T, [])
  1098       | tweak_ho_quant ho_quant (T as Type (_, [p_T as Type (_, [x_T, _]), _]))
  1101       | tweak_ho_quant ho_quant (T as Type (_, [p_T as Type (_, [x_T, _]), _]))
  1172     case unprefix_and_unascii const_prefix s of
  1175     case unprefix_and_unascii const_prefix s of
  1173       NONE =>
  1176       NONE =>
  1174       if level_of_type_enc type_enc = No_Types orelse s = tptp_choice then []
  1177       if level_of_type_enc type_enc = No_Types orelse s = tptp_choice then []
  1175       else T_args
  1178       else T_args
  1176     | SOME s'' =>
  1179     | SOME s'' =>
  1177       filter_type_args thy constrs type_enc (invert_const s'') ary T_args
  1180       filter_type_args thy constrs type_enc (unmangled_invert_const s'') ary T_args
  1178 fun filter_type_args_in_iterm thy constrs type_enc =
  1181 fun filter_type_args_in_iterm thy constrs type_enc =
  1179   let
  1182   let
  1180     fun filt ary (IApp (tm1, tm2)) = IApp (filt (ary + 1) tm1, filt 0 tm2)
  1183     fun filt ary (IApp (tm1, tm2)) = IApp (filt (ary + 1) tm1, filt 0 tm2)
  1181       | filt ary (IConst (name as (s, _), T, T_args)) =
  1184       | filt ary (IConst (name as (s, _), T, T_args)) =
  1182         filter_type_args_in_const thy constrs type_enc ary s T_args
  1185         filter_type_args_in_const thy constrs type_enc ary s T_args
  1339 
  1342 
  1340 fun tvar_footprint thy s ary =
  1343 fun tvar_footprint thy s ary =
  1341   (case unprefix_and_unascii const_prefix s of
  1344   (case unprefix_and_unascii const_prefix s of
  1342      SOME s =>
  1345      SOME s =>
  1343      let fun tvars_of T = [] |> Term.add_tvarsT T |> map fst in
  1346      let fun tvars_of T = [] |> Term.add_tvarsT T |> map fst in
  1344        s |> invert_const |> robust_const_type thy |> chop_fun ary |> fst
  1347        s |> unmangled_invert_const |> robust_const_type thy |> chop_fun ary
  1345          |> map tvars_of
  1348          |> fst |> map tvars_of
  1346      end
  1349      end
  1347    | NONE => [])
  1350    | NONE => [])
  1348   handle TYPE _ => []
  1351   handle TYPE _ => []
  1349 
  1352 
  1350 fun type_arg_cover thy pos s ary =
  1353 fun type_arg_cover thy pos s ary =
  1549                       case unprefix_and_unascii const_prefix s of
  1552                       case unprefix_and_unascii const_prefix s of
  1550                         SOME s =>
  1553                         SOME s =>
  1551                         (if String.isSubstring uncurried_alias_sep s then
  1554                         (if String.isSubstring uncurried_alias_sep s then
  1552                            ary
  1555                            ary
  1553                          else case try (robust_const_ary thy
  1556                          else case try (robust_const_ary thy
  1554                                         o invert_const o hd
  1557                                         o unmangled_invert_const) s of
  1555                                         o unmangled_const_name) s of
       
  1556                            SOME ary0 => Int.min (ary0, ary)
  1558                            SOME ary0 => Int.min (ary0, ary)
  1557                          | NONE => ary)
  1559                          | NONE => ary)
  1558                       | NONE => ary
  1560                       | NONE => ary
  1559                     val min_ary =
  1561                     val min_ary =
  1560                       case app_op_level of
  1562                       case app_op_level of
  1593   case Symtab.lookup sym_tab s of
  1595   case Symtab.lookup sym_tab s of
  1594     SOME ({min_ary, ...} : sym_info) => min_ary
  1596     SOME ({min_ary, ...} : sym_info) => min_ary
  1595   | NONE =>
  1597   | NONE =>
  1596     case unprefix_and_unascii const_prefix s of
  1598     case unprefix_and_unascii const_prefix s of
  1597       SOME s =>
  1599       SOME s =>
  1598       let val s = s |> unmangled_const_name |> hd |> invert_const in
  1600       let val s = s |> unmangled_invert_const in
  1599         if s = predicator_name then 1
  1601         if s = predicator_name then 1
  1600         else if s = app_op_name then 2
  1602         else if s = app_op_name then 2
  1601         else if s = type_guard_name then 1
  1603         else if s = type_guard_name then 1
  1602         else 0
  1604         else 0
  1603       end
  1605       end
  1857 fun add_type_constrs_in_term thy =
  1859 fun add_type_constrs_in_term thy =
  1858   let
  1860   let
  1859     fun add (Const (@{const_name Meson.skolem}, _) $ _) = I
  1861     fun add (Const (@{const_name Meson.skolem}, _) $ _) = I
  1860       | add (t $ u) = add t #> add u
  1862       | add (t $ u) = add t #> add u
  1861       | add (Const x) =
  1863       | add (Const x) =
  1862         x |> robust_const_typargs thy |> fold (fold_type_constrs set_insert)
  1864         x |> robust_const_type_args thy |> fold (fold_type_constrs set_insert)
  1863       | add (Abs (_, _, u)) = add u
  1865       | add (Abs (_, _, u)) = add u
  1864       | add _ = I
  1866       | add _ = I
  1865   in add end
  1867   in add end
  1866 
  1868 
  1867 fun type_constrs_of_terms thy ts =
  1869 fun type_constrs_of_terms thy ts =
  2385       if null T_args then
  2387       if null T_args then
  2386         (T, [])
  2388         (T, [])
  2387       else case unprefix_and_unascii const_prefix s of
  2389       else case unprefix_and_unascii const_prefix s of
  2388         SOME s' =>
  2390         SOME s' =>
  2389         let
  2391         let
  2390           val s' = s' |> invert_const
  2392           val s' = s' |> unmangled_invert_const
  2391           val T = s' |> robust_const_type thy
  2393           val T = s' |> robust_const_type thy
  2392         in (T, robust_const_typargs thy (s', T)) end
  2394         in (T, robust_const_type_args thy (s', T)) end
  2393       | NONE => raise Fail "unexpected type arguments"
  2395       | NONE => raise Fail "unexpected type arguments"
  2394   in
  2396   in
  2395     Sym_Decl (sym_decl_prefix ^ s, (s, s'),
  2397     Sym_Decl (sym_decl_prefix ^ s, (s, s'),
  2396               T |> fused_type ctxt mono (level_of_type_enc type_enc) ary
  2398               T |> fused_type ctxt mono (level_of_type_enc type_enc) ary
  2397                 |> native_ho_type_from_typ type_enc pred_sym ary
  2399                 |> native_ho_type_from_typ type_enc pred_sym ary
  2520       let
  2522       let
  2521         val thy = Proof_Context.theory_of ctxt
  2523         val thy = Proof_Context.theory_of ctxt
  2522         val (role, maybe_negate) = honor_conj_sym_role in_conj
  2524         val (role, maybe_negate) = honor_conj_sym_role in_conj
  2523         val base_name = base_s0 |> `(make_fixed_const (SOME type_enc))
  2525         val base_name = base_s0 |> `(make_fixed_const (SOME type_enc))
  2524         val T = case types of [T] => T | _ => robust_const_type thy base_s0
  2526         val T = case types of [T] => T | _ => robust_const_type thy base_s0
  2525         val T_args = robust_const_typargs thy (base_s0, T)
  2527         val T_args = robust_const_type_args thy (base_s0, T)
  2526         val (base_name as (base_s, _), T_args) =
  2528         val (base_name as (base_s, _), T_args) =
  2527           mangle_type_args_in_const type_enc base_name T_args
  2529           mangle_type_args_in_const type_enc base_name T_args
  2528         val base_ary = min_ary_of sym_tab0 base_s
  2530         val base_ary = min_ary_of sym_tab0 base_s
  2529         fun do_const name = IConst (name, T, T_args)
  2531         fun do_const name = IConst (name, T, T_args)
  2530         val filter_ty_args = filter_type_args_in_iterm thy constrs type_enc
  2532         val filter_ty_args = filter_type_args_in_iterm thy constrs type_enc
  2562         sym_tab (s, {min_ary, types, in_conj, ...} : sym_info) =
  2564         sym_tab (s, {min_ary, types, in_conj, ...} : sym_info) =
  2563   case unprefix_and_unascii const_prefix s of
  2565   case unprefix_and_unascii const_prefix s of
  2564     SOME mangled_s =>
  2566     SOME mangled_s =>
  2565     if String.isSubstring uncurried_alias_sep mangled_s then
  2567     if String.isSubstring uncurried_alias_sep mangled_s then
  2566       let
  2568       let
  2567         val base_s0 = mangled_s |> unmangled_const_name |> hd |> invert_const
  2569         val base_s0 = mangled_s |> unmangled_invert_const
  2568       in
  2570       in
  2569         do_uncurried_alias_lines_for_sym ctxt constrs mono type_enc sym_tab0
  2571         do_uncurried_alias_lines_for_sym ctxt constrs mono type_enc sym_tab0
  2570                                          sym_tab base_s0 types in_conj min_ary
  2572                                          sym_tab base_s0 types in_conj min_ary
  2571       end
  2573       end
  2572     else
  2574     else