src/Pure/IsaPlanner/rw_inst.ML
changeset 15959 366d39e95d3c
parent 15915 b0e8b37642a4
child 16179 fa7e70be26b0
equal deleted inserted replaced
15958:b4ea8bf8e2f7 15959:366d39e95d3c
   199           cross_instL (instL (ix, t) insts, (ix, t) :: (instL (ix, t) l));
   199           cross_instL (instL (ix, t) insts, (ix, t) :: (instL (ix, t) l));
   200 
   200 
   201     in cross_instL (insts, []) end;
   201     in cross_instL (insts, []) end;
   202 
   202 
   203 
   203 
   204 (* assume that rule and target_thm have distinct var names *)
   204 (* assume that rule and target_thm have distinct var names. THINK:
   205 (* THINK: efficient version with tables for vars for: target vars,
   205 efficient version with tables for vars for: target vars, introduced
   206 introduced vars, and rule vars, for quicker instantiation? *)
   206 vars, and rule vars, for quicker instantiation?  The outerterm defines
   207 (* The outerterm defines which part of the target_thm was modified *)
   207 which part of the target_thm was modified.  Note: we take Ts in the
   208 (* Note: we take Ts in the upterm order, ie last abstraction first.,
   208 upterm order, ie last abstraction first., and with an outeterm where
   209 and with an outeterm where the abstracted subterm has the arguments in
   209 the abstracted subterm has the arguments in the revered order, ie
   210 the revered order, ie first abstraction first. *)
   210 first abstraction first.  FakeTs has abstractions using the fake name
       
   211 - ie the name distinct from all other abstractions. *)
       
   212 
   211 fun rw ((nonfixed_typinsts, unprepinsts), FakeTs, Ts, outerterm) rule target_thm = 
   213 fun rw ((nonfixed_typinsts, unprepinsts), FakeTs, Ts, outerterm) rule target_thm = 
   212     let 
   214     let 
   213       (* general signature info *)
   215       (* general signature info *)
   214       val target_sign = (Thm.sign_of_thm target_thm);
   216       val target_sign = (Thm.sign_of_thm target_thm);
   215       val ctermify = Thm.cterm_of target_sign;
   217       val ctermify = Thm.cterm_of target_sign;
   217 
   219 
   218       (* fix all non-instantiated tvars *)
   220       (* fix all non-instantiated tvars *)
   219       val (fixtyinsts, othertfrees) = 
   221       val (fixtyinsts, othertfrees) = 
   220           mk_fixtvar_tyinsts nonfixed_typinsts
   222           mk_fixtvar_tyinsts nonfixed_typinsts
   221                              [Thm.prop_of rule, Thm.prop_of target_thm];
   223                              [Thm.prop_of rule, Thm.prop_of target_thm];
   222           
   224       val new_fixed_typs = map (fn ((s,i),(srt,ty)) => (Term.dest_TFree ty))
       
   225                                fixtyinsts;
   223       val typinsts = cross_inst_typs (nonfixed_typinsts @ fixtyinsts);
   226       val typinsts = cross_inst_typs (nonfixed_typinsts @ fixtyinsts);
   224 
   227 
   225       (* certified instantiations for types *)
   228       (* certified instantiations for types *)
   226       val ctyp_insts = 
   229       val ctyp_insts = 
   227           map (fn (ix,(s,ty)) => (ctypeify (TVar (ix,s)), ctypeify ty)) typinsts;
   230           map (fn (ix,(s,ty)) => (ctypeify (TVar (ix,s)), ctypeify ty)) 
       
   231               typinsts;
   228 
   232 
   229       (* type instantiated versions *)
   233       (* type instantiated versions *)
   230       val tgt_th_tyinst = Thm.instantiate (ctyp_insts,[]) target_thm;
   234       val tgt_th_tyinst = Thm.instantiate (ctyp_insts,[]) target_thm;
   231       val rule_tyinst =  Thm.instantiate (ctyp_insts,[]) rule;
   235       val rule_tyinst =  Thm.instantiate (ctyp_insts,[]) rule;
   232 
   236 
   233       val term_typ_inst = map (fn (ix,(srt,ty)) => (ix,ty)) typinsts;
   237       val term_typ_inst = map (fn (ix,(srt,ty)) => (ix,ty)) typinsts;
   234       (* type instanitated outer term *)
   238       (* type instanitated outer term *)
   235       val outerterm_tyinst = Term.subst_TVars term_typ_inst outerterm;
   239       val outerterm_tyinst = Term.subst_TVars term_typ_inst outerterm;
       
   240 
       
   241       val FakeTs_tyinst = map (apsnd (Term.typ_subst_TVars term_typ_inst)) 
       
   242                               FakeTs;
       
   243       val Ts_tyinst = map (apsnd (Term.typ_subst_TVars term_typ_inst)) 
       
   244                           Ts;
   236 
   245 
   237       (* type-instantiate the var instantiations *)
   246       (* type-instantiate the var instantiations *)
   238       val insts_tyinst = foldr (fn ((ix,(ty,t)),insts_tyinst) => 
   247       val insts_tyinst = foldr (fn ((ix,(ty,t)),insts_tyinst) => 
   239                             (ix, (Term.typ_subst_TVars term_typ_inst ty, 
   248                             (ix, (Term.typ_subst_TVars term_typ_inst ty, 
   240                                   Term.subst_TVars term_typ_inst t))
   249                                   Term.subst_TVars term_typ_inst t))
   266             |> Term.subst_Vars (map (fn (ix,(ty,t)) => (ix,t)) insts_tyinst_inst)
   275             |> Term.subst_Vars (map (fn (ix,(ty,t)) => (ix,t)) insts_tyinst_inst)
   267             |> Term.subst_Vars (map (fn ((ix,ty),t) => (ix,t)) renamings);
   276             |> Term.subst_Vars (map (fn ((ix,ty),t) => (ix,t)) renamings);
   268       val couter_inst = Thm.reflexive (ctermify outerterm_inst);
   277       val couter_inst = Thm.reflexive (ctermify outerterm_inst);
   269       val (cprems, abstract_rule_inst) = 
   278       val (cprems, abstract_rule_inst) = 
   270           rule_inst |> Thm.instantiate ([], cterm_renamings)
   279           rule_inst |> Thm.instantiate ([], cterm_renamings)
   271                     |> mk_abstractedrule FakeTs Ts;
   280                     |> mk_abstractedrule FakeTs_tyinst Ts_tyinst;
   272       val specific_tgt_rule = 
   281       val specific_tgt_rule = 
   273           beta_eta_contract
   282           beta_eta_contract
   274             (Thm.combination couter_inst abstract_rule_inst);
   283             (Thm.combination couter_inst abstract_rule_inst);
   275 
   284 
   276       (* create an instantiated version of the target thm *)
   285       (* create an instantiated version of the target thm *)