1.1 --- a/src/Provers/Arith/cancel_factor.ML Wed Jul 28 11:42:48 2010 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,70 +0,0 @@
1.4 -(* Title: Provers/Arith/cancel_factor.ML
1.5 - Author: Markus Wenzel and Stefan Berghofer, TU Muenchen
1.6 -
1.7 -Cancel common constant factor from balanced exression (e.g. =, <=, < of sums).
1.8 -*)
1.9 -
1.10 -signature CANCEL_FACTOR_DATA =
1.11 -sig
1.12 - (*abstract syntax*)
1.13 - val mk_sum: term list -> term
1.14 - val dest_sum: term -> term list
1.15 - val mk_bal: term * term -> term
1.16 - val dest_bal: term -> term * term
1.17 - (*rules*)
1.18 - val prove_conv: tactic -> tactic -> Proof.context -> term * term -> thm
1.19 - val norm_tac: tactic (*AC0 etc.*)
1.20 - val multiply_tac: integer -> tactic
1.21 - (*apply a ~~ b == k * a ~~ k * b (for k > 0)*)
1.22 -end;
1.23 -
1.24 -signature CANCEL_FACTOR =
1.25 -sig
1.26 - val proc: simpset -> term -> thm option
1.27 -end;
1.28 -
1.29 -
1.30 -functor CancelFactorFun(Data: CANCEL_FACTOR_DATA): CANCEL_FACTOR =
1.31 -struct
1.32 -
1.33 -
1.34 -(* count terms *)
1.35 -
1.36 -fun ins_term (t, []) = [(t, 1)]
1.37 - | ins_term (t, (u, k) :: uks) =
1.38 - if t aconv u then (u, k + 1) :: uks
1.39 - else (t, 1) :: (u, k) :: uks;
1.40 -
1.41 -fun count_terms ts = foldr ins_term (sort Term_Ord.term_ord ts, []);
1.42 -
1.43 -
1.44 -(* divide sum *)
1.45 -
1.46 -fun div_sum d =
1.47 - Data.mk_sum o maps (fn (t, k) => replicate (k div d) t);
1.48 -
1.49 -
1.50 -(* the simplification procedure *)
1.51 -
1.52 -fun proc ss t =
1.53 - (case try Data.dest_bal t of
1.54 - NONE => NONE
1.55 - | SOME bal =>
1.56 - (case pairself Data.dest_sum bal of
1.57 - ([_], _) => NONE
1.58 - | (_, [_]) => NONE
1.59 - | ts_us =>
1.60 - let
1.61 - val (tks, uks) = pairself count_terms ts_us;
1.62 - val d = 0
1.63 - |> fold (Integer.gcd o snd) tks
1.64 - |> fold (Integer.gcd o snd) uks;
1.65 - in
1.66 - if d = 0 orelse d = 1 then NONE
1.67 - else SOME
1.68 - (Data.prove_conv (Data.multiply_tac d) Data.norm_tac (Simplifier.the_context ss)
1.69 - (t, Data.mk_bal (div_sum d tks, div_sum d uks)))
1.70 - end));
1.71 -
1.72 -
1.73 -end;