67 fun is_of_fs_name T = Sign.of_sort thy (T, [Sign.intern_class thy ("fs_"^atom_basename)]); |
67 fun is_of_fs_name T = Sign.of_sort thy (T, [Sign.intern_class thy ("fs_"^atom_basename)]); |
68 (* rebuild de bruijn indices *) |
68 (* rebuild de bruijn indices *) |
69 val bvs = map_index (Bound o fst) ps; |
69 val bvs = map_index (Bound o fst) ps; |
70 (* select variables of the right class *) |
70 (* select variables of the right class *) |
71 val vs = filter (fn t => is_of_fs_name (fastype_of1 (Ts, t))) |
71 val vs = filter (fn t => is_of_fs_name (fastype_of1 (Ts, t))) |
72 (OldTerm.term_frees goal @ bvs); |
72 (Misc_Legacy.term_frees goal @ bvs); |
73 (* build the tuple *) |
73 (* build the tuple *) |
74 val s = (Library.foldr1 (fn (v, s) => |
74 val s = (Library.foldr1 (fn (v, s) => |
75 HOLogic.pair_const (fastype_of1 (Ts, v)) (fastype_of1 (Ts, s)) $ v $ s) vs) |
75 HOLogic.pair_const (fastype_of1 (Ts, v)) (fastype_of1 (Ts, s)) $ v $ s) vs) |
76 handle TERM _ => HOLogic.unit; |
76 handle TERM _ => HOLogic.unit; |
77 val fs_name_thm = get_dyn_thm thy ("fs_"^atom_basename^"1") atom_basename; |
77 val fs_name_thm = get_dyn_thm thy ("fs_"^atom_basename^"1") atom_basename; |
78 val at_name_inst_thm = get_dyn_thm thy ("at_"^atom_basename^"_inst") atom_basename; |
78 val at_name_inst_thm = get_dyn_thm thy ("at_"^atom_basename^"_inst") atom_basename; |
79 val exists_fresh' = at_name_inst_thm RS at_exists_fresh'; |
79 val exists_fresh' = at_name_inst_thm RS at_exists_fresh'; |
80 (* find the variable we want to instantiate *) |
80 (* find the variable we want to instantiate *) |
81 val x = hd (OldTerm.term_vars (prop_of exists_fresh')); |
81 val x = hd (Misc_Legacy.term_vars (prop_of exists_fresh')); |
82 in |
82 in |
83 (cut_inst_tac_term' [(x,s)] exists_fresh' 1 THEN |
83 (cut_inst_tac_term' [(x,s)] exists_fresh' 1 THEN |
84 rtac fs_name_thm 1 THEN |
84 rtac fs_name_thm 1 THEN |
85 etac exE 1) thm |
85 etac exE 1) thm |
86 handle Empty => all_tac thm (* if we collected no variables then we do nothing *) |
86 handle Empty => all_tac thm (* if we collected no variables then we do nothing *) |
135 val ss = global_simpset_of thy; |
135 val ss = global_simpset_of thy; |
136 val abs_fresh = Global_Theory.get_thms thy "abs_fresh"; |
136 val abs_fresh = Global_Theory.get_thms thy "abs_fresh"; |
137 val fresh_perm_app = Global_Theory.get_thms thy "fresh_perm_app"; |
137 val fresh_perm_app = Global_Theory.get_thms thy "fresh_perm_app"; |
138 val ss' = ss addsimps fresh_prod::abs_fresh; |
138 val ss' = ss addsimps fresh_prod::abs_fresh; |
139 val ss'' = ss' addsimps fresh_perm_app; |
139 val ss'' = ss' addsimps fresh_perm_app; |
140 val x = hd (tl (OldTerm.term_vars (prop_of exI))); |
140 val x = hd (tl (Misc_Legacy.term_vars (prop_of exI))); |
141 val goal = nth (prems_of thm) (i-1); |
141 val goal = nth (prems_of thm) (i-1); |
142 val atom_name_opt = get_inner_fresh_fun goal; |
142 val atom_name_opt = get_inner_fresh_fun goal; |
143 val n = length (Logic.strip_params goal); |
143 val n = length (Logic.strip_params goal); |
144 (* Here we rely on the fact that the variable introduced by generate_fresh_tac *) |
144 (* Here we rely on the fact that the variable introduced by generate_fresh_tac *) |
145 (* is the last one in the list, the inner one *) |
145 (* is the last one in the list, the inner one *) |
150 let |
150 let |
151 val atom_basename = Long_Name.base_name atom_name; |
151 val atom_basename = Long_Name.base_name atom_name; |
152 val pt_name_inst = get_dyn_thm thy ("pt_"^atom_basename^"_inst") atom_basename; |
152 val pt_name_inst = get_dyn_thm thy ("pt_"^atom_basename^"_inst") atom_basename; |
153 val at_name_inst = get_dyn_thm thy ("at_"^atom_basename^"_inst") atom_basename; |
153 val at_name_inst = get_dyn_thm thy ("at_"^atom_basename^"_inst") atom_basename; |
154 fun inst_fresh vars params i st = |
154 fun inst_fresh vars params i st = |
155 let val vars' = OldTerm.term_vars (prop_of st); |
155 let val vars' = Misc_Legacy.term_vars (prop_of st); |
156 val thy = theory_of_thm st; |
156 val thy = theory_of_thm st; |
157 in case subtract (op =) vars vars' of |
157 in case subtract (op =) vars vars' of |
158 [x] => Seq.single (Thm.instantiate ([],[(cterm_of thy x,cterm_of thy (list_abs (params,Bound 0)))]) st) |
158 [x] => Seq.single (Thm.instantiate ([],[(cterm_of thy x,cterm_of thy (list_abs (params,Bound 0)))]) st) |
159 | _ => error "fresh_fun_simp: Too many variables, please report." |
159 | _ => error "fresh_fun_simp: Too many variables, please report." |
160 end |
160 end |
161 in |
161 in |
162 ((fn st => |
162 ((fn st => |
163 let |
163 let |
164 val vars = OldTerm.term_vars (prop_of st); |
164 val vars = Misc_Legacy.term_vars (prop_of st); |
165 val params = Logic.strip_params (nth (prems_of st) (i-1)) |
165 val params = Logic.strip_params (nth (prems_of st) (i-1)) |
166 (* The tactics which solve the subgoals generated |
166 (* The tactics which solve the subgoals generated |
167 by the conditionnal rewrite rule. *) |
167 by the conditionnal rewrite rule. *) |
168 val post_rewrite_tacs = |
168 val post_rewrite_tacs = |
169 [rtac pt_name_inst, |
169 [rtac pt_name_inst, |