src/Tools/IsaPlanner/rw_inst.ML
changeset 30190 479806475f3c
parent 29270 0eade173f77e
child 33037 b22e44496dc2
equal deleted inserted replaced
30189:3633f560f4c3 30190:479806475f3c
   134       other uninstantiated vars in the hyps of the rule 
   134       other uninstantiated vars in the hyps of the rule 
   135       ie ?z in C ?z ?x ==> A ?x ?y = B ?x ?y *)
   135       ie ?z in C ?z ?x ==> A ?x ?y = B ?x ?y *)
   136 fun mk_renamings tgt rule_inst = 
   136 fun mk_renamings tgt rule_inst = 
   137     let
   137     let
   138       val rule_conds = Thm.prems_of rule_inst
   138       val rule_conds = Thm.prems_of rule_inst
   139       val names = foldr OldTerm.add_term_names [] (tgt :: rule_conds);
   139       val names = List.foldr OldTerm.add_term_names [] (tgt :: rule_conds);
   140       val (conds_tyvs,cond_vs) = 
   140       val (conds_tyvs,cond_vs) = 
   141           Library.foldl (fn ((tyvs, vs), t) => 
   141           Library.foldl (fn ((tyvs, vs), t) => 
   142                     (Library.union
   142                     (Library.union
   143                        (OldTerm.term_tvars t, tyvs),
   143                        (OldTerm.term_tvars t, tyvs),
   144                      Library.union 
   144                      Library.union 
   145                        (map Term.dest_Var (OldTerm.term_vars t), vs))) 
   145                        (map Term.dest_Var (OldTerm.term_vars t), vs))) 
   146                 (([],[]), rule_conds);
   146                 (([],[]), rule_conds);
   147       val termvars = map Term.dest_Var (OldTerm.term_vars tgt); 
   147       val termvars = map Term.dest_Var (OldTerm.term_vars tgt); 
   148       val vars_to_fix = Library.union (termvars, cond_vs);
   148       val vars_to_fix = Library.union (termvars, cond_vs);
   149       val (renamings, names2) = 
   149       val (renamings, names2) = 
   150           foldr (fn (((n,i),ty), (vs, names')) => 
   150           List.foldr (fn (((n,i),ty), (vs, names')) => 
   151                     let val n' = Name.variant names' n in
   151                     let val n' = Name.variant names' n in
   152                       ((((n,i),ty), Free (n', ty)) :: vs, n'::names')
   152                       ((((n,i),ty), Free (n', ty)) :: vs, n'::names')
   153                     end)
   153                     end)
   154                 ([], names) vars_to_fix;
   154                 ([], names) vars_to_fix;
   155     in renamings end;
   155     in renamings end;
   164    already instantiated (in ignore_ixs) from the list of terms. *)
   164    already instantiated (in ignore_ixs) from the list of terms. *)
   165 fun mk_fixtvar_tyinsts ignore_insts ts = 
   165 fun mk_fixtvar_tyinsts ignore_insts ts = 
   166     let 
   166     let 
   167       val ignore_ixs = map fst ignore_insts;
   167       val ignore_ixs = map fst ignore_insts;
   168       val (tvars, tfrees) = 
   168       val (tvars, tfrees) = 
   169             foldr (fn (t, (varixs, tfrees)) => 
   169             List.foldr (fn (t, (varixs, tfrees)) => 
   170                       (OldTerm.add_term_tvars (t,varixs),
   170                       (OldTerm.add_term_tvars (t,varixs),
   171                        OldTerm.add_term_tfrees (t,tfrees)))
   171                        OldTerm.add_term_tfrees (t,tfrees)))
   172                   ([],[]) ts;
   172                   ([],[]) ts;
   173         val unfixed_tvars = 
   173         val unfixed_tvars = 
   174             List.filter (fn (ix,s) => not (member (op =) ignore_ixs ix)) tvars;
   174             List.filter (fn (ix,s) => not (member (op =) ignore_ixs ix)) tvars;
   175         val (fixtyinsts, _) = foldr new_tfree ([], map fst tfrees) unfixed_tvars
   175         val (fixtyinsts, _) = List.foldr new_tfree ([], map fst tfrees) unfixed_tvars
   176     in (fixtyinsts, tfrees) end;
   176     in (fixtyinsts, tfrees) end;
   177 
   177 
   178 
   178 
   179 (* cross-instantiate the instantiations - ie for each instantiation
   179 (* cross-instantiate the instantiations - ie for each instantiation
   180 replace all occurances in other instantiations - no loops are possible
   180 replace all occurances in other instantiations - no loops are possible
   246                               FakeTs;
   246                               FakeTs;
   247       val Ts_tyinst = map (apsnd (Term.typ_subst_TVars term_typ_inst)) 
   247       val Ts_tyinst = map (apsnd (Term.typ_subst_TVars term_typ_inst)) 
   248                           Ts;
   248                           Ts;
   249 
   249 
   250       (* type-instantiate the var instantiations *)
   250       (* type-instantiate the var instantiations *)
   251       val insts_tyinst = foldr (fn ((ix,(ty,t)),insts_tyinst) => 
   251       val insts_tyinst = List.foldr (fn ((ix,(ty,t)),insts_tyinst) => 
   252                             (ix, (Term.typ_subst_TVars term_typ_inst ty, 
   252                             (ix, (Term.typ_subst_TVars term_typ_inst ty, 
   253                                   Term.subst_TVars term_typ_inst t))
   253                                   Term.subst_TVars term_typ_inst t))
   254                             :: insts_tyinst)
   254                             :: insts_tyinst)
   255                         [] unprepinsts;
   255                         [] unprepinsts;
   256 
   256