52 val addcongs: simpset * thm list -> simpset |
53 val addcongs: simpset * thm list -> simpset |
53 val delcongs: simpset * thm list -> simpset |
54 val delcongs: simpset * thm list -> simpset |
54 val addsimprocs: simpset * simproc list -> simpset |
55 val addsimprocs: simpset * simproc list -> simpset |
55 val delsimprocs: simpset * simproc list -> simpset |
56 val delsimprocs: simpset * simproc list -> simpset |
56 val setmksimps: simpset * (thm -> thm list) -> simpset |
57 val setmksimps: simpset * (thm -> thm list) -> simpset |
|
58 val setmksimps2: simpset * (thm list -> thm -> thm list) -> simpset |
57 val setmkcong: simpset * (thm -> thm) -> simpset |
59 val setmkcong: simpset * (thm -> thm) -> simpset |
58 val setmksym: simpset * (thm -> thm option) -> simpset |
60 val setmksym: simpset * (thm -> thm option) -> simpset |
59 val setmkeqTrue: simpset * (thm -> thm option) -> simpset |
61 val setmkeqTrue: simpset * (thm -> thm option) -> simpset |
60 val settermless: simpset * (term * term -> bool) -> simpset |
62 val settermless: simpset * (term * term -> bool) -> simpset |
61 val setsubgoaler: simpset * (simpset -> int -> tactic) -> simpset |
63 val setsubgoaler: simpset * (simpset -> int -> tactic) -> simpset |
201 A congruence is `weak' if it avoids normalization of some argument. |
203 A congruence is `weak' if it avoids normalization of some argument. |
202 procs: discrimination net of simplification procedures |
204 procs: discrimination net of simplification procedures |
203 (functions that prove rewrite rules on the fly); |
205 (functions that prove rewrite rules on the fly); |
204 mk_rews: |
206 mk_rews: |
205 mk: turn simplification thms into rewrite rules; |
207 mk: turn simplification thms into rewrite rules; |
|
208 mk2: like mk but may also depend on the other premises |
206 mk_cong: prepare congruence rules; |
209 mk_cong: prepare congruence rules; |
207 mk_sym: turn == around; |
210 mk_sym: turn == around; |
208 mk_eq_True: turn P into P == True; |
211 mk_eq_True: turn P into P == True; |
209 termless: relation for ordered rewriting;*) |
212 termless: relation for ordered rewriting;*) |
210 |
213 |
211 type mk_rews = |
214 type mk_rews = |
212 {mk: thm -> thm list, |
215 {mk: thm -> thm list, |
|
216 mk2: thm list -> thm -> thm list, |
213 mk_cong: thm -> thm, |
217 mk_cong: thm -> thm, |
214 mk_sym: thm -> thm option, |
218 mk_sym: thm -> thm option, |
215 mk_eq_True: thm -> thm option}; |
219 mk_eq_True: thm -> thm option}; |
216 |
220 |
217 datatype simpset = |
221 datatype simpset = |
300 make_simpset ((Net.empty, [], [], 0), |
304 make_simpset ((Net.empty, [], [], 0), |
301 (([], []), Net.empty, mk_rews, termless, subgoal_tac, [], solvers)); |
305 (([], []), Net.empty, mk_rews, termless, subgoal_tac, [], solvers)); |
302 |
306 |
303 val basic_mk_rews: mk_rews = |
307 val basic_mk_rews: mk_rews = |
304 {mk = fn th => if can Logic.dest_equals (Thm.concl_of th) then [th] else [], |
308 {mk = fn th => if can Logic.dest_equals (Thm.concl_of th) then [th] else [], |
|
309 mk2 = fn thms => fn thm => [], |
305 mk_cong = I, |
310 mk_cong = I, |
306 mk_sym = Some o Drule.symmetric_fun, |
311 mk_sym = Some o Drule.symmetric_fun, |
307 mk_eq_True = K None}; |
312 mk_eq_True = K None}; |
308 |
313 |
309 in |
314 in |
484 in rrule_eq_True (thm', name, lhs', elhs', rhs', ss, thm) end) |
489 in rrule_eq_True (thm', name, lhs', elhs', rhs', ss, thm) end) |
485 end |
490 end |
486 else rrule_eq_True (thm, name, lhs, elhs, rhs, ss, thm) |
491 else rrule_eq_True (thm, name, lhs, elhs, rhs, ss, thm) |
487 end; |
492 end; |
488 |
493 |
489 fun extract_rews (Simpset (_, {mk_rews = {mk, ...}, ...}), thms) = |
494 fun extract_rews (Simpset ({prems, ...}, {mk_rews = {mk, ...}, ...}), thms) |
490 flat (map (fn thm => map (rpair (Thm.name_of_thm thm)) (mk thm)) thms); |
495 = flat (map (fn thm => map (rpair (Thm.name_of_thm thm)) (mk thm)) thms); |
|
496 |
|
497 fun extract_rews2 (Simpset ({prems, ...}, {mk_rews = {mk2, ...}, ...}), thms) |
|
498 = flat (map (fn thm => map (rpair (Thm.name_of_thm thm)) (mk2 prems thm)) thms); |
491 |
499 |
492 fun orient_comb_simps comb mk_rrule (ss, thms) = |
500 fun orient_comb_simps comb mk_rrule (ss, thms) = |
493 let |
501 let |
494 val rews = extract_rews (ss, thms); |
502 val rews = extract_rews (ss, thms); |
495 val rrules = flat (map mk_rrule rews); |
503 val rrules = flat (map mk_rrule rews); |
496 in foldl comb (ss, rrules) end; |
504 in foldl comb (ss, rrules) end; |
497 |
505 |
498 fun extract_safe_rrules (ss, thm) = |
506 fun extract_safe_rrules (ss, thm) = |
499 flat (map (orient_rrule ss) (extract_rews (ss, [thm]))); |
507 flat (map (orient_rrule ss) (extract_rews (ss, [thm]))); |
500 |
508 |
|
509 fun extract_safe_rrules2 (ss, thm) = |
|
510 flat (map (orient_rrule ss) (extract_rews2 (ss, [thm]))); |
|
511 |
501 (*add rewrite rules explicitly; do not reorient!*) |
512 (*add rewrite rules explicitly; do not reorient!*) |
502 fun ss addsimps thms = |
513 fun ss addsimps thms = |
503 orient_comb_simps (insert_rrule false) (mk_rrule ss) (ss, thms); |
514 orient_comb_simps (insert_rrule false) (mk_rrule ss) (ss, thms); |
504 |
515 |
|
516 |
|
517 fun add_prem2(ss,thm) = |
|
518 foldl (insert_rrule true) (ss,extract_safe_rrules2(ss,thm)) |
|
519 |> add_prems [thm]; |
|
520 |
|
521 fun add_prems2 thms ss = foldl add_prem2 (ss,thms); |
505 |
522 |
506 (* delsimps *) |
523 (* delsimps *) |
507 |
524 |
508 fun del_rrule (ss, rrule as {thm, elhs, ...}) = |
525 fun del_rrule (ss, rrule as {thm, elhs, ...}) = |
509 ss |> map_simpset1 (fn (rules, prems, bounds, depth) => |
526 ss |> map_simpset1 (fn (rules, prems, bounds, depth) => |
615 |
632 |
616 (* mk_rews *) |
633 (* mk_rews *) |
617 |
634 |
618 local |
635 local |
619 |
636 |
620 fun map_mk_rews f = map_simpset2 (fn (congs, procs, {mk, mk_cong, mk_sym, mk_eq_True}, |
637 fun map_mk_rews f = map_simpset2 (fn (congs, procs, {mk, mk2, mk_cong, mk_sym, mk_eq_True}, |
621 termless, subgoal_tac, loop_tacs, solvers) => |
638 termless, subgoal_tac, loop_tacs, solvers) => |
622 let val (mk', mk_cong', mk_sym', mk_eq_True') = f (mk, mk_cong, mk_sym, mk_eq_True) in |
639 let val (mk', mk2', mk_cong', mk_sym', mk_eq_True') = f (mk, mk2, mk_cong, mk_sym, mk_eq_True) in |
623 (congs, procs, {mk = mk', mk_cong = mk_cong', mk_sym = mk_sym', mk_eq_True = mk_eq_True'}, |
640 (congs, procs, {mk = mk', mk2 = mk2', mk_cong = mk_cong', mk_sym = mk_sym', mk_eq_True = mk_eq_True'}, |
624 termless, subgoal_tac, loop_tacs, solvers) |
641 termless, subgoal_tac, loop_tacs, solvers) |
625 end); |
642 end); |
626 |
643 |
627 in |
644 in |
628 |
645 |
629 fun ss setmksimps mk = ss |> map_mk_rews (fn (_, mk_cong, mk_sym, mk_eq_True) => |
646 fun ss setmksimps mk = ss |> map_mk_rews (fn (_, mk2, mk_cong, mk_sym, mk_eq_True) => |
630 (mk, mk_cong, mk_sym, mk_eq_True)); |
647 (mk, mk2, mk_cong, mk_sym, mk_eq_True)); |
631 |
648 |
632 fun ss setmkcong mk_cong = ss |> map_mk_rews (fn (mk, _, mk_sym, mk_eq_True) => |
649 fun ss setmksimps2 mk2 = ss |> map_mk_rews (fn (mk, _, mk_cong, mk_sym, mk_eq_True) => |
633 (mk, mk_cong, mk_sym, mk_eq_True)); |
650 (mk, mk2, mk_cong, mk_sym, mk_eq_True)); |
634 |
651 |
635 fun ss setmksym mk_sym = ss |> map_mk_rews (fn (mk, mk_cong, _, mk_eq_True) => |
652 fun ss setmkcong mk_cong = ss |> map_mk_rews (fn (mk, mk2, _, mk_sym, mk_eq_True) => |
636 (mk, mk_cong, mk_sym, mk_eq_True)); |
653 (mk, mk2, mk_cong, mk_sym, mk_eq_True)); |
637 |
654 |
638 fun ss setmkeqTrue mk_eq_True = ss |> map_mk_rews (fn (mk, mk_cong, mk_sym, _) => |
655 fun ss setmksym mk_sym = ss |> map_mk_rews (fn (mk, mk2, mk_cong, _, mk_eq_True) => |
639 (mk, mk_cong, mk_sym, mk_eq_True)); |
656 (mk, mk2, mk_cong, mk_sym, mk_eq_True)); |
|
657 |
|
658 fun ss setmkeqTrue mk_eq_True = ss |> map_mk_rews (fn (mk, mk2, mk_cong, mk_sym, _) => |
|
659 (mk, mk2, mk_cong, mk_sym, mk_eq_True)); |
640 |
660 |
641 end; |
661 end; |
642 |
662 |
643 |
663 |
644 (* termless *) |
664 (* termless *) |
997 else |
1017 else |
998 let val asm = assume prem |
1018 let val asm = assume prem |
999 in (extract_safe_rrules (ss, asm), Some asm) end |
1019 in (extract_safe_rrules (ss, asm), Some asm) end |
1000 |
1020 |
1001 and add_rrules (rrss, asms) ss = |
1021 and add_rrules (rrss, asms) ss = |
1002 foldl (insert_rrule true) (ss, flat rrss) |> add_prems (mapfilter I asms) |
1022 let val Asms = mapfilter I asms |
|
1023 in foldl (insert_rrule true) (ss, flat rrss) |> add_prems2 Asms end |
1003 |
1024 |
1004 and disch r (prem, eq) = |
1025 and disch r (prem, eq) = |
1005 let |
1026 let |
1006 val (lhs, rhs) = dest_eq eq; |
1027 val (lhs, rhs) = dest_eq eq; |
1007 val eq' = implies_elim (Thm.instantiate |
1028 val eq' = implies_elim (Thm.instantiate |