src/HOL/Tools/ATP/atp_translate.ML
changeset 43130 d73fc2e55308
parent 43129 4301f1c123d6
child 43136 cf5cda219058
equal deleted inserted replaced
43129:4301f1c123d6 43130:d73fc2e55308
    78   val predicator_name : string
    78   val predicator_name : string
    79   val app_op_name : string
    79   val app_op_name : string
    80   val type_tag_name : string
    80   val type_tag_name : string
    81   val type_pred_name : string
    81   val type_pred_name : string
    82   val simple_type_prefix : string
    82   val simple_type_prefix : string
       
    83   val prefixed_app_op_name : string
       
    84   val prefixed_type_tag_name : string
    83   val ascii_of: string -> string
    85   val ascii_of: string -> string
    84   val unascii_of: string -> string
    86   val unascii_of: string -> string
    85   val strip_prefix_and_unascii : string -> string -> string option
    87   val strip_prefix_and_unascii : string -> string -> string option
    86   val proxify_const : string -> (int * (string * string)) option
    88   val proxify_const : string -> (int * (string * string)) option
    87   val invert_const: string -> string
    89   val invert_const: string -> string
   111   val level_of_type_sys : type_sys -> type_level
   113   val level_of_type_sys : type_sys -> type_level
   112   val is_type_sys_virtually_sound : type_sys -> bool
   114   val is_type_sys_virtually_sound : type_sys -> bool
   113   val is_type_sys_fairly_sound : type_sys -> bool
   115   val is_type_sys_fairly_sound : type_sys -> bool
   114   val choose_format : format list -> type_sys -> format * type_sys
   116   val choose_format : format list -> type_sys -> format * type_sys
   115   val raw_type_literals_for_types : typ list -> type_literal list
   117   val raw_type_literals_for_types : typ list -> type_literal list
       
   118   val unmangled_const_name : string -> string
   116   val unmangled_const : string -> string * string fo_term list
   119   val unmangled_const : string -> string * string fo_term list
   117   val translate_atp_fact :
   120   val translate_atp_fact :
   118     Proof.context -> format -> type_sys -> bool -> (string * locality) * thm
   121     Proof.context -> format -> type_sys -> bool -> (string * locality) * thm
   119     -> translated_formula option * ((string * locality) * thm)
   122     -> translated_formula option * ((string * locality) * thm)
   120   val helper_table : (string * (bool * thm list)) list
   123   val helper_table : (string * (bool * thm list)) list
   186 val predicator_name = "hBOOL"
   189 val predicator_name = "hBOOL"
   187 val app_op_name = "hAPP"
   190 val app_op_name = "hAPP"
   188 val type_tag_name = "ti"
   191 val type_tag_name = "ti"
   189 val type_pred_name = "is"
   192 val type_pred_name = "is"
   190 val simple_type_prefix = "ty_"
   193 val simple_type_prefix = "ty_"
       
   194 
       
   195 val prefixed_app_op_name = const_prefix ^ app_op_name
       
   196 val prefixed_type_tag_name = const_prefix ^ type_tag_name
   191 
   197 
   192 (* Freshness almost guaranteed! *)
   198 (* Freshness almost guaranteed! *)
   193 val sledgehammer_weak_prefix = "Sledgehammer:"
   199 val sledgehammer_weak_prefix = "Sledgehammer:"
   194 
   200 
   195 (*Escaping of special characters.
   201 (*Escaping of special characters.
  1136     if is_pred_sym sym_tab s then tm else predicator tm
  1142     if is_pred_sym sym_tab s then tm else predicator tm
  1137   | _ => predicator tm
  1143   | _ => predicator tm
  1138 
  1144 
  1139 fun list_app head args = fold (curry (CombApp o swap)) args head
  1145 fun list_app head args = fold (curry (CombApp o swap)) args head
  1140 
  1146 
       
  1147 val app_op = `make_fixed_const app_op_name
       
  1148 
  1141 fun explicit_app arg head =
  1149 fun explicit_app arg head =
  1142   let
  1150   let
  1143     val head_T = combtyp_of head
  1151     val head_T = combtyp_of head
  1144     val (arg_T, res_T) = dest_funT head_T
  1152     val (arg_T, res_T) = dest_funT head_T
  1145     val explicit_app =
  1153     val explicit_app =
  1146       CombConst (`make_fixed_const app_op_name, head_T --> head_T,
  1154       CombConst (app_op, head_T --> head_T, [arg_T, res_T])
  1147                  [arg_T, res_T])
       
  1148   in list_app explicit_app [head, arg] end
  1155   in list_app explicit_app [head, arg] end
  1149 fun list_explicit_app head args = fold explicit_app args head
  1156 fun list_explicit_app head args = fold explicit_app args head
  1150 
  1157 
  1151 fun introduce_explicit_apps_in_combterm sym_tab =
  1158 fun introduce_explicit_apps_in_combterm sym_tab =
  1152   let
  1159   let
  1199           val (T, T_args) =
  1206           val (T, T_args) =
  1200             (* Aggressively merge most "hAPPs" if the type system is unsound
  1207             (* Aggressively merge most "hAPPs" if the type system is unsound
  1201                anyway, by distinguishing overloads only on the homogenized
  1208                anyway, by distinguishing overloads only on the homogenized
  1202                result type. Don't do it for lightweight type systems, though,
  1209                result type. Don't do it for lightweight type systems, though,
  1203                since it leads to too many unsound proofs. *)
  1210                since it leads to too many unsound proofs. *)
  1204             if s = const_prefix ^ app_op_name andalso
  1211             if s = prefixed_app_op_name andalso length T_args = 2 andalso
  1205                length T_args = 2 andalso
       
  1206                not (is_type_sys_virtually_sound type_sys) andalso
  1212                not (is_type_sys_virtually_sound type_sys) andalso
  1207                heaviness_of_type_sys type_sys = Heavyweight then
  1213                heaviness_of_type_sys type_sys = Heavyweight then
  1208               T_args |> map (homogenized_type ctxt nonmono_Ts level 0)
  1214               T_args |> map (homogenized_type ctxt nonmono_Ts level 0)
  1209                      |> (fn Ts => let val T = hd Ts --> nth Ts 1 in
  1215                      |> (fn Ts => let val T = hd Ts --> nth Ts 1 in
  1210                                     (T --> T, tl Ts)
  1216                                     (T --> T, tl Ts)
  1275     (false, @{lemma "P | fimplies P Q" "~ Q | fimplies P Q"
  1281     (false, @{lemma "P | fimplies P Q" "~ Q | fimplies P Q"
  1276                     "~ fimplies P Q | ~ P | Q"
  1282                     "~ fimplies P Q | ~ P | Q"
  1277                 by (unfold fimplies_def) fast+})),
  1283                 by (unfold fimplies_def) fast+})),
  1278    ("If", (true, @{thms if_True if_False True_or_False}))]
  1284    ("If", (true, @{thms if_True if_False True_or_False}))]
  1279 
  1285 
       
  1286 val type_tag = `make_fixed_const type_tag_name
       
  1287 
  1280 fun ti_ti_helper_fact () =
  1288 fun ti_ti_helper_fact () =
  1281   let
  1289   let
  1282     fun var s = ATerm (`I s, [])
  1290     fun var s = ATerm (`I s, [])
  1283     fun tag tm = ATerm (`make_fixed_const type_tag_name, [var "X", tm])
  1291     fun tag tm = ATerm (type_tag, [var "X", tm])
  1284   in
  1292   in
  1285     Formula (helper_prefix ^ "ti_ti", Axiom,
  1293     Formula (helper_prefix ^ "ti_ti", Axiom,
  1286              AAtom (ATerm (`I tptp_equal, [tag (tag (var "Y")), tag (var "Y")]))
  1294              AAtom (ATerm (`I tptp_equal, [tag (tag (var "Y")), tag (var "Y")]))
  1287              |> close_formula_universally, simp_info, NONE)
  1295              |> close_formula_universally, simp_info, NONE)
  1288   end
  1296   end
  1400   | fo_literal_from_type_literal (TyLitFree (class, name)) =
  1408   | fo_literal_from_type_literal (TyLitFree (class, name)) =
  1401     (true, ATerm (class, [ATerm (name, [])]))
  1409     (true, ATerm (class, [ATerm (name, [])]))
  1402 
  1410 
  1403 fun formula_from_fo_literal (pos, t) = AAtom t |> not pos ? mk_anot
  1411 fun formula_from_fo_literal (pos, t) = AAtom t |> not pos ? mk_anot
  1404 
  1412 
       
  1413 val type_pred = `make_fixed_const type_pred_name
       
  1414 
  1405 fun type_pred_combterm ctxt nonmono_Ts type_sys T tm =
  1415 fun type_pred_combterm ctxt nonmono_Ts type_sys T tm =
  1406   CombApp (CombConst (`make_fixed_const type_pred_name, T --> @{typ bool}, [T])
  1416   CombApp (CombConst (type_pred, T --> @{typ bool}, [T])
  1407            |> enforce_type_arg_policy_in_combterm ctxt nonmono_Ts type_sys,
  1417            |> enforce_type_arg_policy_in_combterm ctxt nonmono_Ts type_sys,
  1408            tm)
  1418            tm)
  1409 
  1419 
  1410 fun var_occurs_positively_naked_in_term _ (SOME false) _ accum = accum
  1420 fun var_occurs_positively_naked_in_term _ (SOME false) _ accum = accum
  1411   | var_occurs_positively_naked_in_term name _ (ATerm ((s, _), tms)) accum =
  1421   | var_occurs_positively_naked_in_term name _ (ATerm ((s, _), tms)) accum =
  1416 
  1426 
  1417 fun mk_const_aterm x T_args args =
  1427 fun mk_const_aterm x T_args args =
  1418   ATerm (x, map (fo_term_from_typ false) T_args @ args)
  1428   ATerm (x, map (fo_term_from_typ false) T_args @ args)
  1419 
  1429 
  1420 fun tag_with_type ctxt format nonmono_Ts type_sys T tm =
  1430 fun tag_with_type ctxt format nonmono_Ts type_sys T tm =
  1421   CombConst (`make_fixed_const type_tag_name, T --> T, [T])
  1431   CombConst (type_tag, T --> T, [T])
  1422   |> enforce_type_arg_policy_in_combterm ctxt nonmono_Ts type_sys
  1432   |> enforce_type_arg_policy_in_combterm ctxt nonmono_Ts type_sys
  1423   |> term_from_combterm ctxt format nonmono_Ts type_sys Top_Level
  1433   |> term_from_combterm ctxt format nonmono_Ts type_sys Top_Level
  1424   |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm]))
  1434   |> (fn ATerm (s, tms) => ATerm (s, tms @ [tm]))
  1425 and term_from_combterm ctxt format nonmono_Ts type_sys =
  1435 and term_from_combterm ctxt format nonmono_Ts type_sys =
  1426   let
  1436   let