src/HOL/arith_data.ML
author webertj
Mon Mar 07 19:30:53 2005 +0100 (2005-03-07)
changeset 15584 3478bb4f93ff
parent 15570 8d8c70b41bab
child 15921 b6e345548913
permissions -rw-r--r--
refute_params: default value itself=1 added (for type classes)
     1 (*  Title:      HOL/arith_data.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, Stefan Berghofer and Tobias Nipkow
     4 
     5 Various arithmetic proof procedures.
     6 *)
     7 
     8 (*---------------------------------------------------------------------------*)
     9 (* 1. Cancellation of common terms                                           *)
    10 (*---------------------------------------------------------------------------*)
    11 
    12 structure NatArithUtils =
    13 struct
    14 
    15 (** abstract syntax of structure nat: 0, Suc, + **)
    16 
    17 (* mk_sum, mk_norm_sum *)
    18 
    19 val one = HOLogic.mk_nat 1;
    20 val mk_plus = HOLogic.mk_binop "op +";
    21 
    22 fun mk_sum [] = HOLogic.zero
    23   | mk_sum [t] = t
    24   | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
    25 
    26 (*normal form of sums: Suc (... (Suc (a + (b + ...))))*)
    27 fun mk_norm_sum ts =
    28   let val (ones, sums) = List.partition (equal one) ts in
    29     funpow (length ones) HOLogic.mk_Suc (mk_sum sums)
    30   end;
    31 
    32 
    33 (* dest_sum *)
    34 
    35 val dest_plus = HOLogic.dest_bin "op +" HOLogic.natT;
    36 
    37 fun dest_sum tm =
    38   if HOLogic.is_zero tm then []
    39   else
    40     (case try HOLogic.dest_Suc tm of
    41       SOME t => one :: dest_sum t
    42     | NONE =>
    43         (case try dest_plus tm of
    44           SOME (t, u) => dest_sum t @ dest_sum u
    45         | NONE => [tm]));
    46 
    47 
    48 (** generic proof tools **)
    49 
    50 (* prove conversions *)
    51 
    52 val mk_eqv = HOLogic.mk_Trueprop o HOLogic.mk_eq;
    53 
    54 fun prove_conv expand_tac norm_tac sg tu =
    55   mk_meta_eq (prove_goalw_cterm_nocheck [] (cterm_of sg (mk_eqv tu))
    56     (K [expand_tac, norm_tac]))
    57   handle ERROR => error ("The error(s) above occurred while trying to prove " ^
    58     (string_of_cterm (cterm_of sg (mk_eqv tu))));
    59 
    60 val subst_equals = prove_goal HOL.thy "[| t = s; u = t |] ==> u = s"
    61   (fn prems => [cut_facts_tac prems 1, SIMPSET' asm_simp_tac 1]);
    62 
    63 
    64 (* rewriting *)
    65 
    66 fun simp_all rules = ALLGOALS (simp_tac (HOL_ss addsimps rules));
    67 
    68 val add_rules = [add_Suc, add_Suc_right, add_0, add_0_right];
    69 val mult_rules = [mult_Suc, mult_Suc_right, mult_0, mult_0_right];
    70 
    71 fun prep_simproc (name, pats, proc) =
    72   Simplifier.simproc (Theory.sign_of (the_context ())) name pats proc;
    73 
    74 end;
    75 
    76 signature ARITH_DATA =
    77 sig
    78   val nat_cancel_sums_add: simproc list
    79   val nat_cancel_sums: simproc list
    80 end;
    81 
    82 structure ArithData: ARITH_DATA =
    83 struct
    84 
    85 open NatArithUtils;
    86 
    87 
    88 (** cancel common summands **)
    89 
    90 structure Sum =
    91 struct
    92   val mk_sum = mk_norm_sum;
    93   val dest_sum = dest_sum;
    94   val prove_conv = prove_conv;
    95   val norm_tac = simp_all add_rules THEN simp_all add_ac;
    96 end;
    97 
    98 fun gen_uncancel_tac rule ct =
    99   rtac (instantiate' [] [NONE, SOME ct] (rule RS subst_equals)) 1;
   100 
   101 
   102 (* nat eq *)
   103 
   104 structure EqCancelSums = CancelSumsFun
   105 (struct
   106   open Sum;
   107   val mk_bal = HOLogic.mk_eq;
   108   val dest_bal = HOLogic.dest_bin "op =" HOLogic.natT;
   109   val uncancel_tac = gen_uncancel_tac nat_add_left_cancel;
   110 end);
   111 
   112 
   113 (* nat less *)
   114 
   115 structure LessCancelSums = CancelSumsFun
   116 (struct
   117   open Sum;
   118   val mk_bal = HOLogic.mk_binrel "op <";
   119   val dest_bal = HOLogic.dest_bin "op <" HOLogic.natT;
   120   val uncancel_tac = gen_uncancel_tac nat_add_left_cancel_less;
   121 end);
   122 
   123 
   124 (* nat le *)
   125 
   126 structure LeCancelSums = CancelSumsFun
   127 (struct
   128   open Sum;
   129   val mk_bal = HOLogic.mk_binrel "op <=";
   130   val dest_bal = HOLogic.dest_bin "op <=" HOLogic.natT;
   131   val uncancel_tac = gen_uncancel_tac nat_add_left_cancel_le;
   132 end);
   133 
   134 
   135 (* nat diff *)
   136 
   137 structure DiffCancelSums = CancelSumsFun
   138 (struct
   139   open Sum;
   140   val mk_bal = HOLogic.mk_binop "op -";
   141   val dest_bal = HOLogic.dest_bin "op -" HOLogic.natT;
   142   val uncancel_tac = gen_uncancel_tac diff_cancel;
   143 end);
   144 
   145 
   146 
   147 (** prepare nat_cancel simprocs **)
   148 
   149 val nat_cancel_sums_add = map prep_simproc
   150   [("nateq_cancel_sums",
   151      ["(l::nat) + m = n", "(l::nat) = m + n", "Suc m = n", "m = Suc n"], EqCancelSums.proc),
   152    ("natless_cancel_sums",
   153      ["(l::nat) + m < n", "(l::nat) < m + n", "Suc m < n", "m < Suc n"], LessCancelSums.proc),
   154    ("natle_cancel_sums",
   155      ["(l::nat) + m <= n", "(l::nat) <= m + n", "Suc m <= n", "m <= Suc n"], LeCancelSums.proc)];
   156 
   157 val nat_cancel_sums = nat_cancel_sums_add @
   158   [prep_simproc ("natdiff_cancel_sums",
   159     ["((l::nat) + m) - n", "(l::nat) - (m + n)", "Suc m - n", "m - Suc n"], DiffCancelSums.proc)];
   160 
   161 end;
   162 
   163 open ArithData;
   164 
   165 
   166 (*---------------------------------------------------------------------------*)
   167 (* 2. Linear arithmetic                                                      *)
   168 (*---------------------------------------------------------------------------*)
   169 
   170 (* Parameters data for general linear arithmetic functor *)
   171 
   172 structure LA_Logic: LIN_ARITH_LOGIC =
   173 struct
   174 val ccontr = ccontr;
   175 val conjI = conjI;
   176 val neqE = linorder_neqE;
   177 val notI = notI;
   178 val sym = sym;
   179 val not_lessD = linorder_not_less RS iffD1;
   180 val not_leD = linorder_not_le RS iffD1;
   181 
   182 
   183 fun mk_Eq thm = (thm RS Eq_FalseI) handle THM _ => (thm RS Eq_TrueI);
   184 
   185 val mk_Trueprop = HOLogic.mk_Trueprop;
   186 
   187 fun neg_prop(TP$(Const("Not",_)$t)) = TP$t
   188   | neg_prop(TP$t) = TP $ (Const("Not",HOLogic.boolT-->HOLogic.boolT)$t);
   189 
   190 fun is_False thm =
   191   let val _ $ t = #prop(rep_thm thm)
   192   in t = Const("False",HOLogic.boolT) end;
   193 
   194 fun is_nat(t) = fastype_of1 t = HOLogic.natT;
   195 
   196 fun mk_nat_thm sg t =
   197   let val ct = cterm_of sg t  and cn = cterm_of sg (Var(("n",0),HOLogic.natT))
   198   in instantiate ([],[(cn,ct)]) le0 end;
   199 
   200 end;
   201 
   202 
   203 (* arith theory data *)
   204 
   205 structure ArithTheoryDataArgs =
   206 struct
   207   val name = "HOL/arith";
   208   type T = {splits: thm list, inj_consts: (string * typ)list, discrete: string  list, presburger: (int -> tactic) option};
   209 
   210   val empty = {splits = [], inj_consts = [], discrete = [], presburger = NONE};
   211   val copy = I;
   212   val prep_ext = I;
   213   fun merge ({splits= splits1, inj_consts= inj_consts1, discrete= discrete1, presburger= presburger1},
   214              {splits= splits2, inj_consts= inj_consts2, discrete= discrete2, presburger= presburger2}) =
   215    {splits = Drule.merge_rules (splits1, splits2),
   216     inj_consts = merge_lists inj_consts1 inj_consts2,
   217     discrete = merge_lists discrete1 discrete2,
   218     presburger = (case presburger1 of NONE => presburger2 | p => p)};
   219   fun print _ _ = ();
   220 end;
   221 
   222 structure ArithTheoryData = TheoryDataFun(ArithTheoryDataArgs);
   223 
   224 fun arith_split_add (thy, thm) = (ArithTheoryData.map (fn {splits,inj_consts,discrete,presburger} =>
   225   {splits= thm::splits, inj_consts= inj_consts, discrete= discrete, presburger= presburger}) thy, thm);
   226 
   227 fun arith_discrete d = ArithTheoryData.map (fn {splits,inj_consts,discrete,presburger} =>
   228   {splits = splits, inj_consts = inj_consts, discrete = d :: discrete, presburger= presburger});
   229 
   230 fun arith_inj_const c = ArithTheoryData.map (fn {splits,inj_consts,discrete,presburger} =>
   231   {splits = splits, inj_consts = c :: inj_consts, discrete = discrete, presburger = presburger});
   232 
   233 
   234 structure LA_Data_Ref: LIN_ARITH_DATA =
   235 struct
   236 
   237 (* Decomposition of terms *)
   238 
   239 fun nT (Type("fun",[N,_])) = N = HOLogic.natT
   240   | nT _ = false;
   241 
   242 fun add_atom(t,m,(p,i)) = (case assoc(p,t) of NONE => ((t,m)::p,i)
   243                            | SOME n => (overwrite(p,(t,ratadd(n,m))), i));
   244 
   245 exception Zero;
   246 
   247 fun rat_of_term(numt,dent) =
   248   let val num = HOLogic.dest_binum numt and den = HOLogic.dest_binum dent
   249   in if den = 0 then raise Zero else int_ratdiv(num,den) end;
   250 
   251 (* Warning: in rare cases number_of encloses a non-numeral,
   252    in which case dest_binum raises TERM; hence all the handles below.
   253    Same for Suc-terms that turn out not to be numerals -
   254    although the simplifier should eliminate those anyway...
   255 *)
   256 
   257 fun number_of_Sucs (Const("Suc",_) $ n) = number_of_Sucs n + 1
   258   | number_of_Sucs t = if HOLogic.is_zero t then 0
   259                        else raise TERM("number_of_Sucs",[])
   260 
   261 (* decompose nested multiplications, bracketing them to the right and combining all
   262    their coefficients
   263 *)
   264 
   265 fun demult inj_consts =
   266 let
   267 fun demult((mC as Const("op *",_)) $ s $ t,m) = ((case s of
   268         Const("Numeral.number_of",_)$n
   269         => demult(t,ratmul(m,rat_of_int(HOLogic.dest_binum n)))
   270       | Const("uminus",_)$(Const("Numeral.number_of",_)$n)
   271         => demult(t,ratmul(m,rat_of_int(~(HOLogic.dest_binum n))))
   272       | Const("Suc",_) $ _
   273         => demult(t,ratmul(m,rat_of_int(number_of_Sucs s)))
   274       | Const("op *",_) $ s1 $ s2 => demult(mC $ s1 $ (mC $ s2 $ t),m)
   275       | Const("HOL.divide",_) $ numt $ (Const("Numeral.number_of",_)$dent) =>
   276           let val den = HOLogic.dest_binum dent
   277           in if den = 0 then raise Zero
   278              else demult(mC $ numt $ t,ratmul(m, ratinv(rat_of_int den)))
   279           end
   280       | _ => atomult(mC,s,t,m)
   281       ) handle TERM _ => atomult(mC,s,t,m))
   282   | demult(atom as Const("HOL.divide",_) $ t $ (Const("Numeral.number_of",_)$dent), m) =
   283       (let val den = HOLogic.dest_binum dent
   284        in if den = 0 then raise Zero else demult(t,ratmul(m, ratinv(rat_of_int den))) end
   285        handle TERM _ => (SOME atom,m))
   286   | demult(Const("0",_),m) = (NONE, rat_of_int 0)
   287   | demult(Const("1",_),m) = (NONE, m)
   288   | demult(t as Const("Numeral.number_of",_)$n,m) =
   289       ((NONE,ratmul(m,rat_of_int(HOLogic.dest_binum n)))
   290        handle TERM _ => (SOME t,m))
   291   | demult(Const("uminus",_)$t, m) = demult(t,ratmul(m,rat_of_int(~1)))
   292   | demult(t as Const f $ x, m) =
   293       (if f mem inj_consts then SOME x else SOME t,m)
   294   | demult(atom,m) = (SOME atom,m)
   295 
   296 and atomult(mC,atom,t,m) = (case demult(t,m) of (NONE,m') => (SOME atom,m')
   297                             | (SOME t',m') => (SOME(mC $ atom $ t'),m'))
   298 in demult end;
   299 
   300 fun decomp2 inj_consts (rel,lhs,rhs) =
   301 let
   302 (* Turn term into list of summand * multiplicity plus a constant *)
   303 fun poly(Const("op +",_) $ s $ t, m, pi) = poly(s,m,poly(t,m,pi))
   304   | poly(all as Const("op -",T) $ s $ t, m, pi) =
   305       if nT T then add_atom(all,m,pi)
   306       else poly(s,m,poly(t,ratneg m,pi))
   307   | poly(Const("uminus",_) $ t, m, pi) = poly(t,ratneg m,pi)
   308   | poly(Const("0",_), _, pi) = pi
   309   | poly(Const("1",_), m, (p,i)) = (p,ratadd(i,m))
   310   | poly(Const("Suc",_)$t, m, (p,i)) = poly(t, m, (p,ratadd(i,m)))
   311   | poly(t as Const("op *",_) $ _ $ _, m, pi as (p,i)) =
   312       (case demult inj_consts (t,m) of
   313          (NONE,m') => (p,ratadd(i,m))
   314        | (SOME u,m') => add_atom(u,m',pi))
   315   | poly(t as Const("HOL.divide",_) $ _ $ _, m, pi as (p,i)) =
   316       (case demult inj_consts (t,m) of
   317          (NONE,m') => (p,ratadd(i,m'))
   318        | (SOME u,m') => add_atom(u,m',pi))
   319   | poly(all as (Const("Numeral.number_of",_)$t,m,(p,i))) =
   320       ((p,ratadd(i,ratmul(m,rat_of_int(HOLogic.dest_binum t))))
   321        handle TERM _ => add_atom all)
   322   | poly(all as Const f $ x, m, pi) =
   323       if f mem inj_consts then poly(x,m,pi) else add_atom(all,m,pi)
   324   | poly x  = add_atom x;
   325 
   326 val (p,i) = poly(lhs,rat_of_int 1,([],rat_of_int 0))
   327 and (q,j) = poly(rhs,rat_of_int 1,([],rat_of_int 0))
   328 
   329   in case rel of
   330        "op <"  => SOME(p,i,"<",q,j)
   331      | "op <=" => SOME(p,i,"<=",q,j)
   332      | "op ="  => SOME(p,i,"=",q,j)
   333      | _       => NONE
   334   end handle Zero => NONE;
   335 
   336 fun negate(SOME(x,i,rel,y,j,d)) = SOME(x,i,"~"^rel,y,j,d)
   337   | negate NONE = NONE;
   338 
   339 fun of_lin_arith_sort sg U =
   340   Type.of_sort (Sign.tsig_of sg) (U,["Ring_and_Field.ordered_idom"])
   341 
   342 fun allows_lin_arith sg discrete (U as Type(D,[])) =
   343       if of_lin_arith_sort sg U
   344       then (true, D mem discrete)
   345       else (* special cases *)
   346            if D mem discrete then (true,true) else (false,false)
   347   | allows_lin_arith sg discrete U = (of_lin_arith_sort sg U, false);
   348 
   349 fun decomp1 (sg,discrete,inj_consts) (T,xxx) =
   350   (case T of
   351      Type("fun",[U,_]) =>
   352        (case allows_lin_arith sg discrete U of
   353           (true,d) => (case decomp2 inj_consts xxx of NONE => NONE
   354                        | SOME(p,i,rel,q,j) => SOME(p,i,rel,q,j,d))
   355         | (false,_) => NONE)
   356    | _ => NONE);
   357 
   358 fun decomp2 data (_$(Const(rel,T)$lhs$rhs)) = decomp1 data (T,(rel,lhs,rhs))
   359   | decomp2 data (_$(Const("Not",_)$(Const(rel,T)$lhs$rhs))) =
   360       negate(decomp1 data (T,(rel,lhs,rhs)))
   361   | decomp2 data _ = NONE
   362 
   363 fun decomp sg =
   364   let val {discrete, inj_consts, ...} = ArithTheoryData.get_sg sg
   365   in decomp2 (sg,discrete,inj_consts) end
   366 
   367 fun number_of(n,T) = HOLogic.number_of_const T $ (HOLogic.mk_bin n)
   368 
   369 end;
   370 
   371 
   372 structure Fast_Arith =
   373   Fast_Lin_Arith(structure LA_Logic=LA_Logic and LA_Data=LA_Data_Ref);
   374 
   375 val fast_arith_tac    = Fast_Arith.lin_arith_tac false
   376 and fast_ex_arith_tac = Fast_Arith.lin_arith_tac
   377 and trace_arith    = Fast_Arith.trace
   378 and fast_arith_neq_limit = Fast_Arith.fast_arith_neq_limit;
   379 
   380 local
   381 
   382 val isolateSuc =
   383   let val thy = theory "Nat"
   384   in prove_goal thy "Suc(i+j) = i+j + Suc 0"
   385      (fn _ => [simp_tac (simpset_of thy) 1])
   386   end;
   387 
   388 (* reduce contradictory <= to False.
   389    Most of the work is done by the cancel tactics.
   390 *)
   391 val add_rules =
   392  [add_zero_left,add_zero_right,Zero_not_Suc,Suc_not_Zero,le_0_eq,
   393   One_nat_def,isolateSuc,
   394   order_less_irrefl];
   395 
   396 val add_mono_thms_ordered_semiring = map (fn s => prove_goal (the_context ()) s
   397  (fn prems => [cut_facts_tac prems 1,
   398                blast_tac (claset() addIs [add_mono]) 1]))
   399 ["(i <= j) & (k <= l) ==> i + k <= j + (l::'a::pordered_ab_semigroup_add)",
   400  "(i  = j) & (k <= l) ==> i + k <= j + (l::'a::pordered_ab_semigroup_add)",
   401  "(i <= j) & (k  = l) ==> i + k <= j + (l::'a::pordered_ab_semigroup_add)",
   402  "(i  = j) & (k  = l) ==> i + k  = j + (l::'a::pordered_ab_semigroup_add)"
   403 ];
   404 
   405 val mono_ss = simpset() addsimps
   406                 [add_mono,add_strict_mono,add_less_le_mono,add_le_less_mono];
   407 
   408 val add_mono_thms_ordered_field =
   409   map (fn s => prove_goal (the_context ()) s
   410                  (fn prems => [cut_facts_tac prems 1, asm_simp_tac mono_ss 1]))
   411     ["(i<j) & (k=l)   ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)",
   412      "(i=j) & (k<l)   ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)",
   413      "(i<j) & (k<=l)  ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)",
   414      "(i<=j) & (k<l)  ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)",
   415      "(i<j) & (k<l)   ==> i+k < j+(l::'a::pordered_cancel_ab_semigroup_add)"];
   416 
   417 in
   418 
   419 val init_lin_arith_data =
   420  Fast_Arith.setup @
   421  [Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset = _} =>
   422    {add_mono_thms = add_mono_thms @
   423     add_mono_thms_ordered_semiring @ add_mono_thms_ordered_field,
   424     mult_mono_thms = mult_mono_thms,
   425     inj_thms = inj_thms,
   426     lessD = lessD @ [Suc_leI],
   427     simpset = HOL_basic_ss addsimps add_rules
   428                    addsimprocs [ab_group_add_cancel.sum_conv, 
   429                                 ab_group_add_cancel.rel_conv]
   430                    (*abel_cancel helps it work in abstract algebraic domains*)
   431                    addsimprocs nat_cancel_sums_add}),
   432   ArithTheoryData.init, arith_discrete "nat"];
   433 
   434 end;
   435 
   436 val fast_nat_arith_simproc =
   437   Simplifier.simproc (Theory.sign_of (the_context ())) "fast_nat_arith"
   438     ["(m::nat) < n","(m::nat) <= n", "(m::nat) = n"] Fast_Arith.lin_arith_prover;
   439 
   440 
   441 (* Because of fast_nat_arith_simproc, the arithmetic solver is really only
   442 useful to detect inconsistencies among the premises for subgoals which are
   443 *not* themselves (in)equalities, because the latter activate
   444 fast_nat_arith_simproc anyway. However, it seems cheaper to activate the
   445 solver all the time rather than add the additional check. *)
   446 
   447 
   448 (* arith proof method *)
   449 
   450 (* FIXME: K true should be replaced by a sensible test to speed things up
   451    in case there are lots of irrelevant terms involved;
   452    elimination of min/max can be optimized:
   453    (max m n + k <= r) = (m+k <= r & n+k <= r)
   454    (l <= min m n + k) = (l <= m+k & l <= n+k)
   455 *)
   456 local
   457 
   458 fun raw_arith_tac ex i st =
   459   refute_tac (K true)
   460    (REPEAT o split_tac (#splits (ArithTheoryData.get_sg (Thm.sign_of_thm st))))
   461    ((REPEAT_DETERM o etac linorder_neqE) THEN' fast_ex_arith_tac ex)
   462    i st;
   463 
   464 fun presburger_tac i st =
   465   (case ArithTheoryData.get_sg (sign_of_thm st) of
   466      {presburger = SOME tac, ...} =>
   467        (tracing "Simple arithmetic decision procedure failed.\nNow trying full Presburger arithmetic..."; tac i st)
   468    | _ => no_tac st);
   469 
   470 in
   471 
   472 val simple_arith_tac = FIRST' [fast_arith_tac,
   473   ObjectLogic.atomize_tac THEN' raw_arith_tac true];
   474 
   475 val arith_tac = FIRST' [fast_arith_tac,
   476   ObjectLogic.atomize_tac THEN' raw_arith_tac true,
   477   presburger_tac];
   478 
   479 val silent_arith_tac = FIRST' [fast_arith_tac,
   480   ObjectLogic.atomize_tac THEN' raw_arith_tac false,
   481   presburger_tac];
   482 
   483 fun arith_method prems =
   484   Method.METHOD (fn facts => HEADGOAL (Method.insert_tac (prems @ facts) THEN' arith_tac));
   485 
   486 end;
   487 
   488 (* antisymmetry:
   489    combines x <= y (or ~(y < x)) and y <= x (or ~(x < y)) into x = y
   490 
   491 local
   492 val antisym = mk_meta_eq order_antisym
   493 val not_lessD = linorder_not_less RS iffD1
   494 fun prp t thm = (#prop(rep_thm thm) = t)
   495 in
   496 fun antisym_eq prems thm =
   497   let
   498     val r = #prop(rep_thm thm);
   499   in
   500     case r of
   501       Tr $ ((c as Const("op <=",T)) $ s $ t) =>
   502         let val r' = Tr $ (c $ t $ s)
   503         in
   504           case Library.find_first (prp r') prems of
   505             NONE =>
   506               let val r' = Tr $ (HOLogic.not_const $ (Const("op <",T) $ s $ t))
   507               in case Library.find_first (prp r') prems of
   508                    NONE => []
   509                  | SOME thm' => [(thm' RS not_lessD) RS (thm RS antisym)]
   510               end
   511           | SOME thm' => [thm' RS (thm RS antisym)]
   512         end
   513     | Tr $ (Const("Not",_) $ (Const("op <",T) $ s $ t)) =>
   514         let val r' = Tr $ (Const("op <=",T) $ s $ t)
   515         in
   516           case Library.find_first (prp r') prems of
   517             NONE =>
   518               let val r' = Tr $ (HOLogic.not_const $ (Const("op <",T) $ t $ s))
   519               in case Library.find_first (prp r') prems of
   520                    NONE => []
   521                  | SOME thm' =>
   522                      [(thm' RS not_lessD) RS ((thm RS not_lessD) RS antisym)]
   523               end
   524           | SOME thm' => [thm' RS ((thm RS not_lessD) RS antisym)]
   525         end
   526     | _ => []
   527   end
   528   handle THM _ => []
   529 end;
   530 *)
   531 
   532 (* theory setup *)
   533 
   534 val arith_setup =
   535  [Simplifier.change_simpset_of (op addsimprocs) nat_cancel_sums] @
   536   init_lin_arith_data @
   537   [Simplifier.change_simpset_of (op addSolver)
   538    (mk_solver "lin. arith." Fast_Arith.cut_lin_arith_tac),
   539   Simplifier.change_simpset_of (op addsimprocs) [fast_nat_arith_simproc],
   540   Method.add_methods
   541       [("arith", (arith_method o #2) oo Method.syntax Args.bang_facts,
   542 	"decide linear arithmethic")],
   543   Attrib.add_attributes [("arith_split",
   544     (Attrib.no_args arith_split_add, 
   545      Attrib.no_args Attrib.undef_local_attribute),
   546     "declaration of split rules for arithmetic procedure")]];