44 * Extract termination goals so that they can be put it into a goalstack, or |
44 * Extract termination goals so that they can be put it into a goalstack, or |
45 * have a tactic directly applied to them. |
45 * have a tactic directly applied to them. |
46 *--------------------------------------------------------------------------*) |
46 *--------------------------------------------------------------------------*) |
47 fun termination_goals rules = |
47 fun termination_goals rules = |
48 map (#1 o Type.freeze_thaw o HOLogic.dest_Trueprop) |
48 map (#1 o Type.freeze_thaw o HOLogic.dest_Trueprop) |
49 (foldr (fn (th,A) => union_term (prems_of th, A)) (rules, [])); |
49 (Library.foldr (fn (th,A) => union_term (prems_of th, A)) (rules, [])); |
50 |
50 |
51 (*--------------------------------------------------------------------------- |
51 (*--------------------------------------------------------------------------- |
52 * Finds the termination conditions in (highly massaged) definition and |
52 * Finds the termination conditions in (highly massaged) definition and |
53 * puts them into a goalstack. |
53 * puts them into a goalstack. |
54 *--------------------------------------------------------------------------*) |
54 *--------------------------------------------------------------------------*) |
103 Const("==",_)$_$_ => r |
103 Const("==",_)$_$_ => r |
104 | _ $(Const("op =",_)$_$_) => r RS eq_reflection |
104 | _ $(Const("op =",_)$_$_) => r RS eq_reflection |
105 | _ => r RS P_imp_P_eq_True |
105 | _ => r RS P_imp_P_eq_True |
106 |
106 |
107 (*Is this the best way to invoke the simplifier??*) |
107 (*Is this the best way to invoke the simplifier??*) |
108 fun rewrite L = rewrite_rule (map mk_meta_eq (filter(not o id_thm) L)) |
108 fun rewrite L = rewrite_rule (map mk_meta_eq (List.filter(not o id_thm) L)) |
109 |
109 |
110 fun join_assums th = |
110 fun join_assums th = |
111 let val {sign,...} = rep_thm th |
111 let val {sign,...} = rep_thm th |
112 val tych = cterm_of sign |
112 val tych = cterm_of sign |
113 val {lhs,rhs} = S.dest_eq(#2 (S.strip_forall (concl th))) |
113 val {lhs,rhs} = S.dest_eq(#2 (S.strip_forall (concl th))) |
205 to. Probably this is not important, and it would work fine, but, for now, I |
205 to. Probably this is not important, and it would work fine, but, for now, I |
206 prefer leaving more fine-grain control to the user. |
206 prefer leaving more fine-grain control to the user. |
207 -- Lucas Dixon, Aug 2004 *) |
207 -- Lucas Dixon, Aug 2004 *) |
208 local |
208 local |
209 fun get_related_thms i = |
209 fun get_related_thms i = |
210 mapfilter ((fn (r,x) => if x = i then SOME r else NONE)); |
210 List.mapPartial ((fn (r,x) => if x = i then SOME r else NONE)); |
211 |
211 |
212 fun solve_eq (th, [], i) = |
212 fun solve_eq (th, [], i) = |
213 raise ERROR_MESSAGE "derive_init_eqs: missing rules" |
213 raise ERROR_MESSAGE "derive_init_eqs: missing rules" |
214 | solve_eq (th, [a], i) = [(a, i)] |
214 | solve_eq (th, [a], i) = [(a, i)] |
215 | solve_eq (th, splitths as (_ :: _), i) = |
215 | solve_eq (th, splitths as (_ :: _), i) = |
224 fun derive_init_eqs sgn rules eqs = |
224 fun derive_init_eqs sgn rules eqs = |
225 let |
225 let |
226 val eqths = map (Thm.trivial o (Thm.cterm_of sgn) o HOLogic.mk_Trueprop) |
226 val eqths = map (Thm.trivial o (Thm.cterm_of sgn) o HOLogic.mk_Trueprop) |
227 eqs |
227 eqs |
228 fun countlist l = |
228 fun countlist l = |
229 (rev o snd o (foldl (fn ((i,L), e) => (i + 1,(e,i) :: L)))) ((0,[]), l) |
229 (rev o snd o (Library.foldl (fn ((i,L), e) => (i + 1,(e,i) :: L)))) ((0,[]), l) |
230 in |
230 in |
231 flat (map (fn (e,i) => solve_eq (e, (get_related_thms i rules), i)) |
231 List.concat (map (fn (e,i) => solve_eq (e, (get_related_thms i rules), i)) |
232 (countlist eqths)) |
232 (countlist eqths)) |
233 end; |
233 end; |
234 end; |
234 end; |
235 |
235 |
236 |
236 |