src/HOL/Tools/ATP/atp_translate.ML
changeset 45377 8a3220581a62
parent 45364 d00339ae7fff
child 45401 36478a5f6104
equal deleted inserted replaced
45376:4b3caf1701a0 45377:8a3220581a62
   775       | add_formula_vars bounds (AConn (_, phis)) =
   775       | add_formula_vars bounds (AConn (_, phis)) =
   776         fold (add_formula_vars bounds) phis
   776         fold (add_formula_vars bounds) phis
   777       | add_formula_vars bounds (AAtom tm) = add_term_vars bounds tm
   777       | add_formula_vars bounds (AAtom tm) = add_term_vars bounds tm
   778   in mk_aquant AForall (add_formula_vars [] phi []) phi end
   778   in mk_aquant AForall (add_formula_vars [] phi []) phi end
   779 
   779 
   780 fun add_term_vars type_enc =
   780 fun add_term_vars bounds (ATerm (name as (s, _), tms)) =
   781   let
   781     (if is_tptp_variable s andalso
   782     fun vars bounds (ATerm (name as (s, _), tms)) =
   782         not (String.isPrefix tvar_prefix s) andalso
   783         (if is_tptp_variable s andalso
   783         not (member (op =) bounds name) then
   784             not (String.isPrefix tvar_prefix s) andalso
   784        insert (op =) (name, NONE)
   785             not (member (op =) bounds name) then
   785      else
   786            insert (op =) (name, NONE)
   786        I)
   787          else
   787     #> fold (add_term_vars bounds) tms
   788            I)
   788   | add_term_vars bounds (AAbs ((name, _), tm)) =
   789         #> fold (vars bounds) tms
   789     add_term_vars (name :: bounds) tm
   790       | vars bounds (AAbs ((name, _), tm)) = vars (name :: bounds) tm
   790 val close_formula_universally = close_universally add_term_vars
   791   in vars end
       
   792 fun close_formula_universally type_enc =
       
   793   close_universally (add_term_vars type_enc)
       
   794 
   791 
   795 fun add_iterm_vars bounds (IApp (tm1, tm2)) =
   792 fun add_iterm_vars bounds (IApp (tm1, tm2)) =
   796     fold (add_iterm_vars bounds) [tm1, tm2]
   793     fold (add_iterm_vars bounds) [tm1, tm2]
   797   | add_iterm_vars _ (IConst _) = I
   794   | add_iterm_vars _ (IConst _) = I
   798   | add_iterm_vars bounds (IVar (name, T)) =
   795   | add_iterm_vars bounds (IVar (name, T)) =
  1539                       | _ => NONE) Ts)
  1536                       | _ => NONE) Ts)
  1540 
  1537 
  1541 fun eq_formula type_enc atomic_Ts pred_sym tm1 tm2 =
  1538 fun eq_formula type_enc atomic_Ts pred_sym tm1 tm2 =
  1542   (if pred_sym then AConn (AIff, [AAtom tm1, AAtom tm2])
  1539   (if pred_sym then AConn (AIff, [AAtom tm1, AAtom tm2])
  1543    else AAtom (ATerm (`I tptp_equal, [tm1, tm2])))
  1540    else AAtom (ATerm (`I tptp_equal, [tm1, tm2])))
  1544   |> close_formula_universally type_enc
  1541   |> close_formula_universally
  1545   |> bound_tvars type_enc atomic_Ts
  1542   |> bound_tvars type_enc atomic_Ts
  1546 
  1543 
  1547 val type_tag = `(make_fixed_const NONE) type_tag_name
  1544 val type_tag = `(make_fixed_const NONE) type_tag_name
  1548 
  1545 
  1549 fun type_tag_idempotence_fact format type_enc =
  1546 fun type_tag_idempotence_fact format type_enc =
  1827   (prefix ^ (if freshen then string_of_int j ^ "_" else "") ^ encode name, kind,
  1824   (prefix ^ (if freshen then string_of_int j ^ "_" else "") ^ encode name, kind,
  1828    iformula
  1825    iformula
  1829    |> formula_from_iformula ctxt format mono type_enc
  1826    |> formula_from_iformula ctxt format mono type_enc
  1830                             should_guard_var_in_formula
  1827                             should_guard_var_in_formula
  1831                             (if pos then SOME true else NONE)
  1828                             (if pos then SOME true else NONE)
  1832    |> close_formula_universally type_enc
  1829    |> close_formula_universally
  1833    |> bound_tvars type_enc atomic_types,
  1830    |> bound_tvars type_enc atomic_types,
  1834    NONE,
  1831    NONE,
  1835    case locality of
  1832    case locality of
  1836      Intro => isabelle_info format introN
  1833      Intro => isabelle_info format introN
  1837    | Elim => isabelle_info format elimN
  1834    | Elim => isabelle_info format elimN
  1844   let val ty_arg = ATerm (tvar_a_name, []) in
  1841   let val ty_arg = ATerm (tvar_a_name, []) in
  1845     Formula (class_rel_clause_prefix ^ ascii_of name, Axiom,
  1842     Formula (class_rel_clause_prefix ^ ascii_of name, Axiom,
  1846              AConn (AImplies,
  1843              AConn (AImplies,
  1847                     [type_class_formula type_enc subclass ty_arg,
  1844                     [type_class_formula type_enc subclass ty_arg,
  1848                      type_class_formula type_enc superclass ty_arg])
  1845                      type_class_formula type_enc superclass ty_arg])
  1849              |> close_formula_universally type_enc,
  1846              |> close_formula_universally,
  1850              isabelle_info format introN, NONE)
  1847              isabelle_info format introN, NONE)
  1851   end
  1848   end
  1852 
  1849 
  1853 fun formula_from_arity_atom type_enc (class, t, args) =
  1850 fun formula_from_arity_atom type_enc (class, t, args) =
  1854   ATerm (t, map (fn arg => ATerm (arg, [])) args)
  1851   ATerm (t, map (fn arg => ATerm (arg, [])) args)
  1867         ({name, kind, iformula, atomic_types, ...} : translated_formula) =
  1864         ({name, kind, iformula, atomic_types, ...} : translated_formula) =
  1868   Formula (conjecture_prefix ^ name, kind,
  1865   Formula (conjecture_prefix ^ name, kind,
  1869            iformula
  1866            iformula
  1870            |> formula_from_iformula ctxt format mono type_enc
  1867            |> formula_from_iformula ctxt format mono type_enc
  1871                   should_guard_var_in_formula (SOME false)
  1868                   should_guard_var_in_formula (SOME false)
  1872            |> close_formula_universally type_enc
  1869            |> close_formula_universally
  1873            |> bound_tvars type_enc atomic_types, NONE, NONE)
  1870            |> bound_tvars type_enc atomic_types, NONE, NONE)
  1874 
  1871 
  1875 fun formula_line_for_free_type j phi =
  1872 fun formula_line_for_free_type j phi =
  1876   Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, phi, NONE, NONE)
  1873   Formula (tfree_clause_prefix ^ string_of_int j, Hypothesis, phi, NONE, NONE)
  1877 fun formula_lines_for_free_types type_enc (facts : translated_formula list) =
  1874 fun formula_lines_for_free_types type_enc (facts : translated_formula list) =
  2058            IConst (`make_bound_var "X", T, [])
  2055            IConst (`make_bound_var "X", T, [])
  2059            |> type_guard_iterm format type_enc T
  2056            |> type_guard_iterm format type_enc T
  2060            |> AAtom
  2057            |> AAtom
  2061            |> formula_from_iformula ctxt format mono type_enc
  2058            |> formula_from_iformula ctxt format mono type_enc
  2062                                     (K (K (K (K (K (K true)))))) (SOME true)
  2059                                     (K (K (K (K (K (K true)))))) (SOME true)
  2063            |> close_formula_universally type_enc
  2060            |> close_formula_universally
  2064            |> bound_tvars type_enc (atomic_types_of T),
  2061            |> bound_tvars type_enc (atomic_types_of T),
  2065            isabelle_info format introN, NONE)
  2062            isabelle_info format introN, NONE)
  2066 
  2063 
  2067 fun formula_line_for_tags_mono_type ctxt format mono type_enc T =
  2064 fun formula_line_for_tags_mono_type ctxt format mono type_enc T =
  2068   let val x_var = ATerm (`make_bound_var "X", []) in
  2065   let val x_var = ATerm (`make_bound_var "X", []) in
  2141              |> fold (curry (IApp o swap)) bounds
  2138              |> fold (curry (IApp o swap)) bounds
  2142              |> type_guard_iterm format type_enc res_T
  2139              |> type_guard_iterm format type_enc res_T
  2143              |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts)
  2140              |> AAtom |> mk_aquant AForall (bound_names ~~ bound_Ts)
  2144              |> formula_from_iformula ctxt format mono type_enc
  2141              |> formula_from_iformula ctxt format mono type_enc
  2145                                       (K (K (K (K (K (K true)))))) (SOME true)
  2142                                       (K (K (K (K (K (K true)))))) (SOME true)
  2146              |> close_formula_universally type_enc
  2143              |> close_formula_universally
  2147              |> n > 1 ? bound_tvars type_enc (atomic_types_of T)
  2144              |> n > 1 ? bound_tvars type_enc (atomic_types_of T)
  2148              |> maybe_negate,
  2145              |> maybe_negate,
  2149              isabelle_info format introN, NONE)
  2146              isabelle_info format introN, NONE)
  2150   end
  2147   end
  2151 
  2148