src/HOL/Tools/Predicate_Compile/predicate_compile_aux.ML
author bulwahn
Thu Nov 12 09:10:22 2009 +0100 (2009-11-12)
changeset 33620 b6bf2dc5aed7
parent 33619 d93a3cb55068
child 33623 4ec42d38224f
permissions -rw-r--r--
added interface of user proposals for names of generated constants
wenzelm@33265
     1
(*  Title:      HOL/Tools/Predicate_Compile/predicate_compile_aux.ML
wenzelm@33265
     2
    Author:     Lukas Bulwahn, TU Muenchen
bulwahn@33250
     3
wenzelm@33265
     4
Auxilary functions for predicate compiler.
bulwahn@33250
     5
*)
bulwahn@33250
     6
wenzelm@33265
     7
(* FIXME proper signature *)
wenzelm@33265
     8
bulwahn@33250
     9
structure Predicate_Compile_Aux =
bulwahn@33250
    10
struct
bulwahn@33250
    11
bulwahn@33328
    12
bulwahn@33328
    13
(* mode *)
bulwahn@33328
    14
bulwahn@33327
    15
type smode = (int * int list option) list
bulwahn@33327
    16
type mode = smode option list * smode
bulwahn@33328
    17
datatype tmode = Mode of mode * smode * tmode option list;
bulwahn@33328
    18
bulwahn@33328
    19
fun string_of_smode js =
bulwahn@33328
    20
    commas (map
bulwahn@33328
    21
      (fn (i, is) =>
bulwahn@33328
    22
        string_of_int i ^ (case is of NONE => ""
bulwahn@33328
    23
    | SOME is => "p" ^ enclose "[" "]" (commas (map string_of_int is)))) js)
bulwahn@33619
    24
(* FIXME: remove! *)
bulwahn@33328
    25
bulwahn@33328
    26
fun string_of_mode (iss, is) = space_implode " -> " (map
bulwahn@33328
    27
  (fn NONE => "X"
bulwahn@33328
    28
    | SOME js => enclose "[" "]" (string_of_smode js))
bulwahn@33328
    29
       (iss @ [SOME is]));
bulwahn@33328
    30
bulwahn@33328
    31
fun string_of_tmode (Mode (predmode, termmode, param_modes)) =
bulwahn@33619
    32
  "predmode: " ^ (string_of_mode predmode) ^
bulwahn@33328
    33
  (if null param_modes then "" else
bulwahn@33328
    34
    "; " ^ "params: " ^ commas (map (the_default "NONE" o Option.map string_of_tmode) param_modes))
bulwahn@33327
    35
bulwahn@33619
    36
(* new datatype for mode *)
bulwahn@33619
    37
bulwahn@33619
    38
datatype mode' = Bool | Input | Output | Pair of mode' * mode' | Fun of mode' * mode'
bulwahn@33619
    39
bulwahn@33619
    40
(* name: binder_modes? *)
bulwahn@33619
    41
