src/HOL/Tools/Metis/metis_reconstruct.ML
changeset 70516 60005f96d232
parent 70515 c04e2426f319
child 70518 bf5724694ce5
equal deleted inserted replaced
70515:c04e2426f319 70516:60005f96d232
   178   end
   178   end
   179 
   179 
   180 (*Like RSN, but we rename apart only the type variables. Vars here typically
   180 (*Like RSN, but we rename apart only the type variables. Vars here typically
   181   have an index of 1, and the use of RSN would increase this typically to 3.
   181   have an index of 1, and the use of RSN would increase this typically to 3.
   182   Instantiations of those Vars could then fail.*)
   182   Instantiations of those Vars could then fail.*)
   183 fun resolve_inc_tyvars ctxt tha i thb =
   183 fun resolve_inc_tyvars ctxt th1 i th2 =
   184   let
   184   let
   185     val tha = incr_type_indexes ctxt (Thm.maxidx_of thb + 1) tha
   185     val th1' = incr_type_indexes ctxt (Thm.maxidx_of th2 + 1) th1
   186     fun res (tha, thb) =
   186     fun res (tha, thb) =
   187       (case Thm.bicompose (SOME ctxt) {flatten = true, match = false, incremented = true}
   187       (case Thm.bicompose (SOME ctxt) {flatten = true, match = false, incremented = true}
   188             (false, tha, Thm.nprems_of tha) i thb
   188             (false, tha, Thm.nprems_of tha) i thb
   189            |> Seq.list_of |> distinct Thm.eq_thm of
   189            |> Seq.list_of |> distinct Thm.eq_thm of
   190         [th] => th
   190         [th] => th
   197             raise THM ("resolve_inc_tyvars: unique result expected", i, [tha, thb])
   197             raise THM ("resolve_inc_tyvars: unique result expected", i, [tha, thb])
   198           else
   198           else
   199             res (tha', thb')
   199             res (tha', thb')
   200         end)
   200         end)
   201   in
   201   in
   202     res (tha, thb)
   202     res (th1', th2)
   203     handle TERM z =>
   203     handle TERM z =>
   204       let
   204       let
   205         val ps = []
   205         val ps = []
   206           |> fold (Term.add_vars o Thm.prop_of) [tha, thb]
   206           |> fold (Term.add_vars o Thm.prop_of) [th1', th2]
   207           |> AList.group (op =)
   207           |> AList.group (op =)
   208           |> maps (fn ((s, _), T :: Ts) => map (fn T' => (Free (s, T), Free (s, T'))) Ts)
   208           |> maps (fn ((s, _), T :: Ts) => map (fn T' => (Free (s, T), Free (s, T'))) Ts)
   209           |> rpair Envir.init
   209           |> rpair Envir.init
   210           |-> fold (Pattern.unify (Context.Proof ctxt))
   210           |-> fold (Pattern.unify (Context.Proof ctxt))
   211           |> Envir.type_env |> Vartab.dest
   211           |> Envir.type_env |> Vartab.dest
   215           "?a::?'a" with "?a::?'b" or "?a::nat" and throw a "TERM" exception (with "add_ffpair" as
   215           "?a::?'a" with "?a::?'b" or "?a::nat" and throw a "TERM" exception (with "add_ffpair" as
   216           first argument). We then perform unification of the types of variables by hand and try
   216           first argument). We then perform unification of the types of variables by hand and try
   217           again. We could do this the first time around but this error occurs seldom and we don't
   217           again. We could do this the first time around but this error occurs seldom and we don't
   218           want to break existing proofs in subtle ways or slow them down.*)
   218           want to break existing proofs in subtle ways or slow them down.*)
   219         if null ps then raise TERM z
   219         if null ps then raise TERM z
   220         else res (apply2 (Drule.instantiate_normalize (ps, [])) (tha, thb))
   220         else res (apply2 (Drule.instantiate_normalize (ps, [])) (th1', th2))
   221       end
   221       end
   222   end
   222   end
   223 
   223 
   224 fun s_not (\<^const>\<open>Not\<close> $ t) = t
   224 fun s_not (\<^const>\<open>Not\<close> $ t) = t
   225   | s_not t = HOLogic.mk_not t
   225   | s_not t = HOLogic.mk_not t