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