src/Provers/Arith/cancel_sums.ML
author haftmann
Wed, 28 Jul 2010 14:09:56 +0200
changeset 38298 04a8de29e8f7
parent 35408 b48ab741683b
child 43232 23f352990944
permissions -rw-r--r--
dropped dead code
     1 (*  Title:      Provers/Arith/cancel_sums.ML
     2     Author:     Markus Wenzel and Stefan Berghofer, TU Muenchen
     3 
     4 Cancel common summands of balanced expressions:
     5 
     6   A + x + B ~~ A' + x + B'  ==  A + B ~~ A' + B'
     7 
     8 where + is AC0 and ~~ an appropriate balancing operation (e.g. =, <=, <, -).
     9 *)
    10 
    11 signature CANCEL_SUMS_DATA =
    12 sig
    13   (*abstract syntax*)
    14   val mk_sum: term list -> term
    15   val dest_sum: term -> term list
    16   val mk_bal: term * term -> term
    17   val dest_bal: term -> term * term
    18   (*rules*)
    19   val prove_conv: tactic -> (simpset -> tactic) -> simpset -> term * term -> thm
    20   val norm_tac: simpset -> tactic            (*AC0 etc.*)
    21   val uncancel_tac: cterm -> tactic          (*apply A ~~ B  ==  x + A ~~ x + B*)
    22 end;
    23 
    24 signature CANCEL_SUMS =
    25 sig
    26   val proc: simpset -> term -> thm option
    27 end;
    28 
    29 
    30 functor CancelSumsFun(Data: CANCEL_SUMS_DATA): CANCEL_SUMS =
    31 struct
    32 
    33 
    34 (* cancel *)
    35 
    36 fun cons1 x (xs, y, z) = (x :: xs, y, z);
    37 fun cons2 y (x, ys, z) = (x, y :: ys, z);
    38 
    39 (*symmetric difference of multisets -- assumed to be sorted wrt. Term_Ord.term_ord*)
    40 fun cancel ts [] vs = (ts, [], vs)
    41   | cancel [] us vs = ([], us, vs)
    42   | cancel (t :: ts) (u :: us) vs =
    43       (case Term_Ord.term_ord (t, u) of
    44         EQUAL => cancel ts us (t :: vs)
    45       | LESS => cons1 t (cancel ts (u :: us) vs)
    46       | GREATER => cons2 u (cancel (t :: ts) us vs));
    47 
    48 
    49 (* uncancel *)
    50 
    51 fun uncancel_sums_tac _ [] = all_tac
    52   | uncancel_sums_tac thy (t :: ts) =
    53       Data.uncancel_tac (Thm.cterm_of thy t) THEN
    54       uncancel_sums_tac thy ts;
    55 
    56 
    57 (* the simplification procedure *)
    58 
    59 fun proc ss t =
    60   (case try Data.dest_bal t of
    61     NONE => NONE
    62   | SOME bal =>
    63       let
    64         val thy = ProofContext.theory_of (Simplifier.the_context ss);
    65         val (ts, us) = pairself (sort Term_Ord.term_ord o Data.dest_sum) bal;
    66         val (ts', us', vs) = cancel ts us [];
    67       in
    68         if null vs then NONE
    69         else SOME
    70           (Data.prove_conv (uncancel_sums_tac thy vs) Data.norm_tac ss
    71             (t, Data.mk_bal (Data.mk_sum ts', Data.mk_sum us')))
    72       end);
    73 
    74 end;