src/HOL/arith_data.ML
changeset 9593 b732997cfc11
parent 9436 62bb04ab4b01
child 9893 93d2fde0306c
equal deleted inserted replaced
9592:abbd48606a0a 9593:b732997cfc11
   260 end;
   260 end;
   261 
   261 
   262 
   262 
   263 (* arith theory data *)
   263 (* arith theory data *)
   264 
   264 
   265 structure ArithDataArgs =
   265 structure ArithTheoryDataArgs =
   266 struct
   266 struct
   267   val name = "HOL/arith";
   267   val name = "HOL/arith";
   268   type T = {splits: thm list, discrete: (string * bool) list};
   268   type T = {splits: thm list, discrete: (string * bool) list};
   269 
   269 
   270   val empty = {splits = [], discrete = []};
   270   val empty = {splits = [], discrete = []};
   274    {splits = Drule.merge_rules (splits1, splits2),
   274    {splits = Drule.merge_rules (splits1, splits2),
   275     discrete = merge_alists discrete1 discrete2};
   275     discrete = merge_alists discrete1 discrete2};
   276   fun print _ _ = ();
   276   fun print _ _ = ();
   277 end;
   277 end;
   278 
   278 
   279 structure ArithData = TheoryDataFun(ArithDataArgs);
   279 structure ArithTheoryData = TheoryDataFun(ArithTheoryDataArgs);
   280 
   280 
   281 fun arith_split_add (thy, thm) = (ArithData.map (fn {splits, discrete} =>
   281 fun arith_split_add (thy, thm) = (ArithTheoryData.map (fn {splits, discrete} =>
   282   {splits = thm :: splits, discrete = discrete}) thy, thm);
   282   {splits = thm :: splits, discrete = discrete}) thy, thm);
   283 
   283 
   284 fun arith_discrete d = ArithData.map (fn {splits, discrete} =>
   284 fun arith_discrete d = ArithTheoryData.map (fn {splits, discrete} =>
   285   {splits = splits, discrete = d :: discrete});
   285   {splits = splits, discrete = d :: discrete});
   286 
   286 
   287 
   287 
   288 structure LA_Data_Ref: LIN_ARITH_DATA =
   288 structure LA_Data_Ref: LIN_ARITH_DATA =
   289 struct
   289 struct
   340 fun decomp2 discrete (_$(Const(rel,T)$lhs$rhs)) = decomp1 discrete (T,(rel,lhs,rhs))
   340 fun decomp2 discrete (_$(Const(rel,T)$lhs$rhs)) = decomp1 discrete (T,(rel,lhs,rhs))
   341   | decomp2 discrete (_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
   341   | decomp2 discrete (_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
   342       negate(decomp1 discrete (T,(rel,lhs,rhs)))
   342       negate(decomp1 discrete (T,(rel,lhs,rhs)))
   343   | decomp2 discrete _ = None
   343   | decomp2 discrete _ = None
   344 
   344 
   345 val decomp = decomp2 o #discrete o ArithData.get_sg;
   345 val decomp = decomp2 o #discrete o ArithTheoryData.get_sg;
   346 
   346 
   347 end;
   347 end;
   348 
   348 
   349 
   349 
   350 structure Fast_Arith =
   350 structure Fast_Arith =
   375  Fast_Arith.setup @
   375  Fast_Arith.setup @
   376  [Fast_Arith.map_data (fn {add_mono_thms, lessD, simpset = _} =>
   376  [Fast_Arith.map_data (fn {add_mono_thms, lessD, simpset = _} =>
   377    {add_mono_thms = add_mono_thms @ add_mono_thms_nat,
   377    {add_mono_thms = add_mono_thms @ add_mono_thms_nat,
   378     lessD = lessD @ [Suc_leI],
   378     lessD = lessD @ [Suc_leI],
   379     simpset = HOL_basic_ss addsimps add_rules addsimprocs nat_cancel_sums_add}),
   379     simpset = HOL_basic_ss addsimps add_rules addsimprocs nat_cancel_sums_add}),
   380   ArithData.init, arith_discrete ("nat", true)];
   380   ArithTheoryData.init, arith_discrete ("nat", true)];
   381 
   381 
   382 end;
   382 end;
   383 
   383 
   384 
   384 
   385 local
   385 local
   405    elimination of min/max can be optimized:
   405    elimination of min/max can be optimized:
   406    (max m n + k <= r) = (m+k <= r & n+k <= r)
   406    (max m n + k <= r) = (m+k <= r & n+k <= r)
   407    (l <= min m n + k) = (l <= m+k & l <= n+k)
   407    (l <= min m n + k) = (l <= m+k & l <= n+k)
   408 *)
   408 *)
   409 fun arith_tac i st =
   409 fun arith_tac i st =
   410   refute_tac (K true) (REPEAT o split_tac (#splits (ArithData.get_sg (Thm.sign_of_thm st))))
   410   refute_tac (K true) (REPEAT o split_tac (#splits (ArithTheoryData.get_sg (Thm.sign_of_thm st))))
   411              ((REPEAT_DETERM o etac linorder_neqE) THEN' fast_arith_tac) i st;
   411              ((REPEAT_DETERM o etac linorder_neqE) THEN' fast_arith_tac) i st;
   412 
   412 
   413 fun arith_method prems =
   413 fun arith_method prems =
   414   Method.METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ facts) THEN' arith_tac));
   414   Method.METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ facts) THEN' arith_tac));
   415 
   415