src/HOL/ex/reflection.ML
author haftmann
Wed Mar 12 19:38:14 2008 +0100 (2008-03-12)
changeset 26265 4b63b9e9b10d
parent 24630 351a308ab58d
child 29269 5c25a2012975
permissions -rw-r--r--
separated Random.thy from Quickcheck.thy
wenzelm@20319
     1
(*
wenzelm@20319
     2
    ID:         $Id$
wenzelm@20319
     3
    Author:     Amine Chaieb, TU Muenchen
wenzelm@20319
     4
wenzelm@20319
     5
A trial for automatical reification.
wenzelm@20319
     6
*)
wenzelm@20319
     7
wenzelm@20319
     8
signature REFLECTION = sig
wenzelm@20319
     9
  val genreify_tac: Proof.context -> thm list -> term option -> int -> tactic
chaieb@23648
    10
  val reflection_tac: Proof.context -> thm list -> thm list -> term option -> int -> tactic
haftmann@21878
    11
  val gen_reflection_tac: Proof.context -> (cterm -> thm)
chaieb@23648
    12
    -> thm list -> thm list -> term option -> int -> tactic
wenzelm@20319
    13
end;
wenzelm@20319
    14
chaieb@23648
    15
structure Reflection : REFLECTION
wenzelm@20319
    16
= struct
wenzelm@20319
    17
chaieb@20374
    18
val ext2 = thm "ext2";
wenzelm@21669
    19
val nth_Cons_0 = thm "nth_Cons_0";
wenzelm@21669
    20
val nth_Cons_Suc = thm "nth_Cons_Suc";
wenzelm@21669
    21
chaieb@20374
    22
  (* Make a congruence rule out of a defining equation for the interpretation *)
chaieb@20374
    23
  (* th is one defining equation of f, i.e.
chaieb@20374
    24
     th is "f (Cp ?t1 ... ?tn) = P(f ?t1, .., f ?tn)" *)
chaieb@20374
    25
  (* Cp is a constructor pattern and P is a pattern *)
chaieb@20374
    26
chaieb@20374
    27
  (* The result is:
chaieb@20374
    28
      [|?A1 = f ?t1 ; .. ; ?An= f ?tn |] ==> P (?A1, .., ?An) = f (Cp ?t1 .. ?tn) *)
chaieb@20374
    29
  (*  + the a list of names of the A1 .. An, Those are fresh in the ctxt*)
chaieb@20374
    30
chaieb@20374
    31
chaieb@20374
    32
fun mk_congeq ctxt fs th = 
chaieb@20374
    33
  let 
chaieb@20564
    34
   val (f as Const(fN,fT)) = th |> prop_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq 
chaieb@20564
    35
				|> fst |> strip_comb |> fst
chaieb@20374
    36
   val thy = ProofContext.theory_of ctxt
chaieb@20374
    37
   val cert = Thm.cterm_of thy
