src/Provers/Arith/assoc_fold.ML
changeset 51717 9e7d1c139569
parent 35762 af3ff2ba4c54
child 60754 02924903a6fd
equal deleted inserted replaced
51709:19b47bfac6ef 51717:9e7d1c139569
    14   val is_numeral: term -> bool
    14   val is_numeral: term -> bool
    15 end;
    15 end;
    16 
    16 
    17 signature ASSOC_FOLD =
    17 signature ASSOC_FOLD =
    18 sig
    18 sig
    19   val proc: simpset -> term -> thm option
    19   val proc: Proof.context -> term -> thm option
    20 end;
    20 end;
    21 
    21 
    22 functor Assoc_Fold(Data: ASSOC_FOLD_DATA): ASSOC_FOLD =
    22 functor Assoc_Fold(Data: ASSOC_FOLD_DATA): ASSOC_FOLD =
    23 struct
    23 struct
    24 
    24 
    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;