src/HOL/Statespace/distinct_tree_prover.ML
author haftmann
Sun Oct 08 22:28:22 2017 +0200 (23 months ago)
changeset 66816 212a3334e7da
parent 62913 13252110a6fe
child 69597 ff784d5a5bfb
permissions -rw-r--r--
more fundamental definition of div and mod on int
wenzelm@29269
     1
(*  Title:      HOL/Statespace/distinct_tree_prover.ML
schirmer@25171
     2
    Author:     Norbert Schirmer, TU Muenchen
schirmer@25171
     3
*)
schirmer@25171
     4
schirmer@25408
     5
signature DISTINCT_TREE_PROVER =
schirmer@25408
     6
sig
wenzelm@45355
     7
  datatype direction = Left | Right
wenzelm@29302
     8
  val mk_tree : ('a -> term) -> typ -> 'a list -> term
wenzelm@29302
     9
  val dest_tree : term -> term list
wenzelm@45355
    10
  val find_tree : term -> term -> direction list option
schirmer@25408
    11
wenzelm@29302
    12
  val neq_to_eq_False : thm
wenzelm@60327
    13
  val distinctTreeProver : Proof.context -> thm -> direction list -> direction list -> thm
wenzelm@45355
    14
  val neq_x_y : Proof.context -> term -> term -> string -> thm option
wenzelm@29302
    15
  val distinctFieldSolver : string list -> solver
wenzelm@42368
    16
  val distinctTree_tac : string list -> Proof.context -> int -> tactic
wenzelm@60327
    17
  val distinct_implProver : Proof.context -> thm -> cterm -> thm
wenzelm@60327
    18
  val subtractProver : Proof.context -> term -> cterm -> thm -> thm
wenzelm@29302
    19
  val distinct_simproc : string list -> simproc
wenzelm@45355
    20
wenzelm@60639
    21
  val discharge : Proof.context -> thm list -> thm -> thm
schirmer@25408
    22
end;
schirmer@25408
    23
schirmer@25408
    24
structure DistinctTreeProver : DISTINCT_TREE_PROVER =
schirmer@25171
    25
struct
wenzelm@39159
    26
wenzelm@45356
    27
val neq_to_eq_False = @{thm neq_to_eq_False};
schirmer@25171
    28
wenzelm@45355
    29
datatype direction = Left | Right;
schirmer@25408
    30
wenzelm@45355
    31
fun treeT T = Type (@{type_name tree}, [T]);
wenzelm@45740
    32
wenzelm@45355
    33
fun mk_tree' e T n [] = Const (@{const_name Tip}, treeT T)
schirmer@25171
    34
  | mk_tree' e T n xs =
schirmer@25171
    35
     let
schirmer@25171
    36
       val m = (n - 1) div 2;
schirmer@25171
    37
       val (xsl,x::xsr) = chop m xs;
schirmer@25171
    38
       val l = mk_tree' e T m xsl;
schirmer@25171
    39
       val r = mk_tree' e T (n-(m+1)) xsr;
wenzelm@45355
    40
     in
wenzelm@45355
    41
       Const (@{const_name Node}, treeT T --> T --> HOLogic.boolT--> treeT T --> treeT T) $
wenzelm@45740
    42
         l $ e x $ @{term False} $ r
schirmer@25171
    43
     end
schirmer@25171
    44
wenzelm@45355
    45
fun mk_tree e T xs = mk_tree' e T (length xs) xs;
schirmer@25171
    46
wenzelm@45355
    47
fun dest_tree (Const (@{const_name Tip}, _)) = []
wenzelm@45355
    48
  | dest_tree (Const (@{const_name Node}, _) $ l $ e $ _ $ r) = dest_tree l @ e :: dest_tree r
wenzelm@45355
    49
  | dest_tree t = raise TERM ("dest_tree", [t]);
schirmer@25171
    50
schirmer@25408
    51
schirmer@25171
    52
wenzelm@45355
    53
fun lin_find_tree e (Const (@{const_name Tip}, _)) = NONE
wenzelm@45355
    54
  | lin_find_tree e (Const (@{const_name Node}, _) $ l $ x $ _ $ r) =
wenzelm@45355
    55
      if e aconv x
schirmer@25171
    56
      then SOME []
wenzelm@45355
    57
      else
wenzelm@45355
    58
        (case lin_find_tree e l of
wenzelm@45355
    59
          SOME path => SOME (Left :: path)
wenzelm@45355
    60
        | NONE =>
wenzelm@45355
    61
            (case lin_find_tree e r of
wenzelm@45355
    62
              SOME path => SOME (Right :: path)
wenzelm@45355
    63
            | NONE => NONE))
wenzelm@45355
    64
  | lin_find_tree e t = raise TERM ("find_tree: input not a tree", [t])
schirmer@25171
    65
wenzelm@45355
    66
fun bin_find_tree order e (Const (@{const_name Tip}, _)) = NONE
wenzelm@45355
    67
  | bin_find_tree order e (Const (@{const_name Node}, _) $ l $ x $ _ $ r) =
wenzelm@45355
    68
      (case order (e, x) of
wenzelm@45355
    69
        EQUAL => SOME []
wenzelm@45355
    70
      | LESS => Option.map (cons Left) (bin_find_tree order e l)
wenzelm@45355
    71
      | GREATER => Option.map (cons Right) (bin_find_tree order e r))
wenzelm@45355
    72
  | bin_find_tree order e t = raise TERM ("find_tree: input not a tree", [t])
schirmer@25171
    73
schirmer@25171
    74
fun find_tree e t =
wenzelm@35408
    75
  (case bin_find_tree Term_Ord.fast_term_ord e t of
wenzelm@45355
    76
    NONE => lin_find_tree e t
wenzelm@45355
    77
  | x => x);
wenzelm@45355
    78
schirmer@25171
    79
wenzelm@45355
    80
fun split_common_prefix xs [] = ([], xs, [])
wenzelm@45355
    81
  | split_common_prefix [] ys = ([], [], ys)
wenzelm@45355
    82
  | split_common_prefix (xs as (x :: xs')) (ys as (y :: ys')) =
wenzelm@45355
    83
      if x = y
wenzelm@45355
    84
      then let val (ps, xs'', ys'') = split_common_prefix xs' ys' in (x :: ps, xs'', ys'') end
wenzelm@45355
    85
      else ([], xs, ys)
schirmer@25171
    86
schirmer@25171
    87
schirmer@25171
    88
(* Wrapper around Thm.instantiate. The type instiations of instTs are applied to
schirmer@25171
    89
 * the right hand sides of insts
schirmer@25171
    90
 *)
wenzelm@60327
    91
fun instantiate ctxt instTs insts =
schirmer@25171
    92
  let
wenzelm@59582
    93
    val instTs' = map (fn (T, U) => (dest_TVar (Thm.typ_of T), Thm.typ_of U)) instTs;
schirmer@25171
    94
    fun substT x = (case AList.lookup (op =) instTs' x of NONE => TVar x | SOME T' => T');
schirmer@25171
    95
    fun mapT_and_recertify ct =
wenzelm@60327
    96
      (Thm.cterm_of ctxt (Term.map_types (Term.map_type_tvar substT) (Thm.term_of ct)));
schirmer@25171
    97
    val insts' = map (apfst mapT_and_recertify) insts;
wenzelm@60642
    98
  in
wenzelm@60642
    99
    Thm.instantiate
wenzelm@60642
   100
     (map (apfst (dest_TVar o Thm.typ_of)) instTs,
wenzelm@60642
   101
      map (apfst (dest_Var o Thm.term_of)) insts')
wenzelm@60642
   102
  end;
schirmer@25171
   103
wenzelm@51701
   104
fun tvar_clash ixn S S' =
wenzelm@51701
   105
  raise TYPE ("Type variable has two distinct sorts", [TVar (ixn, S), TVar (ixn, S')], []);
schirmer@25171
   106
schirmer@25171
   107
fun lookup (tye, (ixn, S)) =
schirmer@25171
   108
  (case AList.lookup (op =) tye ixn of
schirmer@25171
   109
    NONE => NONE
schirmer@25171
   110
  | SOME (S', T) => if S = S' then SOME T else tvar_clash ixn S S');
schirmer@25171
   111
schirmer@25171
   112
val naive_typ_match =
schirmer@25171
   113
  let
schirmer@25171
   114
    fun match (TVar (v, S), T) subs =
schirmer@25171
   115
          (case lookup (subs, (v, S)) of
schirmer@25171
   116
            NONE => ((v, (S, T))::subs)
schirmer@25171
   117
          | SOME _ => subs)
schirmer@25171
   118
      | match (Type (a, Ts), Type (b, Us)) subs =
schirmer@25171
   119
          if a <> b then raise Type.TYPE_MATCH
schirmer@25171
   120
          else matches (Ts, Us) subs
schirmer@25171
   121
      | match (TFree x, TFree y) subs =
schirmer@25171
   122
          if x = y then subs else raise Type.TYPE_MATCH
schirmer@25171
   123
      | match _ _ = raise Type.TYPE_MATCH
schirmer@25171
   124
    and matches (T :: Ts, U :: Us) subs = matches (Ts, Us) (match (T, U) subs)
schirmer@25171
   125
      | matches _ subs = subs;
schirmer@25171
   126
  in match end;
schirmer@25171
   127
schirmer@25171
   128
wenzelm@45355
   129
(* expects that relevant type variables are already contained in
schirmer@25171
   130
 * term variables. First instantiation of variables is returned without further
schirmer@25171
   131
 * checking.
schirmer@25171
   132
 *)
wenzelm@45355
   133
fun naive_cterm_first_order_match (t, ct) env =
schirmer@25171
   134
  let
wenzelm@45355
   135
    fun mtch (env as (tyinsts, insts)) =
wenzelm@45355
   136
      fn (Var (ixn, T), ct) =>
wenzelm@45355
   137
          (case AList.lookup (op =) insts ixn of
wenzelm@59586
   138
            NONE => (naive_typ_match (T, Thm.typ_of_cterm ct) tyinsts, (ixn, ct) :: insts)
wenzelm@45355
   139
          | SOME _ => env)
wenzelm@45355
   140
       | (f $ t, ct) =>
wenzelm@45355
   141
          let val (cf, ct') = Thm.dest_comb ct;
wenzelm@45355
   142
          in mtch (mtch env (f, cf)) (t, ct') end
wenzelm@45355
   143
       | _ => env;
wenzelm@45355
   144
  in mtch env (t, ct) end;
schirmer@25171
   145
schirmer@25171
   146
wenzelm@60639
   147
fun discharge ctxt prems rule =
schirmer@25171
   148
  let
wenzelm@45355
   149
    val (tyinsts,insts) =
wenzelm@59582
   150
      fold naive_cterm_first_order_match (Thm.prems_of rule ~~ map Thm.cprop_of prems) ([], []);
wenzelm@45355
   151
    val tyinsts' =
wenzelm@60642
   152
      map (fn (v, (S, U)) => ((v, S), Thm.ctyp_of ctxt U)) tyinsts;
wenzelm@45355
   153
    val insts' =
wenzelm@60642
   154
      map (fn (idxn, ct) => ((idxn, Thm.typ_of_cterm ct), ct)) insts;
wenzelm@45355
   155
    val rule' = Thm.instantiate (tyinsts', insts') rule;
wenzelm@45355
   156
  in fold Thm.elim_implies prems rule' end;
schirmer@25171
   157
schirmer@25171
   158
local
schirmer@25171
   159
wenzelm@45355
   160
val (l_in_set_root, x_in_set_root, r_in_set_root) =
wenzelm@45355
   161
  let
wenzelm@45355
   162
    val (Node_l_x_d, r) =
wenzelm@59582
   163
      Thm.cprop_of @{thm in_set_root}
wenzelm@45355
   164
      |> Thm.dest_comb |> #2
wenzelm@45355
   165
      |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2 |> Thm.dest_comb;
wenzelm@45355
   166
    val (Node_l, x) = Node_l_x_d |> Thm.dest_comb |> #1 |> Thm.dest_comb;
wenzelm@45355
   167
    val l = Node_l |> Thm.dest_comb |> #2;
wenzelm@45355
   168
  in (l,x,r) end;
schirmer@25171
   169
wenzelm@45355
   170
val (x_in_set_left, r_in_set_left) =
wenzelm@45355
   171
  let
wenzelm@45355
   172
    val (Node_l_x_d, r) =
wenzelm@59582
   173
      Thm.cprop_of @{thm in_set_left}
wenzelm@45355
   174
      |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2
wenzelm@45355
   175
      |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2 |> Thm.dest_comb;
wenzelm@45355
   176
    val x = Node_l_x_d |> Thm.dest_comb |> #1 |> Thm.dest_comb |> #2;
wenzelm@45355
   177
  in (x, r) end;
wenzelm@45355
   178
wenzelm@45355
   179
val (x_in_set_right, l_in_set_right) =
wenzelm@45355
   180
  let
wenzelm@45355
   181
    val (Node_l, x) =
wenzelm@59582
   182
      Thm.cprop_of @{thm in_set_right}
wenzelm@45355
   183
      |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2
wenzelm@45355
   184
      |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2
wenzelm@45355
   185
      |> Thm.dest_comb |> #1 |> Thm.dest_comb |> #1
wenzelm@45355
   186
      |> Thm.dest_comb;
wenzelm@45355
   187
    val l = Node_l |> Thm.dest_comb |> #2;
wenzelm@45355
   188
  in (x, l) end;
schirmer@25171
   189
schirmer@25171
   190
in
schirmer@25171
   191
(*
schirmer@25171
   192
1. First get paths x_path y_path of x and y in the tree.
schirmer@25171
   193
2. For the common prefix descend into the tree according to the path
schirmer@25171
   194
   and lemmas all_distinct_left/right
schirmer@25171
   195
3. If one restpath is empty use distinct_left/right,
schirmer@25171
   196
   otherwise all_distinct_left_right
schirmer@25171
   197
*)
schirmer@25171
   198
wenzelm@60327
   199
fun distinctTreeProver ctxt dist_thm x_path y_path =
schirmer@25171
   200
  let
schirmer@25171
   201
    fun dist_subtree [] thm = thm
wenzelm@45355
   202
      | dist_subtree (p :: ps) thm =
wenzelm@45355
   203
         let
wenzelm@45356
   204
           val rule =
wenzelm@45356
   205
            (case p of Left => @{thm all_distinct_left} | Right => @{thm all_distinct_right})
wenzelm@60639
   206
         in dist_subtree ps (discharge ctxt [thm] rule) end;
schirmer@25171
   207
wenzelm@45355
   208
    val (ps, x_rest, y_rest) = split_common_prefix x_path y_path;
schirmer@25171
   209
    val dist_subtree_thm = dist_subtree ps dist_thm;
wenzelm@59582
   210
    val subtree = Thm.cprop_of dist_subtree_thm |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2;
wenzelm@45355
   211
    val (_, [l, _, _, r]) = Drule.strip_comb subtree;
wenzelm@45355
   212
schirmer@25171
   213
    fun in_set ps tree =
schirmer@25171
   214
      let
wenzelm@45355
   215
        val (_, [l, x, _, r]) = Drule.strip_comb tree;
wenzelm@59586
   216
        val xT = Thm.ctyp_of_cterm x;
wenzelm@45355
   217
      in
wenzelm@45355
   218
        (case ps of
wenzelm@45355
   219
          [] =>
wenzelm@60327
   220
            instantiate ctxt
wenzelm@59586
   221
              [(Thm.ctyp_of_cterm x_in_set_root, xT)]
wenzelm@45356
   222
              [(l_in_set_root, l), (x_in_set_root, x), (r_in_set_root, r)] @{thm in_set_root}
wenzelm@45355
   223
        | Left :: ps' =>
wenzelm@45355
   224
            let
wenzelm@45355
   225
              val in_set_l = in_set ps' l;
wenzelm@45355
   226
              val in_set_left' =
wenzelm@60327
   227
                instantiate ctxt
wenzelm@59586
   228
                  [(Thm.ctyp_of_cterm x_in_set_left, xT)]
wenzelm@45356
   229
                  [(x_in_set_left, x), (r_in_set_left, r)] @{thm in_set_left};
wenzelm@60639
   230
            in discharge ctxt [in_set_l] in_set_left' end
wenzelm@45355
   231
        | Right :: ps' =>
wenzelm@45355
   232
            let
wenzelm@45355
   233
              val in_set_r = in_set ps' r;
wenzelm@45355
   234
              val in_set_right' =
wenzelm@60327
   235
                instantiate ctxt
wenzelm@59586
   236
                  [(Thm.ctyp_of_cterm x_in_set_right, xT)]
wenzelm@45356
   237
                  [(x_in_set_right, x), (l_in_set_right, l)] @{thm in_set_right};
wenzelm@60639
   238
            in discharge ctxt [in_set_r] in_set_right' end)
wenzelm@45355
   239
      end;
schirmer@25171
   240
wenzelm@45355
   241
  fun in_set' [] = raise TERM ("distinctTreeProver", [])
wenzelm@45355
   242
    | in_set' (Left :: ps) = in_set ps l
wenzelm@45355
   243
    | in_set' (Right :: ps) = in_set ps r;
wenzelm@45355
   244
wenzelm@60639
   245
  fun distinct_lr node_in_set Left =
wenzelm@60639
   246
        discharge ctxt [dist_subtree_thm, node_in_set] @{thm distinct_left}
wenzelm@60639
   247
    | distinct_lr node_in_set Right =
wenzelm@60639
   248
        discharge ctxt [dist_subtree_thm, node_in_set] @{thm distinct_right}
schirmer@25171
   249
wenzelm@45355
   250
  val (swap, neq) =
wenzelm@45355
   251
    (case x_rest of
wenzelm@45355
   252
      [] =>
wenzelm@45355
   253
        let val y_in_set = in_set' y_rest;
wenzelm@45355
   254
        in (false, distinct_lr y_in_set (hd y_rest)) end
wenzelm@45355
   255
    | xr :: xrs =>
wenzelm@45355
   256
        (case y_rest of
wenzelm@45355
   257
          [] =>
wenzelm@45355
   258
            let val x_in_set = in_set' x_rest;
wenzelm@45355
   259
            in (true, distinct_lr x_in_set (hd x_rest)) end
wenzelm@45355
   260
        | yr :: yrs =>
wenzelm@45355
   261
            let
wenzelm@45355
   262
              val x_in_set = in_set' x_rest;
wenzelm@45355
   263
              val y_in_set = in_set' y_rest;
wenzelm@45355
   264
            in
wenzelm@45355
   265
              (case xr of
wenzelm@45356
   266
                Left =>
wenzelm@60639
   267
                  (false,
wenzelm@60639
   268
                    discharge ctxt [dist_subtree_thm, x_in_set, y_in_set] @{thm distinct_left_right})
wenzelm@45356
   269
              | Right =>
wenzelm@60639
   270
                  (true,
wenzelm@60639
   271
                    discharge ctxt [dist_subtree_thm, y_in_set, x_in_set] @{thm distinct_left_right}))
wenzelm@45355
   272
           end));
wenzelm@60639
   273
  in if swap then discharge ctxt [neq] @{thm swap_neq} else neq end;
schirmer@25171
   274
schirmer@25171
   275
wenzelm@60639
   276
fun deleteProver _ dist_thm [] = @{thm delete_root} OF [dist_thm]
wenzelm@60639
   277
  | deleteProver ctxt dist_thm (p::ps) =
wenzelm@45355
   278
      let
wenzelm@45356
   279
        val dist_rule =
wenzelm@45356
   280
          (case p of Left => @{thm all_distinct_left} | Right => @{thm all_distinct_right});
wenzelm@60639
   281
        val dist_thm' = discharge ctxt [dist_thm] dist_rule;
wenzelm@45356
   282
        val del_rule = (case p of Left => @{thm delete_left} | Right => @{thm delete_right});
wenzelm@60639
   283
        val del = deleteProver ctxt dist_thm' ps;
wenzelm@60639
   284
      in discharge ctxt [dist_thm, del] del_rule end;
schirmer@25171
   285
schirmer@25171
   286
local
wenzelm@45355
   287
  val (alpha, v) =
schirmer@25171
   288
    let
wenzelm@45355
   289
      val ct =
wenzelm@45356
   290
        @{thm subtract_Tip} |> Thm.cprop_of |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2
wenzelm@45355
   291
        |> Thm.dest_comb |> #2;
wenzelm@59586
   292
      val [alpha] = ct |> Thm.ctyp_of_cterm |> Thm.dest_ctyp;
wenzelm@60642
   293
    in (dest_TVar (Thm.typ_of alpha), #1 (dest_Var (Thm.term_of ct))) end;
schirmer@25171
   294
in
schirmer@25171
   295
wenzelm@60327
   296
fun subtractProver ctxt (Const (@{const_name Tip}, T)) ct dist_thm =
wenzelm@45355
   297
      let
wenzelm@45355
   298
        val ct' = dist_thm |> Thm.cprop_of |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2;
wenzelm@45355
   299
        val [alphaI] = #2 (dest_Type T);
wenzelm@45355
   300
      in
wenzelm@45355
   301
        Thm.instantiate
wenzelm@60327
   302
          ([(alpha, Thm.ctyp_of ctxt alphaI)],
wenzelm@60642
   303
           [((v, treeT alphaI), ct')]) @{thm subtract_Tip}
wenzelm@45355
   304
      end
wenzelm@60327
   305
  | subtractProver ctxt (Const (@{const_name Node}, nT) $ l $ x $ d $ r) ct dist_thm =
wenzelm@45355
   306
      let
wenzelm@45355
   307
        val ct' = dist_thm |> Thm.cprop_of |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2;
wenzelm@45355
   308
        val (_, [cl, _, _, cr]) = Drule.strip_comb ct;
wenzelm@59582
   309
        val ps = the (find_tree x (Thm.term_of ct'));
wenzelm@60639
   310
        val del_tree = deleteProver ctxt dist_thm ps;
wenzelm@60639
   311
        val dist_thm' = discharge ctxt [del_tree, dist_thm] @{thm delete_Some_all_distinct};
wenzelm@60327
   312
        val sub_l = subtractProver ctxt (Thm.term_of cl) cl (dist_thm');
wenzelm@45355
   313
        val sub_r =
wenzelm@60327
   314
          subtractProver ctxt (Thm.term_of cr) cr
wenzelm@60639
   315
            (discharge ctxt [sub_l, dist_thm'] @{thm subtract_Some_all_distinct_res});
wenzelm@60639
   316
      in discharge ctxt [del_tree, sub_l, sub_r] @{thm subtract_Node} end;
wenzelm@45355
   317
wenzelm@45355
   318
end;
wenzelm@45355
   319
wenzelm@60327
   320
fun distinct_implProver ctxt dist_thm ct =
schirmer@25171
   321
  let
schirmer@25171
   322
    val ctree = ct |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2;
wenzelm@60327
   323
    val sub = subtractProver ctxt (Thm.term_of ctree) ctree dist_thm;
wenzelm@45356
   324
  in @{thm subtract_Some_all_distinct} OF [sub, dist_thm] end;
schirmer@25171
   325
schirmer@25171
   326
fun get_fst_success f [] = NONE
wenzelm@45355
   327
  | get_fst_success f (x :: xs) =
wenzelm@45355
   328
      (case f x of
wenzelm@45355
   329
        NONE => get_fst_success f xs
wenzelm@45355
   330
      | SOME v => SOME v);
schirmer@25171
   331
schirmer@25171
   332
fun neq_x_y ctxt x y name =
schirmer@25171
   333
  (let
wenzelm@42361
   334
    val dist_thm = the (try (Proof_Context.get_thm ctxt) name);
wenzelm@59582
   335
    val ctree = Thm.cprop_of dist_thm |> Thm.dest_comb |> #2 |> Thm.dest_comb |> #2;
wenzelm@59582
   336
    val tree = Thm.term_of ctree;
schirmer@25171
   337
    val x_path = the (find_tree x tree);
schirmer@25171
   338
    val y_path = the (find_tree y tree);
wenzelm@60327
   339
    val thm = distinctTreeProver ctxt dist_thm x_path y_path;
wenzelm@45355
   340
  in SOME thm
wenzelm@45355
   341
  end handle Option.Option => NONE);
schirmer@25171
   342
wenzelm@42368
   343
fun distinctTree_tac names ctxt = SUBGOAL (fn (goal, i) =>
wenzelm@42368
   344
    (case goal of
wenzelm@42368
   345
      Const (@{const_name Trueprop}, _) $
wenzelm@42368
   346
          (Const (@{const_name Not}, _) $ (Const (@{const_name HOL.eq}, _) $ x $ y)) =>
wenzelm@42368
   347
        (case get_fst_success (neq_x_y ctxt x y) names of
wenzelm@60754
   348
          SOME neq => resolve_tac ctxt [neq] i
wenzelm@42368
   349
        | NONE => no_tac)
wenzelm@42368
   350
    | _ => no_tac))
schirmer@25171
   351
wenzelm@45355
   352
fun distinctFieldSolver names =
wenzelm@51717
   353
  mk_solver "distinctFieldSolver" (distinctTree_tac names);
schirmer@25171
   354
schirmer@25171
   355
fun distinct_simproc names =
wenzelm@61144
   356
  Simplifier.make_simproc @{context} "DistinctTreeProver.distinct_simproc"
wenzelm@61144
   357
   {lhss = [@{term "x = y"}],
wenzelm@61144
   358
    proc = fn _ => fn ctxt => fn ct =>
wenzelm@61144
   359
      (case Thm.term_of ct of
wenzelm@61144
   360
        Const (@{const_name HOL.eq}, _) $ x $ y =>
wenzelm@45356
   361
          Option.map (fn neq => @{thm neq_to_eq_False} OF [neq])
wenzelm@45355
   362
            (get_fst_success (neq_x_y ctxt x y) names)
wenzelm@62913
   363
      | _ => NONE)};
schirmer@25171
   364
wenzelm@45355
   365
end;
wenzelm@45355
   366
nipkow@62391
   367
end;