wenzelm@22568
    38
   val (((_,_),[th']), ctxt') = Variable.import_thms true [th] ctxt
chaieb@20374
    39
   val (lhs, rhs) = HOLogic.dest_eq (HOLogic.dest_Trueprop (Thm.prop_of th'))
chaieb@20564
    40
   fun add_fterms (t as t1 $ t2) = 
chaieb@22199
    41
       if exists (fn f => could_unify (t |> strip_comb |> fst, f)) fs then insert (op aconv) t
chaieb@20564
    42
       else add_fterms t1 #> add_fterms t2
chaieb@20374
    43
     | add_fterms (t as Abs(xn,xT,t')) = 
chaieb@20564
    44
       if (fN mem (term_consts t)) then (fn _ => [t]) else (fn _ => [])
chaieb@20374
    45
     | add_fterms _ = I
chaieb@20374
    46
   val fterms = add_fterms rhs []
wenzelm@20797
    47
   val (xs, ctxt'') = Variable.variant_fixes (replicate (length fterms) "x") ctxt'
chaieb@20374
    48
   val tys = map fastype_of fterms
chaieb@20374
    49
   val vs = map Free (xs ~~ tys)
chaieb@20374
    50
   val env = fterms ~~ vs
chaieb@20564
    51
		    (* FIXME!!!!*)	
chaieb@20564
    52
   fun replace_fterms (t as t1 $ t2) =
chaieb@20374
    53
       (case AList.lookup (op aconv) env t of
chaieb@20374
    54
	    SOME v => v
chaieb@20564
    55
	  | NONE => replace_fterms t1 $ replace_fterms t2)
chaieb@20374
    56
     | replace_fterms t = (case AList.lookup (op aconv) env t of
chaieb@20374
    57
			       SOME v => v
chaieb@20374
    58
			     | NONE => t)
chaieb@20374
    59
      
chaieb@20374
    60
   fun mk_def (Abs(x,xT,t),v) = HOLogic.mk_Trueprop ((HOLogic.all_const xT)$ Abs(x,xT,HOLogic.mk_eq(v$(Bound 0), t)))
chaieb@20374
    61
     | mk_def (t, v) = HOLogic.mk_Trueprop (HOLogic.mk_eq (v, t))
chaieb@23605
    62
   fun tryext x = (x RS ext2 handle THM _ =>  x)
chaieb@20374
    63
   val cong = (Goal.prove ctxt'' [] (map mk_def env)
chaieb@20374
    64
			  (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, replace_fterms rhs)))
chaieb@20374
    65
			  (fn x => LocalDefs.unfold_tac (#context x) (map tryext (#prems x)) 
chaieb@20374
    66
							THEN rtac th' 1)) RS sym
chaieb@20374
    67
	      
chaieb@20374
    68
   val (cong' :: vars') = 
chaieb@20374
    69
       Variable.export ctxt'' ctxt (cong :: map (Drule.mk_term o cert) vs)
chaieb@20374
    70
   val vs' = map (fst o fst o Term.dest_Var o Thm.term_of o Drule.dest_term) vars'
chaieb@20374
    71
					      
chaieb@20374
    72
  in  (vs', cong') end; 
wenzelm@20319
    73
 (* congs is a list of pairs (P,th) where th is a theorem for *)
wenzelm@20319
    74
        (* [| f p1 = A1; ...; f pn = An|] ==> f (C p1 .. pn) = P *)
wenzelm@20319
    75
val FWD = curry (op OF);
wenzelm@20319
    76
wenzelm@20319
    77
 (* da is the decomposition for atoms, ie. it returns ([],g) where g
wenzelm@20319
    78
 returns the right instance f (AtC n) = t , where AtC is the Atoms
wenzelm@20319
    79
 constructor and n is the number of the atom corresponding to t *)
wenzelm@20319
    80
wenzelm@20319
    81
(* Generic decomp for reification : matches the actual term with the
wenzelm@20319
    82
rhs of one cong rule. The result of the matching guides the
wenzelm@20319
    83
proof synthesis: The matches of the introduced Variables A1 .. An are
wenzelm@20319
    84
processed recursively
wenzelm@20319
    85
 The rest is instantiated in the cong rule,i.e. no reification is needed *)
wenzelm@20319
    86
chaieb@20374
    87
exception REIF of string;
chaieb@20374
    88
chaieb@20564
    89
val bds = ref ([]: (typ * ((term list) * (term list))) list);
chaieb@20564
    90
chaieb@20564
    91
fun index_of t = 
chaieb@20564
    92
 let 
chaieb@20564
    93
  val tt = HOLogic.listT (fastype_of t)
chaieb@20564
    94
 in 
chaieb@22199
    95
  (case AList.lookup Type.could_unify (!bds) tt of
chaieb@20564
    96
    NONE => error "index_of : type not found in environements!"
chaieb@20564
    97
  | SOME (tbs,tats) =>
chaieb@20564
    98
    let
chaieb@20564
    99
     val i = find_index_eq t tats
chaieb@20564
   100
     val j = find_index_eq t tbs 
chaieb@20564
   101
    in (if j= ~1 then 
chaieb@20564
   102
	    if i= ~1 
chaieb@23605
   103
	    then (bds := AList.update Type.could_unify (tt,(tbs,tats@[t])) (!bds) ; 
chaieb@20564
   104
		  length tbs + length tats) 
chaieb@20564
   105
	    else i else j)
chaieb@20564
   106
    end)
chaieb@20564
   107
 end;
chaieb@20564
   108
chaieb@20564
   109
fun dest_listT (Type ("List.list", [T])) = T;
chaieb@20374
   110
chaieb@20374
   111
fun decomp_genreif da cgns (t,ctxt) =
chaieb@20564
   112
 let 
chaieb@20564
   113
  val thy = ProofContext.theory_of ctxt 
chaieb@20564
   114
  val cert = cterm_of thy
chaieb@20564
   115
  fun tryabsdecomp (s,ctxt) = 
chaieb@20564
   116
   (case s of 
chaieb@20564
   117
     Abs(xn,xT,ta) => 
chaieb@20564
   118
     (let
wenzelm@20797
   119
       val ([xn],ctxt') = Variable.variant_fixes ["x"] ctxt
chaieb@20564
   120
       val (xn,ta) = variant_abs (xn,xT,ta)
chaieb@20564
   121
       val x = Free(xn,xT)
chaieb@23605
   122
       val _ = (case AList.lookup Type.could_unify (!bds) (HOLogic.listT xT)
chaieb@20564
   123
		 of NONE => error "tryabsdecomp: Type not found in the Environement"
chaieb@20564
   124
		  | SOME (bsT,atsT) => 
chaieb@23605
   125
		    (bds := AList.update Type.could_unify (HOLogic.listT xT, ((x::bsT), atsT)) (!bds)))
chaieb@20564
   126
      in ([(ta, ctxt')] , 
chaieb@23605
   127
	  fn [th] => ((let val (bsT,asT) = the(AList.lookup Type.could_unify (!bds) (HOLogic.listT xT))
chaieb@23605
   128
		       in (bds := AList.update Type.could_unify (HOLogic.listT xT,(tl bsT,asT)) (!bds))
chaieb@20564
   129
		       end) ; 
chaieb@20564
   130
		      hd (Variable.export ctxt' ctxt [(forall_intr (cert x) th) COMP allI])))
chaieb@20374
   131
	end)
chaieb@20374
   132
    | _ => da (s,ctxt))
chaieb@20374
   133
  in 
chaieb@20374
   134
  (case cgns of 
chaieb@20374
   135
    [] => tryabsdecomp (t,ctxt)
chaieb@20374
   136
  | ((vns,cong)::congs) => ((let
chaieb@20374
   137
        val cert = cterm_of thy
chaieb@20564
   138
	val certy = ctyp_of thy
chaieb@20564
   139
        val (tyenv, tmenv) =
wenzelm@20319
   140
        Pattern.match thy
wenzelm@20319
   141
        ((fst o HOLogic.dest_eq o HOLogic.dest_Trueprop) (concl_of cong), t)
wenzelm@20319
   142
        (Envir.type_env (Envir.empty 0),Term.Vartab.empty)
wenzelm@20319
   143
        val (fnvs,invs) = List.partition (fn ((vn,_),_) => vn mem vns) (Vartab.dest tmenv)
chaieb@20564
   144
        val (fts,its) = 
chaieb@20564
   145
	    (map (snd o snd) fnvs,
chaieb@20564
   146
             map (fn ((vn,vi),(tT,t)) => (cert(Var ((vn,vi),tT)), cert t)) invs)
chaieb@20564
   147
	val ctyenv = map (fn ((vn,vi),(s,ty)) => (certy (TVar((vn,vi),s)), certy ty)) (Vartab.dest tyenv)
chaieb@20564
   148
    in (fts ~~ (replicate (length fts) ctxt), FWD (instantiate (ctyenv, its) cong))
wenzelm@20319
   149
    end)
chaieb@20564
   150
      handle MATCH => decomp_genreif da congs (t,ctxt)))
chaieb@20564
   151
  end;
chaieb@23648
   152
chaieb@23648
   153
 (* looks for the atoms equation and instantiates it with the right number *)
chaieb@20374
   154
chaieb@23548
   155
chaieb@20374
   156
fun mk_decompatom eqs (t,ctxt) =
chaieb@23605
   157
let 
chaieb@23605
   158
 val tT = fastype_of t
chaieb@23605
   159
 fun isat eq = 
chaieb@23605
   160
  let 
chaieb@23605
   161
   val rhs = eq |> prop_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> snd
chaieb@20564
   162
   in exists_Const 
chaieb@20564
   163
	  (fn (n,ty) => n="List.nth" 
chaieb@20564
   164
			andalso 
chaieb@22199
   165
			AList.defined Type.could_unify (!bds) (domain_type ty)) rhs 
chaieb@22199
   166
	  andalso Type.could_unify (fastype_of rhs, tT)
chaieb@20564
   167
   end
chaieb@23605
   168
 fun get_nths t acc = 
chaieb@23605
   169
  case t of
chaieb@23605
   170
    Const("List.nth",_)$vs$n => insert (fn ((a,_),(b,_)) => a aconv b) (t,(vs,n)) acc
chaieb@23605
   171
  | t1$t2 => get_nths t1 (get_nths t2 acc)
chaieb@23605
   172
  | Abs(_,_,t') => get_nths t'  acc
chaieb@23605
   173
  | _ => acc
chaieb@23548
   174
chaieb@23605
   175
 fun 
chaieb@23605
   176
   tryeqs [] = error "Can not find the atoms equation"
chaieb@23605
   177
 | tryeqs (eq::eqs) = ((
chaieb@23605
   178
  let 
chaieb@23605
   179
   val rhs = eq |> prop_of |> HOLogic.dest_Trueprop  |> HOLogic.dest_eq |> snd
chaieb@23605
   180
   val nths = get_nths rhs []
chaieb@23605
   181
   val (vss,ns) = fold_rev (fn (_,(vs,n)) => fn (vss,ns) => 
chaieb@23605
   182
                             (insert (op aconv) vs vss, insert (op aconv) n ns)) nths ([],[]) 
chaieb@23605
   183
   val (vsns, ctxt') = Variable.variant_fixes (replicate (length vss) "vs") ctxt
chaieb@23605
   184
   val (xns, ctxt'') = Variable.variant_fixes (replicate (length nths) "x") ctxt' 
chaieb@23605
   185
   val thy = ProofContext.theory_of ctxt''
chaieb@23605
   186
   val cert = cterm_of thy
chaieb@23605
   187
   val certT = ctyp_of thy
chaieb@23605
   188
   val vsns_map = vss ~~ vsns
chaieb@23605
   189
   val xns_map = (fst (split_list nths)) ~~ xns
chaieb@23605
   190
   val subst = map (fn (nt, xn) => (nt, Var ((xn,0), fastype_of nt))) xns_map
chaieb@23605
   191
   val rhs_P = subst_free subst rhs
chaieb@23605
   192
   val (tyenv, tmenv) = Pattern.match 
chaieb@23605
   193
	                    thy (rhs_P, t)
chaieb@23605
   194
	                    (Envir.type_env (Envir.empty 0),Term.Vartab.empty)
chaieb@23605
   195
   val sbst = Envir.subst_vars (tyenv, tmenv)
chaieb@23605
   196
   val sbsT = Envir.typ_subst_TVars tyenv
chaieb@23605
   197
   val subst_ty = map (fn (n,(s,t)) => (certT (TVar (n, s)), certT t)) 
chaieb@23605
   198
                      (Vartab.dest tyenv)
chaieb@23605
   199
   val tml = Vartab.dest tmenv
chaieb@23605
   200
   val t's = map (fn xn => snd (valOf (AList.lookup (op =) tml (xn,0)))) xns (* FIXME : Express with sbst*)
chaieb@23605
   201
   val subst_ns = map (fn (Const _ $ vs $ n, Var (xn0,T)) => 
chaieb@23605
   202
                          (cert n, snd (valOf (AList.lookup (op =) tml xn0)) 
wenzelm@24630
   203
                             |> (index_of #> HOLogic.mk_nat #> cert))) 
chaieb@23605
   204
                      subst
chaieb@23605
   205
   val subst_vs = 
chaieb@23605
   206
    let 
chaieb@23605
   207
     fun ty (Const _ $ (vs as Var (vsn,lT)) $ n, Var (xn0,T)) = (certT T, certT (sbsT T))
chaieb@23605
   208
     fun h (Const _ $ (vs as Var (vsn,lT)) $ n, Var (xn0,T)) = 
chaieb@20564
   209
      let 
chaieb@23605
   210
       val cns = sbst (Const("List.list.Cons", T --> lT --> lT))
chaieb@23605
   211
       val lT' = sbsT lT
chaieb@23605
   212
       val (bsT,asT) = the (AList.lookup Type.could_unify (!bds) lT)
chaieb@23605
   213
       val vsn = valOf (AList.lookup (op =) vsns_map vs)
chaieb@23605
   214
       val cvs = cert (fold_rev (fn x => fn xs => cns$x$xs) bsT (Free (vsn, lT')))
chaieb@23605
   215
      in (cert vs, cvs) end
chaieb@23605
   216
    in map h subst end
chaieb@23605
   217
   val cts = map (fn ((vn,vi),(tT,t)) => (cert(Var ((vn,vi),tT)), cert t)) 
chaieb@23605
   218
                 (fold (AList.delete (fn (((a: string),_),(b,_)) => a = b)) 
chaieb@23605
   219
                       (map (fn n => (n,0)) xns) tml)
chaieb@23605
   220
   val substt = 
chaieb@23605
   221
    let val ih = Drule.cterm_rule (Thm.instantiate (subst_ty,[]))
chaieb@23605
   222
    in map (fn (v,t) => (ih v, ih t)) (subst_ns@subst_vs@cts)  end
chaieb@23605
   223
   val th = (instantiate (subst_ty, substt)  eq) RS sym
chaieb@23605
   224
  in  hd (Variable.export ctxt'' ctxt [th]) end)
chaieb@23605
   225
 handle MATCH => tryeqs eqs)
chaieb@23605
   226
in ([], fn _ => tryeqs (filter isat eqs))
chaieb@23605
   227
end;
chaieb@20374
   228
wenzelm@20319
   229
  (* Generic reification procedure: *)
wenzelm@20319
   230
  (* creates all needed cong rules and then just uses the theorem synthesis *)
chaieb@20564
   231
chaieb@23624
   232
  fun mk_congs ctxt raw_eqs = 
chaieb@23624
   233
 let
haftmann@21078
   234
  val fs = fold_rev (fn eq =>
haftmann@20853
   235
		     insert (op =) (eq |> prop_of |> HOLogic.dest_Trueprop 
chaieb@20564
   236
			 |> HOLogic.dest_eq |> fst |> strip_comb 
haftmann@21078
   237
			 |> fst)) raw_eqs []
chaieb@23624
   238
  val tys = fold_rev (fn f => fn ts => (f |> fastype_of |> binder_types |> tl) 
haftmann@21078
   239
				    union ts) fs []
chaieb@20564
   240
  val _ = bds := AList.make (fn _ => ([],[])) tys
wenzelm@20797
   241
  val (vs, ctxt') = Variable.variant_fixes (replicate (length tys) "vs") ctxt
chaieb@20564
   242
  val thy = ProofContext.theory_of ctxt'
chaieb@20564
   243
  val cert = cterm_of thy
chaieb@20564
   244
  val vstys = map (fn (t,v) => (t,SOME (cert (Free(v,t))))) 
chaieb@20564
   245
		  (tys ~~ vs)
chaieb@23624
   246
  val is_Var = can dest_Var
chaieb@23624
   247
  fun insteq eq vs = 
chaieb@23624
   248
   let
chaieb@23624
   249
     val subst = map (fn (v as Var(n,t)) => (cert v, (valOf o valOf) (AList.lookup (op =) vstys t)))  
chaieb@23624
   250
  (filter is_Var vs)
chaieb@23624
   251
   in Thm.instantiate ([],subst) eq
chaieb@20564
   252
   end
chaieb@20564
   253
  val eqs = map (fn eq => eq |> prop_of |> HOLogic.dest_Trueprop 
chaieb@23624
   254
			     |> HOLogic.dest_eq |> fst |> strip_comb |> snd |> tl
chaieb@20564
   255
			     |> (insteq eq)) raw_eqs
chaieb@20564
   256
  val (ps,congs) = split_list (map (mk_congeq ctxt' fs) eqs)
chaieb@23624
   257
in ps ~~ (Variable.export ctxt' ctxt congs)
chaieb@23624
   258
end
chaieb@20564
   259
chaieb@23648
   260
fun partition P [] = ([],[])
chaieb@23648
   261
  | partition P (x::xs) = 
chaieb@23648
   262
     let val (yes,no) = partition P xs
chaieb@23648
   263
     in if P x then (x::yes,no) else (yes, x::no) end
chaieb@23648
   264
chaieb@23648
   265
fun rearrange congs = 
chaieb@23648
   266
let 
chaieb@23648
   267
 fun P (_, th) = 
chaieb@23648
   268
  let val @{term "Trueprop"}$(Const ("op =",_) $l$_) = concl_of th
chaieb@23648
   269
  in can dest_Var l end
chaieb@23648
   270
 val (yes,no) = partition P congs 
chaieb@23648
   271
 in no @ yes end
chaieb@23648
   272
chaieb@23648
   273
chaieb@23648
   274
wenzelm@20319
   275
fun genreif ctxt raw_eqs t =
chaieb@20564
   276
 let 
chaieb@23648
   277
  val congs = rearrange (mk_congs ctxt raw_eqs)
chaieb@20564
   278
  val th = divide_and_conquer (decomp_genreif (mk_decompatom raw_eqs) congs) (t,ctxt)
chaieb@23624
   279
  fun is_listVar (Var (_,t)) = can dest_listT t
chaieb@23624
   280
       | is_listVar _ = false
chaieb@23624
   281
  val vars = th |> prop_of |> HOLogic.dest_Trueprop |> HOLogic.dest_eq |> snd
chaieb@23624
   282
	       |> strip_comb |> snd |> filter is_listVar
chaieb@20564
   283
  val cert = cterm_of (ProofContext.theory_of ctxt)
chaieb@23624
   284
  val cvs = map (fn (v as Var(n,t)) => (cert v, the (AList.lookup Type.could_unify (!bds) t) |> snd |> HOLogic.mk_list (dest_listT t) |> cert)) vars
chaieb@23624
   285
  val th' = instantiate ([], cvs) th
chaieb@20564
   286
  val t' = (fst o HOLogic.dest_eq o HOLogic.dest_Trueprop o prop_of) th'
chaieb@23643
   287
  val th'' = Goal.prove ctxt [] [] (HOLogic.mk_Trueprop (HOLogic.mk_eq (t, t')))
wenzelm@24044
   288
			(fn _ => simp_tac (local_simpset_of ctxt) 1)
chaieb@20564
   289
  val _ = bds := []
chaieb@23624
   290
in FWD trans [th'',th']
chaieb@23624
   291
end
wenzelm@20319
   292
chaieb@23648
   293
chaieb@23648
   294
fun genreflect ctxt conv corr_thms raw_eqs t =
chaieb@23648
   295
let 
chaieb@23648
   296
  val reifth = genreif ctxt raw_eqs t
chaieb@23648
   297
  fun trytrans [] = error "No suitable correctness theorem found"
chaieb@23648
   298
    | trytrans (th::ths) = 
chaieb@23648
   299
         (FWD trans [reifth, th RS sym] handle THM _ => trytrans ths)
chaieb@23648
   300
  val th = trytrans corr_thms
chaieb@23648
   301
  val ft = (Thm.dest_arg1 o Thm.dest_arg o Thm.dest_arg o cprop_of) th
chaieb@23648
   302
  val rth = conv ft
chaieb@23648
   303
in simplify (HOL_basic_ss addsimps raw_eqs addsimps [nth_Cons_0, nth_Cons_Suc])
chaieb@23648
   304
           (simplify (HOL_basic_ss addsimps [rth]) th)
chaieb@23648
   305
end
wenzelm@20319
   306
wenzelm@20319
   307
fun genreify_tac ctxt eqs to i = (fn st =>
wenzelm@20319
   308
  let
wenzelm@20319
   309
    val P = HOLogic.dest_Trueprop (List.nth (prems_of st, i - 1))
wenzelm@20319
   310
    val t = (case to of NONE => P | SOME x => x)
wenzelm@20319
   311
    val th = (genreif ctxt eqs t) RS ssubst
wenzelm@20319
   312
  in rtac th i st
wenzelm@20319
   313
  end);
wenzelm@20319
   314
wenzelm@20319
   315
    (* Reflection calls reification and uses the correctness *)
wenzelm@20319
   316
        (* theorem assumed to be the dead of the list *)
chaieb@23648
   317
fun gen_reflection_tac ctxt conv corr_thms raw_eqs to i = (fn st =>
haftmann@21878
   318
  let
haftmann@21878
   319
    val P = HOLogic.dest_Trueprop (nth (prems_of st) (i - 1));
haftmann@21878
   320
    val t = the_default P to;
chaieb@23648
   321
    val th = genreflect ctxt conv corr_thms raw_eqs t
haftmann@21878
   322
      RS ssubst;
nipkow@23791
   323
  in (rtac th i THEN TRY(rtac TrueI i)) st end);
haftmann@21878
   324
nipkow@23791
   325
fun reflection_tac ctxt = gen_reflection_tac ctxt Codegen.evaluation_conv;
wenzelm@20797
   326
end