src/HOL/Tools/Meson/meson.ML
changeset 47956 2a420750248b
parent 47954 aada9fd08b58
child 50695 cace30ea5a2c
equal deleted inserted replaced
47955:a2a821abab83 47956:2a420750248b
   572     skolemize_with_choice_theorems ctxt (choice_theorems thy)
   572     skolemize_with_choice_theorems ctxt (choice_theorems thy)
   573   end
   573   end
   574 
   574 
   575 exception NO_F_PATTERN of unit
   575 exception NO_F_PATTERN of unit
   576 
   576 
   577 fun get_F_pattern t u =
   577 fun get_F_pattern T t u =
   578   let
   578   let
   579     fun pat t u =
   579     fun pat t u =
   580       let
   580       let
   581         val ((head1, args1), (head2, args2)) = (t, u) |> pairself strip_comb
   581         val ((head1, args1), (head2, args2)) = (t, u) |> pairself strip_comb
   582       in
   582       in
   591           let val T = fastype_of t in
   591           let val T = fastype_of t in
   592             if can dest_funT T then (SOME T, Bound 0) else raise NO_F_PATTERN ()
   592             if can dest_funT T then (SOME T, Bound 0) else raise NO_F_PATTERN ()
   593           end
   593           end
   594       end
   594       end
   595   in
   595   in
   596     (case pat t u of
   596     if T = @{typ bool} then
   597        (SOME T, p as _ $ _) => SOME (Abs (Name.uu, T, p))
   597       NONE
   598      | _ => NONE)
   598     else case pat t u of
   599     handle NO_F_PATTERN () => NONE
   599       (SOME T, p as _ $ _) => SOME (Abs (Name.uu, T, p))
       
   600     | _ => NONE
   600   end
   601   end
       
   602   handle NO_F_PATTERN () => NONE
   601 
   603 
   602 val ext_cong_neq = @{thm ext_cong_neq}
   604 val ext_cong_neq = @{thm ext_cong_neq}
   603 val F_ext_cong_neq =
   605 val F_ext_cong_neq =
   604   Term.add_vars (prop_of @{thm ext_cong_neq}) []
   606   Term.add_vars (prop_of @{thm ext_cong_neq}) []
   605   |> filter (fn ((s, _), _) => s = "F")
   607   |> filter (fn ((s, _), _) => s = "F")
   606   |> the_single |> Var
   608   |> the_single |> Var
   607 
   609 
   608 (* Strengthens "f g ~= f h" to "f g ~= f h & (EX x. g x ~= h x)". *)
   610 (* Strengthens "f g ~= f h" to "f g ~= f h & (EX x. g x ~= h x)". *)
   609 fun cong_extensionalize_thm thy th =
   611 fun cong_extensionalize_thm thy th =
   610   case concl_of th of
   612   case concl_of th of
   611     @{const Trueprop} $ (@{const Not} $ (Const (@{const_name HOL.eq}, _)
   613     @{const Trueprop} $ (@{const Not}
   612                                          $ (t as _ $ _) $ (u as _ $ _))) =>
   614         $ (Const (@{const_name HOL.eq}, Type (_, [T, _]))
   613     (case get_F_pattern t u of
   615            $ (t as _ $ _) $ (u as _ $ _))) =>
       
   616     (case get_F_pattern T t u of
   614        SOME p =>
   617        SOME p =>
   615        let val inst = [pairself (cterm_of thy) (F_ext_cong_neq, p)] in
   618        let val inst = [pairself (cterm_of thy) (F_ext_cong_neq, p)] in
   616          th RS cterm_instantiate inst ext_cong_neq
   619          th RS cterm_instantiate inst ext_cong_neq
   617        end
   620        end
   618      | NONE => th)
   621      | NONE => th)