fun strip_fun_mode (Fun (mode, mode')) = mode :: strip_fun_mode mode'
bulwahn@33619
    42
  | strip_fun_mode Bool = []
bulwahn@33619
    43
  | strip_fun_mode _ = error "Bad mode for strip_fun_mode"
bulwahn@33619
    44
bulwahn@33619
    45
fun dest_fun_mode (Fun (mode, mode')) = mode :: dest_fun_mode mode'
bulwahn@33619
    46
  | dest_fun_mode mode = [mode]
bulwahn@33619
    47
bulwahn@33619
    48
fun dest_tuple_mode (Pair (mode, mode')) = mode :: dest_tuple_mode mode'
bulwahn@33619
    49
  | dest_tuple_mode _ = []
bulwahn@33619
    50
bulwahn@33619
    51
fun string_of_mode' mode' =
bulwahn@33619
    52
  let
bulwahn@33619
    53
    fun string_of_mode1 Input = "i"
bulwahn@33619
    54
      | string_of_mode1 Output = "o"
bulwahn@33619
    55
      | string_of_mode1 Bool = "bool"
bulwahn@33619
    56
      | string_of_mode1 mode = "(" ^ (string_of_mode3 mode) ^ ")"
bulwahn@33619
    57
    and string_of_mode2 (Pair (m1, m2))  = string_of_mode3 m1 ^ " * " ^  string_of_mode2 m2
bulwahn@33619
    58
      | string_of_mode2 mode = string_of_mode1 mode
bulwahn@33619
    59
    and string_of_mode3 (Fun (m1, m2)) = string_of_mode2 m1 ^ " => " ^ string_of_mode3 m2
bulwahn@33619
    60
      | string_of_mode3 mode = string_of_mode2 mode
bulwahn@33619
    61
  in string_of_mode3 mode' end
bulwahn@33619
    62
bulwahn@33619
    63
bulwahn@33619
    64
fun translate_mode T (iss, is) =
bulwahn@33619
    65
  let
bulwahn@33619
    66
    val Ts = binder_types T
bulwahn@33619
    67
    val (Ts1, Ts2) = chop (length iss) Ts
bulwahn@33619
    68
    fun translate_smode Ts is =
bulwahn@33619
    69
      let
bulwahn@33619
    70
        fun translate_arg (i, T) =
bulwahn@33619
    71
          case AList.lookup (op =) is (i + 1) of
bulwahn@33619
    72
            SOME NONE => Input
bulwahn@33619
    73
          | SOME (SOME its) =>
bulwahn@33619
    74
            let
bulwahn@33619
    75
              fun translate_tuple (i, T) = if member (op =) its (i + 1) then Input else Output
bulwahn@33619
    76
            in 
bulwahn@33619
    77
              foldr1 Pair (map_index translate_tuple (HOLogic.strip_tupleT T))
bulwahn@33619
    78
            end
bulwahn@33619
    79
          | NONE => Output
bulwahn@33619
    80
      in map_index translate_arg Ts end
bulwahn@33619
    81
    fun mk_mode arg_modes = foldr1 Fun (arg_modes @ [Bool])
bulwahn@33619
    82
    val param_modes =
bulwahn@33619
    83
      map (fn (T, NONE) => Input | (T, SOME is) => mk_mode (translate_smode (binder_types T) is))
bulwahn@33619
    84
        (Ts1 ~~ iss)
bulwahn@33619
    85
  in
bulwahn@33619
    86
    mk_mode (param_modes @ translate_smode Ts2 is)
bulwahn@33619
    87
  end;
bulwahn@33619
    88
bulwahn@33619
    89
fun string_of_mode thy constname mode =
bulwahn@33619
    90
  string_of_mode' (translate_mode (Sign.the_const_type thy constname) mode)
bulwahn@33619
    91
bulwahn@33619
    92
fun eq_mode' (Fun (m1, m2), Fun (m3, m4)) = eq_mode' (m1, m3) andalso eq_mode' (m2, m4)
bulwahn@33619
    93
  | eq_mode' (Pair (m1, m2), Pair (m3, m4)) = eq_mode' (m1, m3) andalso eq_mode' (m2, m4)
bulwahn@33619
    94
  | eq_mode' (Pair (m1, m2), Input) = eq_mode' (m1, Input) andalso eq_mode' (m2, Input)
bulwahn@33619
    95
  | eq_mode' (Pair (m1, m2), Output) = eq_mode' (m1, Output) andalso eq_mode' (m2, Output)
bulwahn@33619
    96
  | eq_mode' (Input, Pair (m1, m2)) = eq_mode' (Input, m1) andalso eq_mode' (Input, m2)
bulwahn@33619
    97
  | eq_mode' (Output, Pair (m1, m2)) = eq_mode' (Output, m1) andalso eq_mode' (Output, m2)
bulwahn@33619
    98
  | eq_mode' (Input, Input) = true
bulwahn@33619
    99
  | eq_mode' (Output, Output) = true
bulwahn@33619
   100
  | eq_mode' (Bool, Bool) = true
bulwahn@33619
   101
  | eq_mode' _ = false
bulwahn@33619
   102
(* FIXME: remove! *)
bulwahn@33619
   103
fun eq_mode'_mode (mode', (iss, is)) =
bulwahn@33619
   104
  let
bulwahn@33619
   105
    val arg_modes = strip_fun_mode mode'
bulwahn@33619
   106
    val (arg_modes1, arg_modes2) = chop (length iss) arg_modes
bulwahn@33619
   107
    fun eq_arg Input NONE = true
bulwahn@33619
   108
      | eq_arg _ NONE = false
bulwahn@33619
   109
      | eq_arg mode (SOME is) =
bulwahn@33619
   110
        let
bulwahn@33619
   111
          val modes = dest_tuple_mode mode
bulwahn@33619
   112
        in
bulwahn@33619
   113
          forall (fn i => nth modes (i - 1) = Input) is
bulwahn@33619
   114
            andalso forall (fn i => nth modes (i - 1) = Output)
bulwahn@33619
   115
              (subtract (op =) is (1 upto length modes))
bulwahn@33619
   116
        end
bulwahn@33619
   117
    fun eq_mode'_smode mode' is =
bulwahn@33619
   118
      forall (fn (i, t) => eq_arg (nth mode' (i - 1)) t) is
bulwahn@33619
   119
        andalso forall (fn i => (nth mode' (i - 1) = Output))
bulwahn@33619
   120
          (subtract (op =) (map fst is) (1 upto length mode'))
bulwahn@33619
   121
  in
bulwahn@33619
   122
    forall (fn (m, NONE) => m = Input | (m, SOME is) => eq_mode'_smode (strip_fun_mode m) is)
bulwahn@33619
   123
      (arg_modes1 ~~ iss)
bulwahn@33619
   124
    andalso eq_mode'_smode arg_modes2 is
bulwahn@33619
   125
  end
bulwahn@33619
   126
bulwahn@33619
   127
bulwahn@33250
   128
(* general syntactic functions *)
bulwahn@33250
   129
bulwahn@33250
   130
(*Like dest_conj, but flattens conjunctions however nested*)
bulwahn@33250
   131
fun conjuncts_aux (Const ("op &", _) $ t $ t') conjs = conjuncts_aux t (conjuncts_aux t' conjs)
bulwahn@33250
   132
  | conjuncts_aux t conjs = t::conjs;
bulwahn@33250
   133
bulwahn@33250
   134
fun conjuncts t = conjuncts_aux t [];
bulwahn@33250
   135
bulwahn@33250
   136
(* syntactic functions *)
bulwahn@33250
   137
bulwahn@33250
   138
fun is_equationlike_term (Const ("==", _) $ _ $ _) = true
bulwahn@33250
   139
  | is_equationlike_term (Const ("Trueprop", _) $ (Const ("op =", _) $ _ $ _)) = true
bulwahn@33250
   140
  | is_equationlike_term _ = false
bulwahn@33250
   141
  
bulwahn@33250
   142
val is_equationlike = is_equationlike_term o prop_of 
bulwahn@33250
   143
bulwahn@33250
   144
fun is_pred_equation_term (Const ("==", _) $ u $ v) =
bulwahn@33250
   145
  (fastype_of u = @{typ bool}) andalso (fastype_of v = @{typ bool})
bulwahn@33250
   146
  | is_pred_equation_term _ = false
bulwahn@33250
   147
  
bulwahn@33250
   148
val is_pred_equation = is_pred_equation_term o prop_of 
bulwahn@33250
   149
bulwahn@33250
   150
fun is_intro_term constname t =
bulwahn@33250
   151
  case fst (strip_comb (HOLogic.dest_Trueprop (Logic.strip_imp_concl t))) of
bulwahn@33250
   152
    Const (c, _) => c = constname
bulwahn@33250
   153
  | _ => false
bulwahn@33250
   154
  
bulwahn@33250
   155
fun is_intro constname t = is_intro_term constname (prop_of t)
bulwahn@33250
   156
bulwahn@33250
   157
fun is_pred thy constname =
bulwahn@33250
   158
  let
bulwahn@33250
   159
    val T = (Sign.the_const_type thy constname)
bulwahn@33250
   160
  in body_type T = @{typ "bool"} end;
bulwahn@33250
   161
  
bulwahn@33250
   162
bulwahn@33250
   163
fun is_predT (T as Type("fun", [_, _])) = (snd (strip_type T) = HOLogic.boolT)
bulwahn@33250
   164
  | is_predT _ = false
bulwahn@33250
   165
bulwahn@33619
   166
(* guessing number of parameters *)
bulwahn@33619
   167
fun find_indexes pred xs =
bulwahn@33619
   168
  let
bulwahn@33619
   169
    fun find is n [] = is
bulwahn@33619
   170
      | find is n (x :: xs) = find (if pred x then (n :: is) else is) (n + 1) xs;
bulwahn@33619
   171
  in rev (find [] 0 xs) end;
bulwahn@33619
   172
bulwahn@33619
   173
fun guess_nparams T =
bulwahn@33619
   174
  let
bulwahn@33619
   175
    val argTs = binder_types T
bulwahn@33619
   176
    val nparams = fold Integer.max
bulwahn@33619
   177
      (map (fn x => x + 1) (find_indexes is_predT argTs)) 0
bulwahn@33619
   178
  in nparams end;
bulwahn@33619
   179
bulwahn@33250
   180
(*** check if a term contains only constructor functions ***)
bulwahn@33250
   181
fun is_constrt thy =
bulwahn@33250
   182
  let
bulwahn@33250
   183
    val cnstrs = flat (maps
bulwahn@33250
   184
      (map (fn (_, (Tname, _, cs)) => map (apsnd (rpair Tname o length)) cs) o #descr o snd)
bulwahn@33250
   185
      (Symtab.dest (Datatype.get_all thy)));
bulwahn@33250
   186
    fun check t = (case strip_comb t of
bulwahn@33250
   187
        (Free _, []) => true
bulwahn@33250
   188
      | (Const (s, T), ts) => (case (AList.lookup (op =) cnstrs s, body_type T) of
bulwahn@33250
   189
            (SOME (i, Tname), Type (Tname', _)) => length ts = i andalso Tname = Tname' andalso forall check ts
bulwahn@33250
   190
          | _ => false)
bulwahn@33250
   191
      | _ => false)
bulwahn@33250
   192
  in check end;  
bulwahn@33250
   193
  
bulwahn@33250
   194
fun strip_ex (Const ("Ex", _) $ Abs (x, T, t)) =
bulwahn@33250
   195
  let
bulwahn@33250
   196
    val (xTs, t') = strip_ex t
bulwahn@33250
   197
  in
bulwahn@33250
   198
    ((x, T) :: xTs, t')
bulwahn@33250
   199
  end
bulwahn@33250
   200
  | strip_ex t = ([], t)
bulwahn@33250
   201
bulwahn@33250
   202
fun focus_ex t nctxt =
bulwahn@33250
   203
  let
bulwahn@33250
   204
    val ((xs, Ts), t') = apfst split_list (strip_ex t) 
bulwahn@33250
   205
    val (xs', nctxt') = Name.variants xs nctxt;
bulwahn@33250
   206
    val ps' = xs' ~~ Ts;
bulwahn@33250
   207
    val vs = map Free ps';
bulwahn@33250
   208
    val t'' = Term.subst_bounds (rev vs, t');
bulwahn@33250
   209
  in ((ps', t''), nctxt') end;
bulwahn@33250
   210
bulwahn@33250
   211
bulwahn@33250
   212
(* introduction rule combinators *)
bulwahn@33250
   213
bulwahn@33250
   214
(* combinators to apply a function to all literals of an introduction rules *)
bulwahn@33250
   215
bulwahn@33250
   216
fun map_atoms f intro = 
bulwahn@33250
   217
  let
bulwahn@33250
   218
    val (literals, head) = Logic.strip_horn intro
bulwahn@33250
   219
    fun appl t = (case t of
bulwahn@33250
   220
        (@{term "Not"} $ t') => HOLogic.mk_not (f t')
bulwahn@33250
   221
      | _ => f t)
bulwahn@33250
   222
  in
bulwahn@33250
   223
    Logic.list_implies
bulwahn@33250
   224
      (map (HOLogic.mk_Trueprop o appl o HOLogic.dest_Trueprop) literals, head)
bulwahn@33250
   225
  end
bulwahn@33250
   226
bulwahn@33250
   227
fun fold_atoms f intro s =
bulwahn@33250
   228
  let
bulwahn@33250
   229
    val (literals, head) = Logic.strip_horn intro
bulwahn@33250
   230
    fun appl t s = (case t of
bulwahn@33250
   231
      (@{term "Not"} $ t') => f t' s
bulwahn@33250
   232
      | _ => f t s)
bulwahn@33250
   233
  in fold appl (map HOLogic.dest_Trueprop literals) s end
bulwahn@33250
   234
bulwahn@33250
   235
fun fold_map_atoms f intro s =
bulwahn@33250
   236
  let
bulwahn@33250
   237
    val (literals, head) = Logic.strip_horn intro
bulwahn@33250
   238
    fun appl t s = (case t of
bulwahn@33250
   239
      (@{term "Not"} $ t') => apfst HOLogic.mk_not (f t' s)
bulwahn@33250
   240
      | _ => f t s)
bulwahn@33250
   241
    val (literals', s') = fold_map appl (map HOLogic.dest_Trueprop literals) s
bulwahn@33250
   242
  in
bulwahn@33250
   243
    (Logic.list_implies (map HOLogic.mk_Trueprop literals', head), s')
bulwahn@33250
   244
  end;
bulwahn@33250
   245
bulwahn@33250
   246
fun maps_premises f intro =
bulwahn@33250
   247
  let
bulwahn@33250
   248
    val (premises, head) = Logic.strip_horn intro
bulwahn@33250
   249
  in
bulwahn@33250
   250
    Logic.list_implies (maps f premises, head)
bulwahn@33250
   251
  end
bulwahn@33250
   252
  
bulwahn@33250
   253
(* lifting term operations to theorems *)
bulwahn@33250
   254
bulwahn@33250
   255
fun map_term thy f th =
bulwahn@33250
   256
  Skip_Proof.make_thm thy (f (prop_of th))
bulwahn@33250
   257
bulwahn@33250
   258
(*
bulwahn@33250
   259
fun equals_conv lhs_cv rhs_cv ct =
bulwahn@33250
   260
  case Thm.term_of ct of
bulwahn@33250
   261
    Const ("==", _) $ _ $ _ => Conv.arg_conv cv ct  
bulwahn@33250
   262
  | _ => error "equals_conv"  
bulwahn@33250
   263
*)
bulwahn@33250
   264
bulwahn@33250
   265
(* Different options for compiler *)
bulwahn@33250
   266
bulwahn@33250
   267
datatype options = Options of {  
bulwahn@33619
   268
  expected_modes : (string * mode' list) option,
bulwahn@33620
   269
  user_proposals : ((string * mode') * string) list,
bulwahn@33250
   270
  show_steps : bool,
bulwahn@33250
   271
  show_proof_trace : bool,
bulwahn@33250
   272
  show_intermediate_results : bool,
bulwahn@33251
   273
  show_mode_inference : bool,
bulwahn@33251
   274
  show_modes : bool,
bulwahn@33250
   275
  show_compilation : bool,
bulwahn@33250
   276
  skip_proof : bool,
bulwahn@33250
   277
bulwahn@33250
   278
  inductify : bool,
bulwahn@33375
   279
  random : bool,
bulwahn@33473
   280
  depth_limited : bool,
bulwahn@33473
   281
  annotated : bool
bulwahn@33250
   282
};
bulwahn@33250
   283
bulwahn@33250
   284
fun expected_modes (Options opt) = #expected_modes opt
bulwahn@33620
   285
fun user_proposal (Options opt) name mode = AList.lookup (eq_pair (op =) eq_mode')
bulwahn@33620
   286
  (#user_proposals opt) (name, mode)
bulwahn@33620
   287
bulwahn@33250
   288
fun show_steps (Options opt) = #show_steps opt
bulwahn@33250
   289
fun show_intermediate_results (Options opt) = #show_intermediate_results opt
bulwahn@33250
   290
fun show_proof_trace (Options opt) = #show_proof_trace opt
bulwahn@33251
   291
fun show_modes (Options opt) = #show_modes opt
bulwahn@33251
   292
fun show_mode_inference (Options opt) = #show_mode_inference opt
bulwahn@33250
   293
fun show_compilation (Options opt) = #show_compilation opt
bulwahn@33250
   294
fun skip_proof (Options opt) = #skip_proof opt
bulwahn@33250
   295
bulwahn@33250
   296
fun is_inductify (Options opt) = #inductify opt
bulwahn@33375
   297
fun is_random (Options opt) = #random opt
bulwahn@33250
   298
fun is_depth_limited (Options opt) = #depth_limited opt
bulwahn@33473
   299
fun is_annotated (Options opt) = #annotated opt
bulwahn@33250
   300
bulwahn@33250
   301
val default_options = Options {
bulwahn@33250
   302
  expected_modes = NONE,
bulwahn@33620
   303
  user_proposals = [],
bulwahn@33250
   304
  show_steps = false,
bulwahn@33250
   305
  show_intermediate_results = false,
bulwahn@33250
   306
  show_proof_trace = false,
bulwahn@33251
   307
  show_modes = false,
bulwahn@33250
   308
  show_mode_inference = false,
bulwahn@33250
   309
  show_compilation = false,
bulwahn@33250
   310
  skip_proof = false,
bulwahn@33250
   311
  
bulwahn@33250
   312
  inductify = false,
bulwahn@33375
   313
  random = false,
bulwahn@33473
   314
  depth_limited = false,
bulwahn@33473
   315
  annotated = false
bulwahn@33250
   316
}
bulwahn@33250
   317
bulwahn@33250
   318
bulwahn@33250
   319
fun print_step options s =
bulwahn@33250
   320
  if show_steps options then tracing s else ()
bulwahn@33250
   321
bulwahn@33250
   322
(* tuple processing *)
bulwahn@33250
   323
bulwahn@33250
   324
fun expand_tuples thy intro =
bulwahn@33250
   325
  let
bulwahn@33250
   326
    fun rewrite_args [] (pats, intro_t, ctxt) = (pats, intro_t, ctxt)
bulwahn@33250
   327
      | rewrite_args (arg::args) (pats, intro_t, ctxt) = 
bulwahn@33250
   328
      (case HOLogic.strip_tupleT (fastype_of arg) of
bulwahn@33250
   329
        (Ts as _ :: _ :: _) =>
bulwahn@33250
   330
        let
bulwahn@33250
   331
          fun rewrite_arg' (Const ("Pair", _) $ _ $ t2, Type ("*", [_, T2]))
bulwahn@33250
   332
            (args, (pats, intro_t, ctxt)) = rewrite_arg' (t2, T2) (args, (pats, intro_t, ctxt))
bulwahn@33250
   333
            | rewrite_arg' (t, Type ("*", [T1, T2])) (args, (pats, intro_t, ctxt)) =
bulwahn@33250
   334
              let
bulwahn@33250
   335
                val ([x, y], ctxt') = Variable.variant_fixes ["x", "y"] ctxt
bulwahn@33250
   336
                val pat = (t, HOLogic.mk_prod (Free (x, T1), Free (y, T2)))
bulwahn@33250
   337
                val intro_t' = Pattern.rewrite_term thy [pat] [] intro_t
bulwahn@33250
   338
                val args' = map (Pattern.rewrite_term thy [pat] []) args
bulwahn@33250
   339
              in
bulwahn@33250
   340
                rewrite_arg' (Free (y, T2), T2) (args', (pat::pats, intro_t', ctxt'))
bulwahn@33250
   341
              end
bulwahn@33250
   342
            | rewrite_arg' _ (args, (pats, intro_t, ctxt)) = (args, (pats, intro_t, ctxt))
bulwahn@33250
   343
          val (args', (pats, intro_t', ctxt')) = rewrite_arg' (arg, fastype_of arg)
bulwahn@33250
   344
            (args, (pats, intro_t, ctxt))
bulwahn@33250
   345
        in
bulwahn@33250
   346
          rewrite_args args' (pats, intro_t', ctxt')
bulwahn@33250
   347
        end
bulwahn@33250
   348
      | _ => rewrite_args args (pats, intro_t, ctxt))
bulwahn@33250
   349
    fun rewrite_prem atom =
bulwahn@33250
   350
      let
bulwahn@33250
   351
        val (_, args) = strip_comb atom
bulwahn@33250
   352
      in rewrite_args args end
bulwahn@33250
   353
    val ctxt = ProofContext.init thy
bulwahn@33250
   354
    val (((T_insts, t_insts), [intro']), ctxt1) = Variable.import false [intro] ctxt
bulwahn@33250
   355
    val intro_t = prop_of intro'
bulwahn@33250
   356
    val concl = Logic.strip_imp_concl intro_t
bulwahn@33250
   357
    val (p, args) = strip_comb (HOLogic.dest_Trueprop concl)
bulwahn@33250
   358
    val (pats', intro_t', ctxt2) = rewrite_args args ([], intro_t, ctxt1)
bulwahn@33250
   359
    val (pats', intro_t', ctxt3) = 
bulwahn@33250
   360
      fold_atoms rewrite_prem intro_t' (pats', intro_t', ctxt2)
bulwahn@33250
   361
    fun rewrite_pat (ct1, ct2) =
bulwahn@33250
   362
      (ct1, cterm_of thy (Pattern.rewrite_term thy pats' [] (term_of ct2)))
bulwahn@33250
   363
    val t_insts' = map rewrite_pat t_insts
bulwahn@33250
   364
    val intro'' = Thm.instantiate (T_insts, t_insts') intro
bulwahn@33250
   365
    val [intro'''] = Variable.export ctxt3 ctxt [intro'']
bulwahn@33250
   366
    val intro'''' = Simplifier.full_simplify
bulwahn@33250
   367
      (HOL_basic_ss addsimps [@{thm fst_conv}, @{thm snd_conv}, @{thm Pair_eq}])
bulwahn@33250
   368
      intro'''
bulwahn@33250
   369
    (* splitting conjunctions introduced by Pair_eq*)
bulwahn@33250
   370
    fun split_conj prem =
bulwahn@33250
   371
      map HOLogic.mk_Trueprop (conjuncts (HOLogic.dest_Trueprop prem))
bulwahn@33250
   372
    val intro''''' = map_term thy (maps_premises split_conj) intro''''
bulwahn@33250
   373
  in
bulwahn@33250
   374
    intro'''''
bulwahn@33250
   375
  end
bulwahn@33250
   376
bulwahn@33250
   377
end;