src/Provers/Arith/fast_lin_arith.ML
changeset 15184 d2c19aea17bc
parent 15027 d23887300b96
child 15531 08c8dad8e399
equal deleted inserted replaced
15183:66da80cad4a2 15184:d2c19aea17bc
    69 *)
    69 *)
    70 
    70 
    71 signature FAST_LIN_ARITH =
    71 signature FAST_LIN_ARITH =
    72 sig
    72 sig
    73   val setup: (theory -> theory) list
    73   val setup: (theory -> theory) list
    74   val map_data: ({add_mono_thms: thm list, mult_mono_thms: (thm*cterm)list, inj_thms: thm list,
    74   val map_data: ({add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    75                  lessD: thm list, simpset: Simplifier.simpset}
    75                  lessD: thm list, simpset: Simplifier.simpset}
    76                  -> {add_mono_thms: thm list, mult_mono_thms: (thm*cterm)list, inj_thms: thm list,
    76                  -> {add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    77                      lessD: thm list, simpset: Simplifier.simpset})
    77                      lessD: thm list, simpset: Simplifier.simpset})
    78                 -> theory -> theory
    78                 -> theory -> theory
    79   val trace           : bool ref
    79   val trace           : bool ref
    80   val fast_arith_neq_limit: int ref
    80   val fast_arith_neq_limit: int ref
    81   val lin_arith_prover: Sign.sg -> simpset -> term -> thm option
    81   val lin_arith_prover: Sign.sg -> simpset -> term -> thm option
    93 (* data kind 'Provers/fast_lin_arith' *)
    93 (* data kind 'Provers/fast_lin_arith' *)
    94 
    94 
    95 structure DataArgs =
    95 structure DataArgs =
    96 struct
    96 struct
    97   val name = "Provers/fast_lin_arith";
    97   val name = "Provers/fast_lin_arith";
    98   type T = {add_mono_thms: thm list, mult_mono_thms: (thm*cterm)list, inj_thms: thm list,
    98   type T = {add_mono_thms: thm list, mult_mono_thms: thm list, inj_thms: thm list,
    99             lessD: thm list, simpset: Simplifier.simpset};
    99             lessD: thm list, simpset: Simplifier.simpset};
   100 
   100 
   101   val empty = {add_mono_thms = [], mult_mono_thms = [], inj_thms = [],
   101   val empty = {add_mono_thms = [], mult_mono_thms = [], inj_thms = [],
   102                lessD = [], simpset = Simplifier.empty_ss};
   102                lessD = [], simpset = Simplifier.empty_ss};
   103   val copy = I;
   103   val copy = I;
   106   fun merge ({add_mono_thms= add_mono_thms1, mult_mono_thms= mult_mono_thms1, inj_thms= inj_thms1,
   106   fun merge ({add_mono_thms= add_mono_thms1, mult_mono_thms= mult_mono_thms1, inj_thms= inj_thms1,
   107               lessD = lessD1, simpset = simpset1},
   107               lessD = lessD1, simpset = simpset1},
   108              {add_mono_thms= add_mono_thms2, mult_mono_thms= mult_mono_thms2, inj_thms= inj_thms2,
   108              {add_mono_thms= add_mono_thms2, mult_mono_thms= mult_mono_thms2, inj_thms= inj_thms2,
   109               lessD = lessD2, simpset = simpset2}) =
   109               lessD = lessD2, simpset = simpset2}) =
   110     {add_mono_thms = Drule.merge_rules (add_mono_thms1, add_mono_thms2),
   110     {add_mono_thms = Drule.merge_rules (add_mono_thms1, add_mono_thms2),
   111      mult_mono_thms = gen_merge_lists' (Drule.eq_thm_prop o pairself fst)
   111      mult_mono_thms = Drule.merge_rules (mult_mono_thms1, mult_mono_thms2),
   112        mult_mono_thms1 mult_mono_thms2,
       
   113      inj_thms = Drule.merge_rules (inj_thms1, inj_thms2),
   112      inj_thms = Drule.merge_rules (inj_thms1, inj_thms2),
   114      lessD = Drule.merge_rules (lessD1, lessD2),
   113      lessD = Drule.merge_rules (lessD1, lessD2),
   115      simpset = Simplifier.merge_ss (simpset1, simpset2)};
   114      simpset = Simplifier.merge_ss (simpset1, simpset2)};
   116 
   115 
   117   fun print _ _ = ();
   116   fun print _ _ = ();
   448         | Some thm => thm;
   447         | Some thm => thm;
   449 
   448 
   450       fun multn(n,thm) =
   449       fun multn(n,thm) =
   451         let fun mul(i,th) = if i=1 then th else mul(i-1, addthms thm th)
   450         let fun mul(i,th) = if i=1 then th else mul(i-1, addthms thm th)
   452         in if n < 0 then mul(~n,thm) RS LA_Logic.sym else mul(n,thm) end;
   451         in if n < 0 then mul(~n,thm) RS LA_Logic.sym else mul(n,thm) end;
   453 
   452 (*
   454       fun multn2(n,thm) =
   453       fun multn2(n,thm) =
   455         let val Some(mth,cv) =
   454         let val Some(mth,cv) =
   456               get_first (fn (th,cv) => Some(thm RS th,cv) handle THM _ => None) mult_mono_thms
   455               get_first (fn (th,cv) => Some(thm RS th,cv) handle THM _ => None) mult_mono_thms
       
   456             val ct = cterm_of sg (LA_Data.number_of(n,#T(rep_cterm cv)))
       
   457         in instantiate ([],[(cv,ct)]) mth end
       
   458 *)
       
   459       fun multn2(n,thm) =
       
   460         let val Some(mth) =
       
   461               get_first (fn th => Some(thm RS th) handle THM _ => None) mult_mono_thms
       
   462             fun cvar(th,_ $ (_ $ _ $ var)) = cterm_of (#sign(rep_thm th)) var;
       
   463             val cv = cvar(mth, hd(prems_of mth));
   457             val ct = cterm_of sg (LA_Data.number_of(n,#T(rep_cterm cv)))
   464             val ct = cterm_of sg (LA_Data.number_of(n,#T(rep_cterm cv)))
   458         in instantiate ([],[(cv,ct)]) mth end
   465         in instantiate ([],[(cv,ct)]) mth end
   459 
   466 
   460       fun simp thm =
   467       fun simp thm =
   461         let val thm' = trace_thm "Simplified:" (full_simplify simpset thm)
   468         let val thm' = trace_thm "Simplified:" (full_simplify simpset thm)