src/HOL/Tools/Sledgehammer/sledgehammer_atp_translate.ML
changeset 42546 8591fcc56c34
parent 42545 a14b602fb3d5
child 42547 b5eec0c99528
equal deleted inserted replaced
42545:a14b602fb3d5 42546:8591fcc56c34
   100   (member (op =) [@{const_name HOL.eq}] s orelse
   100   (member (op =) [@{const_name HOL.eq}] s orelse
   101    case type_sys of
   101    case type_sys of
   102      Many_Typed => false
   102      Many_Typed => false
   103    | Tags full_types => full_types orelse s = explicit_app_base
   103    | Tags full_types => full_types orelse s = explicit_app_base
   104    | Args _ => s = explicit_app_base
   104    | Args _ => s = explicit_app_base
   105    | Mangled _ => s = explicit_app_base
   105    | Mangled _ => false
   106    | No_Types => true)
   106    | No_Types => true)
   107 
   107 
   108 datatype type_arg_policy = No_Type_Args | Explicit_Type_Args | Mangled_Types
   108 datatype type_arg_policy = No_Type_Args | Explicit_Type_Args | Mangled_Types
   109 
   109 
   110 fun type_arg_policy type_sys s =
   110 fun type_arg_policy type_sys s =
   774        (SOME @{type_name fun}, [dom_ty, ran_ty]) =>
   774        (SOME @{type_name fun}, [dom_ty, ran_ty]) =>
   775        strip_and_map_combtyp (n - 1) f ran_ty |>> cons (f dom_ty)
   775        strip_and_map_combtyp (n - 1) f ran_ty |>> cons (f dom_ty)
   776      | _ => ([], f ty))
   776      | _ => ([], f ty))
   777   | strip_and_map_combtyp _ _ _ = raise Fail "unexpected non-function"
   777   | strip_and_map_combtyp _ _ _ = raise Fail "unexpected non-function"
   778 
   778 
   779 fun problem_line_for_const_entry ctxt type_sys sym_tab s (s', ty_args, ty) =
   779 fun problem_line_for_typed_const ctxt type_sys sym_tab s j (s', ty_args, ty) =
   780   let
   780   let
   781     val thy = Proof_Context.theory_of ctxt
   781     val thy = Proof_Context.theory_of ctxt
   782     val arity = min_arity_of thy type_sys sym_tab s
   782     val arity = min_arity_of thy type_sys sym_tab s
   783   in
   783   in
   784     if type_sys = Many_Typed then
   784     if type_sys = Many_Typed then
   785       let
   785       let
   786         val (arg_tys, res_ty) = strip_and_map_combtyp arity mangled_combtyp ty
   786         val (arg_tys, res_ty) = strip_and_map_combtyp arity mangled_combtyp ty
   787         val (s, s') = (s, s') |> mangled_const_name ty_args
   787         val (s, s') = (s, s') |> mangled_const_name ty_args
   788       in
   788       in
   789         Decl (sym_decl_prefix ^ ascii_of s, (s, s'), arg_tys,
   789         Decl (sym_decl_prefix ^ ascii_of s, (s, s'),
       
   790               arg_tys,
   790               if is_pred_sym sym_tab s then `I tff_bool_type else res_ty)
   791               if is_pred_sym sym_tab s then `I tff_bool_type else res_ty)
   791       end
   792       end
   792     else
   793     else
   793       let
   794       let
   794         val (arg_tys, res_ty) = strip_and_map_combtyp arity I ty
   795         val (arg_tys, res_ty) = strip_and_map_combtyp arity I ty
   795         val bounds =
   796         val bounds =
   796           map (`I o make_bound_var o string_of_int) (1 upto length arg_tys)
   797           map (`I o make_bound_var o string_of_int) (1 upto length arg_tys)
   797           ~~ map SOME arg_tys
   798           ~~ map SOME arg_tys
   798         val bound_tms =
   799         val bound_tms =
   799           map (fn (name, ty) => CombConst (name, the ty, [])) bounds
   800           map (fn (name, ty) => CombConst (name, the ty, [])) bounds
       
   801         val freshener =
       
   802           case type_sys of Args _ => string_of_int j ^ "_" | _ => ""
   800       in
   803       in
   801         Formula (Fof, sym_decl_prefix ^ ascii_of s, Axiom,
   804         Formula (Fof, sym_decl_prefix ^ freshener ^ "_" ^ ascii_of s, Axiom,
   802                  CombConst ((s, s'), ty, ty_args)
   805                  CombConst ((s, s'), ty, ty_args)
   803                  |> fold (curry (CombApp o swap)) bound_tms
   806                  |> fold (curry (CombApp o swap)) bound_tms
   804                  |> type_pred_combatom type_sys res_ty
   807                  |> type_pred_combatom type_sys res_ty
   805                  |> mk_aquant AForall bounds
   808                  |> mk_aquant AForall bounds
   806                  |> formula_for_combformula ctxt type_sys,
   809                  |> formula_for_combformula ctxt type_sys,
   807                  NONE, NONE)
   810                  NONE, NONE)
   808       end
   811       end
   809   end
   812   end
   810 fun problem_lines_for_const ctxt type_sys sym_tab (s, xs) =
   813 fun problem_lines_for_const ctxt type_sys sym_tab (s, xs) =
   811   map (problem_line_for_const_entry ctxt type_sys sym_tab s) xs
   814   map2 (problem_line_for_typed_const ctxt type_sys sym_tab s)
       
   815        (0 upto length xs - 1) xs
   812 
   816 
   813 fun add_tff_types_in_formula (AQuant (_, xs, phi)) =
   817 fun add_tff_types_in_formula (AQuant (_, xs, phi)) =
   814     union (op =) (map_filter snd xs) #> add_tff_types_in_formula phi
   818     union (op =) (map_filter snd xs) #> add_tff_types_in_formula phi
   815   | add_tff_types_in_formula (AConn (_, phis)) =
   819   | add_tff_types_in_formula (AConn (_, phis)) =
   816     fold add_tff_types_in_formula phis
   820     fold add_tff_types_in_formula phis