src/Provers/Arith/cancel_sums.ML
changeset 17613 072c21e31b42
parent 15531 08c8dad8e399
child 20044 92cc2f4c7335
equal deleted inserted replaced
17612:5b37787d2d9e 17613:072c21e31b42
    15   val mk_sum: term list -> term
    15   val mk_sum: term list -> term
    16   val dest_sum: term -> term list
    16   val dest_sum: term -> term list
    17   val mk_bal: term * term -> term
    17   val mk_bal: term * term -> term
    18   val dest_bal: term -> term * term
    18   val dest_bal: term -> term * term
    19   (*rules*)
    19   (*rules*)
    20   val prove_conv: tactic -> tactic -> Sign.sg -> term * term -> thm
    20   val prove_conv: tactic -> (simpset -> tactic) -> theory -> simpset -> term * term -> thm
    21   val norm_tac: tactic                   	(*AC0 etc.*)
    21   val norm_tac: simpset -> tactic            (*AC0 etc.*)
    22   val uncancel_tac: cterm -> tactic      	(*apply A ~~ B  ==  x + A ~~ x + B*)
    22   val uncancel_tac: cterm -> tactic          (*apply A ~~ B  ==  x + A ~~ x + B*)
    23 end;
    23 end;
    24 
    24 
    25 signature CANCEL_SUMS =
    25 signature CANCEL_SUMS =
    26 sig
    26 sig
    27   val proc: Sign.sg -> simpset -> term -> thm option
    27   val proc: theory -> simpset -> term -> thm option
    28 end;
    28 end;
    29 
    29 
    30 
    30 
    31 functor CancelSumsFun(Data: CANCEL_SUMS_DATA): CANCEL_SUMS =
    31 functor CancelSumsFun(Data: CANCEL_SUMS_DATA): CANCEL_SUMS =
    32 struct
    32 struct
    49 
    49 
    50 
    50 
    51 (* uncancel *)
    51 (* uncancel *)
    52 
    52 
    53 fun uncancel_sums_tac _ [] = all_tac
    53 fun uncancel_sums_tac _ [] = all_tac
    54   | uncancel_sums_tac sg (t :: ts) =
    54   | uncancel_sums_tac thy (t :: ts) =
    55       Data.uncancel_tac (Thm.cterm_of sg t) THEN
    55       Data.uncancel_tac (Thm.cterm_of thy t) THEN
    56       uncancel_sums_tac sg ts;
    56       uncancel_sums_tac thy ts;
    57 
    57 
    58 
    58 
    59 (* the simplification procedure *)
    59 (* the simplification procedure *)
    60 
    60 
    61 fun proc sg _ t =
    61 fun proc thy ss t =
    62   (case try Data.dest_bal t of
    62   (case try Data.dest_bal t of
    63     NONE => NONE
    63     NONE => NONE
    64   | SOME bal =>
    64   | SOME bal =>
    65       let
    65       let
    66         val (ts, us) = pairself (sort Term.term_ord o Data.dest_sum) bal;
    66         val (ts, us) = pairself (sort Term.term_ord o Data.dest_sum) bal;
    67         val (ts', us', vs) = cancel ts us [];
    67         val (ts', us', vs) = cancel ts us [];
    68       in
    68       in
    69         if null vs then NONE
    69         if null vs then NONE
    70         else SOME
    70         else SOME
    71           (Data.prove_conv (uncancel_sums_tac sg vs) Data.norm_tac sg
    71           (Data.prove_conv (uncancel_sums_tac thy vs) Data.norm_tac thy ss
    72             (t, Data.mk_bal (Data.mk_sum ts', Data.mk_sum us')))
    72             (t, Data.mk_bal (Data.mk_sum ts', Data.mk_sum us')))
    73       end);
    73       end);
    74 
    74 
    75 
    75 
    76 end;
    76 end;