36 then sift_terms plus (x, sift_terms plus (y, (lits,others))) |
36 then sift_terms plus (x, sift_terms plus (y, (lits,others))) |
37 else (lits, t::others) (*arbitrary summand*) |
37 else (lits, t::others) (*arbitrary summand*) |
38 | _ => (lits, t::others)); |
38 | _ => (lits, t::others)); |
39 |
39 |
40 (*A simproc to combine all literals in a associative nest*) |
40 (*A simproc to combine all literals in a associative nest*) |
41 fun proc ss lhs = |
41 fun proc ctxt lhs = |
42 let |
42 let |
43 val plus = (case lhs of f $ _ $ _ => f | _ => error "Assoc_fold: bad pattern") |
43 val plus = (case lhs of f $ _ $ _ => f | _ => error "Assoc_fold: bad pattern") |
44 val (lits, others) = sift_terms plus (lhs, ([],[])) |
44 val (lits, others) = sift_terms plus (lhs, ([],[])) |
45 val _ = length lits < 2 andalso raise Assoc_fail (*we can't reduce the number of terms*) |
45 val _ = length lits < 2 andalso raise Assoc_fail (*we can't reduce the number of terms*) |
46 val rhs = plus $ mk_sum plus lits $ mk_sum plus others |
46 val rhs = plus $ mk_sum plus lits $ mk_sum plus others |
47 val th = Goal.prove (Simplifier.the_context ss) [] [] (Logic.mk_equals (lhs, rhs)) |
47 val th = Goal.prove ctxt [] [] (Logic.mk_equals (lhs, rhs)) |
48 (fn _ => rtac Data.eq_reflection 1 THEN |
48 (fn _ => rtac Data.eq_reflection 1 THEN simp_tac (put_simpset Data.assoc_ss ctxt) 1) |
49 simp_tac (Simplifier.inherit_context ss Data.assoc_ss) 1) |
|
50 in SOME th end handle Assoc_fail => NONE; |
49 in SOME th end handle Assoc_fail => NONE; |
51 |
50 |
52 end; |
51 end; |