src/Provers/Arith/fast_lin_arith.ML
changeset 27020 b5b8afc9fdcd
parent 26945 9cd13e810998
child 30406 15dc25f8a0e2
equal deleted inserted replaced
27019:9ad9d6554d05 27020:b5b8afc9fdcd
    90                  lessD: thm list, neqE: thm list, simpset: Simplifier.simpset}
    90                  lessD: thm list, neqE: thm list, simpset: Simplifier.simpset}
    91                  -> {add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    91                  -> {add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    92                      lessD: thm list, neqE: thm list, simpset: Simplifier.simpset})
    92                      lessD: thm list, neqE: thm list, simpset: Simplifier.simpset})
    93                 -> Context.generic -> Context.generic
    93                 -> Context.generic -> Context.generic
    94   val trace: bool ref
    94   val trace: bool ref
       
    95   val warning_count: int ref;
    95   val cut_lin_arith_tac: simpset -> int -> tactic
    96   val cut_lin_arith_tac: simpset -> int -> tactic
    96   val lin_arith_tac: Proof.context -> bool -> int -> tactic
    97   val lin_arith_tac: Proof.context -> bool -> int -> tactic
    97   val lin_arith_simproc: simpset -> term -> thm option
    98   val lin_arith_simproc: simpset -> term -> thm option
    98 end;
    99 end;
    99 
   100 
   417   (if !trace then tracing (cat_lines [msg, Syntax.string_of_term ctxt t]) else (); t)
   418   (if !trace then tracing (cat_lines [msg, Syntax.string_of_term ctxt t]) else (); t)
   418 
   419 
   419 fun trace_msg msg =
   420 fun trace_msg msg =
   420   if !trace then tracing msg else ();
   421   if !trace then tracing msg else ();
   421 
   422 
       
   423 val warning_count = ref 0;
       
   424 val warning_count_max = 10;
       
   425 
   422 val union_term = curry (gen_union Pattern.aeconv);
   426 val union_term = curry (gen_union Pattern.aeconv);
   423 val union_bterm = curry (gen_union
   427 val union_bterm = curry (gen_union
   424   (fn ((b:bool, t), (b', t')) => b = b' andalso Pattern.aeconv (t, t')));
   428   (fn ((b:bool, t), (b', t')) => b = b' andalso Pattern.aeconv (t, t')));
   425 
   429 
   426 (* FIXME OPTIMIZE!!!! (partly done already)
   430 (* FIXME OPTIMIZE!!!! (partly done already)
   433 with 0 <= n.
   437 with 0 <= n.
   434 *)
   438 *)
   435 local
   439 local
   436   exception FalseE of thm
   440   exception FalseE of thm
   437 in
   441 in
       
   442 
   438 fun mkthm ss asms (just: injust) =
   443 fun mkthm ss asms (just: injust) =
   439   let
   444   let
   440     val ctxt = Simplifier.the_context ss;
   445     val ctxt = Simplifier.the_context ss;
   441     val thy = ProofContext.theory_of ctxt;
   446     val thy = ProofContext.theory_of ctxt;
   442     val {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset, ...} = get_data ctxt;
   447     val {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset, ...} = get_data ctxt;
   490         | mk (NotLessD j)         = trace_thm "NL" (mk j RS LA_Logic.not_lessD)
   495         | mk (NotLessD j)         = trace_thm "NL" (mk j RS LA_Logic.not_lessD)
   491         | mk (Added (j1, j2))     = simp (trace_thm "+" (addthms (mk j1) (mk j2)))
   496         | mk (Added (j1, j2))     = simp (trace_thm "+" (addthms (mk j1) (mk j2)))
   492         | mk (Multiplied (n, j))  = (trace_msg ("*" ^ string_of_int n); trace_thm "*" (multn (n, mk j)))
   497         | mk (Multiplied (n, j))  = (trace_msg ("*" ^ string_of_int n); trace_thm "*" (multn (n, mk j)))
   493         | mk (Multiplied2 (n, j)) = simp (trace_msg ("**" ^ string_of_int n); trace_thm "**" (multn2 (n, mk j)))
   498         | mk (Multiplied2 (n, j)) = simp (trace_msg ("**" ^ string_of_int n); trace_thm "**" (multn2 (n, mk j)))
   494 
   499 
   495   in trace_msg "mkthm";
   500   in
   496      let val thm = trace_thm "Final thm:" (mk just)
   501     let
   497      in let val fls = simplify simpset' thm
   502       val _ = trace_msg "mkthm";
   498         in trace_thm "After simplification:" fls;
   503       val thm = trace_thm "Final thm:" (mk just);
   499            if LA_Logic.is_False fls then fls
   504       val fls = simplify simpset' thm;
   500            else
   505       val _ = trace_thm "After simplification:" fls;
   501             (tracing "Assumptions:"; List.app (tracing o Display.string_of_thm) asms;
   506       val _ =
   502              tracing "Proved:"; tracing (Display.string_of_thm fls);
   507         if LA_Logic.is_False fls then ()
   503              warning "Linear arithmetic should have refuted the assumptions.\n\
   508         else
   504                      \Please inform Tobias Nipkow (nipkow@in.tum.de).";
   509           let val count = CRITICAL (fn () => inc warning_count) in
   505              fls)
   510             if count > warning_count_max then ()
   506         end
   511             else
   507      end handle FalseE thm => trace_thm "False reached early:" thm
   512               (tracing (cat_lines
   508   end
   513                 (["Assumptions:"] @ map Display.string_of_thm asms @ [""] @
       
   514                  ["Proved:", Display.string_of_thm fls, ""] @
       
   515                  (if count <> warning_count_max then []
       
   516                   else ["\n(Reached maximal message count -- disabling future warnings)"])));
       
   517                 warning "Linear arithmetic should have refuted the assumptions.\n\
       
   518                   \Please inform Tobias Nipkow (nipkow@in.tum.de).")
       
   519           end;
       
   520     in fls end
       
   521     handle FalseE thm => trace_thm "False reached early:" thm
       
   522   end;
       
   523 
   509 end;
   524 end;
   510 
   525 
   511 fun coeff poly atom =
   526 fun coeff poly atom =
   512   AList.lookup Pattern.aeconv poly atom |> the_default 0;
   527   AList.lookup Pattern.aeconv poly atom |> the_default 0;
   513 
   528