153 Abs(_,_,body) => add_term_vars(body,hvars) |
153 Abs(_,_,body) => add_term_vars(body,hvars) |
154 | _$_ => let val (f,args) = strip_comb tm |
154 | _$_ => let val (f,args) = strip_comb tm |
155 in case f of |
155 in case f of |
156 Const(c,T) => |
156 Const(c,T) => |
157 if c mem ccs |
157 if c mem ccs |
158 then Library.foldr add_hvars (args,hvars) |
158 then foldr add_hvars hvars args |
159 else add_term_vars(tm,hvars) |
159 else add_term_vars(tm,hvars) |
160 | _ => add_term_vars(tm,hvars) |
160 | _ => add_term_vars(tm,hvars) |
161 end |
161 end |
162 | _ => hvars; |
162 | _ => hvars; |
163 in add_hvars end; |
163 in add_hvars end; |
165 fun add_new_asm_vars new_asms = |
165 fun add_new_asm_vars new_asms = |
166 let fun itf((tm,at),vars) = |
166 let fun itf((tm,at),vars) = |
167 if at then vars else add_term_vars(tm,vars) |
167 if at then vars else add_term_vars(tm,vars) |
168 fun add_list(tm,al,vars) = let val (_,tml) = strip_comb tm |
168 fun add_list(tm,al,vars) = let val (_,tml) = strip_comb tm |
169 in if length(tml)=length(al) |
169 in if length(tml)=length(al) |
170 then Library.foldr itf (tml~~al,vars) |
170 then foldr itf vars (tml~~al) |
171 else vars |
171 else vars |
172 end |
172 end |
173 fun add_vars (tm,vars) = case tm of |
173 fun add_vars (tm,vars) = case tm of |
174 Abs (_,_,body) => add_vars(body,vars) |
174 Abs (_,_,body) => add_vars(body,vars) |
175 | r$s => (case head_of tm of |
175 | r$s => (case head_of tm of |
186 (* thm': [?z -> l; Prems; r -> ?t] ==> ?z -> ?t *) |
186 (* thm': [?z -> l; Prems; r -> ?t] ==> ?z -> ?t *) |
187 val nops = nprems_of thm' |
187 val nops = nprems_of thm' |
188 val lhs = rhs_of_eq 1 thm' |
188 val lhs = rhs_of_eq 1 thm' |
189 val rhs = lhs_of_eq nops thm' |
189 val rhs = lhs_of_eq nops thm' |
190 val asms = tl(rev(tl(prems_of thm'))) |
190 val asms = tl(rev(tl(prems_of thm'))) |
191 val hvars = Library.foldr (add_hidden_vars ccs) (lhs::rhs::asms,[]) |
191 val hvars = foldr (add_hidden_vars ccs) [] (lhs::rhs::asms) |
192 val hvars = add_new_asm_vars new_asms (rhs,hvars) |
192 val hvars = add_new_asm_vars new_asms (rhs,hvars) |
193 fun it_asms (asm,hvars) = |
193 fun it_asms (asm,hvars) = |
194 if atomic asm then add_new_asm_vars new_asms (asm,hvars) |
194 if atomic asm then add_new_asm_vars new_asms (asm,hvars) |
195 else add_term_frees(asm,hvars) |
195 else add_term_frees(asm,hvars) |
196 val hvars = Library.foldr it_asms (asms,hvars) |
196 val hvars = foldr it_asms hvars asms |
197 val hvs = map (#1 o dest_Var) hvars |
197 val hvs = map (#1 o dest_Var) hvars |
198 val refl1_tac = refl_tac 1 |
198 val refl1_tac = refl_tac 1 |
199 fun norm_step_tac st = st |> |
199 fun norm_step_tac st = st |> |
200 (case head_of(rhs_of_eq 1 st) of |
200 (case head_of(rhs_of_eq 1 st) of |
201 Var(ixn,_) => if ixn mem hvs then refl1_tac |
201 Var(ixn,_) => if ixn mem hvs then refl1_tac |
247 Net.insert_term((concl_of th, th), net, Drule.eq_thm_prop) |
247 Net.insert_term((concl_of th, th), net, Drule.eq_thm_prop) |
248 handle Net.INSERT => |
248 handle Net.INSERT => |
249 (writeln"\nDuplicate rewrite or congruence rule:"; print_thm th; |
249 (writeln"\nDuplicate rewrite or congruence rule:"; print_thm th; |
250 net); |
250 net); |
251 |
251 |
252 val insert_thms = Library.foldr insert_thm_warn; |
252 val insert_thms = foldr insert_thm_warn; |
253 |
253 |
254 fun addrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
254 fun addrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
255 splits,split_consts}, thm) = |
255 splits,split_consts}, thm) = |
256 let val thms = mk_simps thm |
256 let val thms = mk_simps thm |
257 in SS{auto_tac=auto_tac,congs=congs, cong_net=cong_net, mk_simps=mk_simps, |
257 in SS{auto_tac=auto_tac,congs=congs, cong_net=cong_net, mk_simps=mk_simps, |
258 simps = (thm,thms)::simps, simp_net = insert_thms(thms,simp_net), |
258 simps = (thm,thms)::simps, simp_net = insert_thms simp_net thms, |
259 splits=splits,split_consts=split_consts} |
259 splits=splits,split_consts=split_consts} |
260 end; |
260 end; |
261 |
261 |
262 val op addrews = Library.foldl addrew; |
262 val op addrews = Library.foldl addrew; |
263 |
263 |
264 fun op addcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
264 fun op addcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
265 splits,split_consts}, thms) = |
265 splits,split_consts}, thms) = |
266 let val congs' = thms @ congs; |
266 let val congs' = thms @ congs; |
267 in SS{auto_tac=auto_tac, congs= congs', |
267 in SS{auto_tac=auto_tac, congs= congs', |
268 cong_net= insert_thms (map mk_trans thms,cong_net), |
268 cong_net= insert_thms cong_net (map mk_trans thms), |
269 mk_simps= normed_rews congs', simps=simps, simp_net=simp_net, |
269 mk_simps= normed_rews congs', simps=simps, simp_net=simp_net, |
270 splits=splits,split_consts=split_consts} |
270 splits=splits,split_consts=split_consts} |
271 end; |
271 end; |
272 |
272 |
273 fun split_err() = error("split rule not of the form ?P(c(...)) = ..."); |
273 fun split_err() = error("split rule not of the form ?P(c(...)) = ..."); |
292 Net.delete_term((concl_of th, th), net, Drule.eq_thm_prop) |
292 Net.delete_term((concl_of th, th), net, Drule.eq_thm_prop) |
293 handle Net.DELETE => |
293 handle Net.DELETE => |
294 (writeln"\nNo such rewrite or congruence rule:"; print_thm th; |
294 (writeln"\nNo such rewrite or congruence rule:"; print_thm th; |
295 net); |
295 net); |
296 |
296 |
297 val delete_thms = Library.foldr delete_thm_warn; |
297 val delete_thms = foldr delete_thm_warn; |
298 |
298 |
299 fun op delcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
299 fun op delcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
300 splits,split_consts}, thms) = |
300 splits,split_consts}, thms) = |
301 let val congs' = Library.foldl (gen_rem Drule.eq_thm_prop) (congs,thms) |
301 let val congs' = Library.foldl (gen_rem Drule.eq_thm_prop) (congs,thms) |
302 in SS{auto_tac=auto_tac, congs= congs', |
302 in SS{auto_tac=auto_tac, congs= congs', |
303 cong_net= delete_thms(map mk_trans thms,cong_net), |
303 cong_net= delete_thms cong_net (map mk_trans thms), |
304 mk_simps= normed_rews congs', simps=simps, simp_net=simp_net, |
304 mk_simps= normed_rews congs', simps=simps, simp_net=simp_net, |
305 splits=splits,split_consts=split_consts} |
305 splits=splits,split_consts=split_consts} |
306 end; |
306 end; |
307 |
307 |
308 fun delrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
308 fun delrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net, |
312 | find([],simps') = (writeln"\nNo such rewrite or congruence rule:"; |
312 | find([],simps') = (writeln"\nNo such rewrite or congruence rule:"; |
313 print_thm thm; |
313 print_thm thm; |
314 ([],simps')) |
314 ([],simps')) |
315 val (thms,simps') = find(simps,[]) |
315 val (thms,simps') = find(simps,[]) |
316 in SS{auto_tac=auto_tac, congs=congs, cong_net=cong_net, mk_simps=mk_simps, |
316 in SS{auto_tac=auto_tac, congs=congs, cong_net=cong_net, mk_simps=mk_simps, |
317 simps = simps', simp_net = delete_thms(thms,simp_net), |
317 simps = simps', simp_net = delete_thms simp_net thms, |
318 splits=splits,split_consts=split_consts} |
318 splits=splits,split_consts=split_consts} |
319 end; |
319 end; |
320 |
320 |
321 val op delrews = Library.foldl delrew; |
321 val op delrews = Library.foldl delrew; |
322 |
322 |
458 fun add_asms(ss,thm,a,anet,ats,cs) = |
458 fun add_asms(ss,thm,a,anet,ats,cs) = |
459 let val As = strip_varify(nth_subgoal i thm, a, []); |
459 let val As = strip_varify(nth_subgoal i thm, a, []); |
460 val thms = map (trivial o cterm_of(#sign(rep_thm(thm))))As; |
460 val thms = map (trivial o cterm_of(#sign(rep_thm(thm))))As; |
461 val new_rws = flat(map mk_rew_rules thms); |
461 val new_rws = flat(map mk_rew_rules thms); |
462 val rwrls = map mk_trans (flat(map mk_rew_rules thms)); |
462 val rwrls = map mk_trans (flat(map mk_rew_rules thms)); |
463 val anet' = Library.foldr lhs_insert_thm (rwrls,anet) |
463 val anet' = foldr lhs_insert_thm anet rwrls |
464 in if !tracing andalso not(null new_rws) |
464 in if !tracing andalso not(null new_rws) |
465 then (writeln"Adding rewrites:"; prths new_rws; ()) |
465 then (writeln"Adding rewrites:"; prths new_rws; ()) |
466 else (); |
466 else (); |
467 (ss,thm,anet',anet::ats,cs) |
467 (ss,thm,anet',anet::ats,cs) |
468 end; |
468 end; |