src/Provers/Arith/fast_lin_arith.ML
changeset 32740 9dd0a2f83429
parent 32283 3bebc195c124
child 32952 aeb1e44fbc19
equal deleted inserted replaced
32739:31e75ad9ae17 32740:9dd0a2f83429
    94                  number_of : serial * (theory -> typ -> int -> cterm)}
    94                  number_of : serial * (theory -> typ -> int -> cterm)}
    95                  -> {add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    95                  -> {add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    96                      lessD: thm list, neqE: thm list, simpset: Simplifier.simpset,
    96                      lessD: thm list, neqE: thm list, simpset: Simplifier.simpset,
    97                      number_of : serial * (theory -> typ -> int -> cterm)})
    97                      number_of : serial * (theory -> typ -> int -> cterm)})
    98                 -> Context.generic -> Context.generic
    98                 -> Context.generic -> Context.generic
    99   val trace: bool ref
    99   val trace: bool Unsynchronized.ref
   100   val warning_count: int ref;
   100   val warning_count: int Unsynchronized.ref;
   101 end;
   101 end;
   102 
   102 
   103 functor Fast_Lin_Arith
   103 functor Fast_Lin_Arith
   104   (structure LA_Logic: LIN_ARITH_LOGIC and LA_Data: LIN_ARITH_DATA): FAST_LIN_ARITH =
   104   (structure LA_Logic: LIN_ARITH_LOGIC and LA_Data: LIN_ARITH_DATA): FAST_LIN_ARITH =
   105 struct
   105 struct
   150 (* possible optimizations:
   150 (* possible optimizations:
   151    use (var,coeff) rep or vector rep  tp save space;
   151    use (var,coeff) rep or vector rep  tp save space;
   152    treat non-negative atoms separately rather than adding 0 <= atom
   152    treat non-negative atoms separately rather than adding 0 <= atom
   153 *)
   153 *)
   154 
   154 
   155 val trace = ref false;
   155 val trace = Unsynchronized.ref false;
   156 
   156 
   157 datatype lineq_type = Eq | Le | Lt;
   157 datatype lineq_type = Eq | Le | Lt;
   158 
   158 
   159 datatype injust = Asm of int
   159 datatype injust = Asm of int
   160                 | Nat of int (* index of atom *)
   160                 | Nat of int (* index of atom *)
   424   (if !trace then tracing (cat_lines [msg, Syntax.string_of_term ctxt t]) else (); t)
   424   (if !trace then tracing (cat_lines [msg, Syntax.string_of_term ctxt t]) else (); t)
   425 
   425 
   426 fun trace_msg msg =
   426 fun trace_msg msg =
   427   if !trace then tracing msg else ();
   427   if !trace then tracing msg else ();
   428 
   428 
   429 val warning_count = ref 0;
   429 val warning_count = Unsynchronized.ref 0;
   430 val warning_count_max = 10;
   430 val warning_count_max = 10;
   431 
   431 
   432 val union_term = curry (gen_union Pattern.aeconv);
   432 val union_term = curry (gen_union Pattern.aeconv);
   433 val union_bterm = curry (gen_union
   433 val union_bterm = curry (gen_union
   434   (fn ((b:bool, t), (b', t')) => b = b' andalso Pattern.aeconv (t, t')));
   434   (fn ((b:bool, t), (b', t')) => b = b' andalso Pattern.aeconv (t, t')));
   531       val fls = simplify simpset' thm;
   531       val fls = simplify simpset' thm;
   532       val _ = trace_thm ctxt "After simplification:" fls;
   532       val _ = trace_thm ctxt "After simplification:" fls;
   533       val _ =
   533       val _ =
   534         if LA_Logic.is_False fls then ()
   534         if LA_Logic.is_False fls then ()
   535         else
   535         else
   536           let val count = CRITICAL (fn () => inc warning_count) in
   536           let val count = CRITICAL (fn () => Unsynchronized.inc warning_count) in
   537             if count > warning_count_max then ()
   537             if count > warning_count_max then ()
   538             else
   538             else
   539               (tracing (cat_lines
   539               (tracing (cat_lines
   540                 (["Assumptions:"] @ map (Display.string_of_thm ctxt) asms @ [""] @
   540                 (["Assumptions:"] @ map (Display.string_of_thm ctxt) asms @ [""] @
   541                  ["Proved:", Display.string_of_thm ctxt fls, ""] @
   541                  ["Proved:", Display.string_of_thm ctxt fls, ""] @