src/HOL/Tools/Metis/metis_reconstruct.ML
changeset 50875 bfb626265782
parent 48132 9aa0fad4e864
child 51701 1e29891759c4
equal deleted inserted replaced
50874:2eae85887282 50875:bfb626265782
     9 
     9 
    10 signature METIS_RECONSTRUCT =
    10 signature METIS_RECONSTRUCT =
    11 sig
    11 sig
    12   type type_enc = ATP_Problem_Generate.type_enc
    12   type type_enc = ATP_Problem_Generate.type_enc
    13 
    13 
    14   exception METIS of string * string
    14   exception METIS_RECONSTRUCT of string * string
    15 
    15 
    16   val hol_clause_from_metis :
    16   val hol_clause_from_metis :
    17     Proof.context -> type_enc -> int Symtab.table
    17     Proof.context -> type_enc -> int Symtab.table
    18     -> (string * term) list * (string * term) list -> Metis_Thm.thm -> term
    18     -> (string * term) list * (string * term) list -> Metis_Thm.thm -> term
    19   val lookth : (Metis_Thm.thm * 'a) list -> Metis_Thm.thm -> 'a
    19   val lookth : (Metis_Thm.thm * 'a) list -> Metis_Thm.thm -> 'a
    32 open ATP_Problem
    32 open ATP_Problem
    33 open ATP_Problem_Generate
    33 open ATP_Problem_Generate
    34 open ATP_Proof_Reconstruct
    34 open ATP_Proof_Reconstruct
    35 open Metis_Generate
    35 open Metis_Generate
    36 
    36 
    37 exception METIS of string * string
    37 exception METIS_RECONSTRUCT of string * string
    38 
    38 
    39 fun atp_name_from_metis type_enc s =
    39 fun atp_name_from_metis type_enc s =
    40   case find_first (fn (_, (f, _)) => f type_enc = s) metis_name_table of
    40   case find_first (fn (_, (f, _)) => f type_enc = s) metis_name_table of
    41     SOME ((s, _), (_, swap)) => (s, swap)
    41     SOME ((s, _), (_, swap)) => (s, swap)
    42   | _ => (s, false)
    42   | _ => (s, false)
   164         cat_lines ("subst_translations:" ::
   164         cat_lines ("subst_translations:" ::
   165           (substs' |> map (fn (x, y) =>
   165           (substs' |> map (fn (x, y) =>
   166             Syntax.string_of_term ctxt (term_of x) ^ " |-> " ^
   166             Syntax.string_of_term ctxt (term_of x) ^ " |-> " ^
   167             Syntax.string_of_term ctxt (term_of y)))));
   167             Syntax.string_of_term ctxt (term_of y)))));
   168   in cterm_instantiate substs' i_th end
   168   in cterm_instantiate substs' i_th end
   169   handle THM (msg, _, _) => raise METIS ("inst_inference", msg)
   169   handle THM (msg, _, _) => raise METIS_RECONSTRUCT ("inst_inference", msg)
   170        | ERROR msg => raise METIS ("inst_inference", msg)
   170        | ERROR msg => raise METIS_RECONSTRUCT ("inst_inference", msg)
   171 
   171 
   172 (* INFERENCE RULE: RESOLVE *)
   172 (* INFERENCE RULE: RESOLVE *)
   173 
   173 
   174 (*Increment the indexes of only the type variables*)
   174 (*Increment the indexes of only the type variables*)
   175 fun incr_type_indexes inc th =
   175 fun incr_type_indexes inc th =
   291              (trace_msg ctxt (fn () => "Failed to find literal in \"th2\"");
   291              (trace_msg ctxt (fn () => "Failed to find literal in \"th2\"");
   292               i_th2)
   292               i_th2)
   293            | j2 =>
   293            | j2 =>
   294              (trace_msg ctxt (fn () => "  index th2: " ^ string_of_int j2);
   294              (trace_msg ctxt (fn () => "  index th2: " ^ string_of_int j2);
   295               resolve_inc_tyvars thy (select_literal j1 i_th1) j2 i_th2
   295               resolve_inc_tyvars thy (select_literal j1 i_th1) j2 i_th2
   296               handle TERM (s, _) => raise METIS ("resolve_inference", s)))
   296               handle TERM (s, _) =>
       
   297                      raise METIS_RECONSTRUCT ("resolve_inference", s)))
   297       end
   298       end
   298   end
   299   end
   299 
   300 
   300 (* INFERENCE RULE: REFL *)
   301 (* INFERENCE RULE: REFL *)
   301 
   302 
   325         hol_terms_from_metis ctxt type_enc concealed sym_tab [m_tm, fr]
   326         hol_terms_from_metis ctxt type_enc concealed sym_tab [m_tm, fr]
   326       val _ = trace_msg ctxt (fn () => "sign of the literal: " ^ Bool.toString pos)
   327       val _ = trace_msg ctxt (fn () => "sign of the literal: " ^ Bool.toString pos)
   327       fun replace_item_list lx 0 (_::ls) = lx::ls
   328       fun replace_item_list lx 0 (_::ls) = lx::ls
   328         | replace_item_list lx i (l::ls) = l :: replace_item_list lx (i-1) ls
   329         | replace_item_list lx i (l::ls) = l :: replace_item_list lx (i-1) ls
   329       fun path_finder_fail tm ps t =
   330       fun path_finder_fail tm ps t =
   330         raise METIS ("equality_inference (path_finder)",
   331         raise METIS_RECONSTRUCT ("equality_inference (path_finder)",
   331                      "path = " ^ space_implode " " (map string_of_int ps) ^
   332                   "path = " ^ space_implode " " (map string_of_int ps) ^
   332                      " isa-term: " ^ Syntax.string_of_term ctxt tm ^
   333                   " isa-term: " ^ Syntax.string_of_term ctxt tm ^
   333                      (case t of
   334                   (case t of
   334                         SOME t => " fol-term: " ^ Metis_Term.toString t
   335                      SOME t => " fol-term: " ^ Metis_Term.toString t
   335                       | NONE => ""))
   336                    | NONE => ""))
   336       fun path_finder tm [] _ = (tm, Bound 0)
   337       fun path_finder tm [] _ = (tm, Bound 0)
   337         | path_finder tm (p :: ps) (t as Metis_Term.Fn (s, ts)) =
   338         | path_finder tm (p :: ps) (t as Metis_Term.Fn (s, ts)) =
   338           let
   339           let
   339             val s = s |> Metis_Name.toString
   340             val s = s |> Metis_Name.toString
   340                       |> perhaps (try (unprefix_and_unascii const_prefix
   341                       |> perhaps (try (unprefix_and_unascii const_prefix
   441         val tac = cut_tac th 1
   442         val tac = cut_tac th 1
   442                   THEN rewrite_goals_tac @{thms not_not [THEN eq_reflection]}
   443                   THEN rewrite_goals_tac @{thms not_not [THEN eq_reflection]}
   443                   THEN ALLGOALS assume_tac
   444                   THEN ALLGOALS assume_tac
   444       in
   445       in
   445         if length prems = length prems0 then
   446         if length prems = length prems0 then
   446           raise METIS ("resynchronize", "Out of sync")
   447           raise METIS_RECONSTRUCT ("resynchronize", "Out of sync")
   447         else
   448         else
   448           Goal.prove ctxt [] [] goal (K tac)
   449           Goal.prove ctxt [] [] goal (K tac)
   449           |> resynchronize ctxt fol_th
   450           |> resynchronize ctxt fol_th
   450       end
   451       end
   451   end
   452   end