--- a/src/HOL/Integ/int_arith1.ML Tue Aug 06 11:20:47 2002 +0200
+++ b/src/HOL/Integ/int_arith1.ML Tue Aug 06 11:22:05 2002 +0200
@@ -34,15 +34,15 @@
(** For cancel_numerals **)
val rel_iff_rel_0_rls = map (inst "y" "?u+?v")
- [zless_iff_zdiff_zless_0, eq_iff_zdiff_eq_0,
- zle_iff_zdiff_zle_0] @
- map (inst "y" "n")
- [zless_iff_zdiff_zless_0, eq_iff_zdiff_eq_0,
- zle_iff_zdiff_zle_0];
+ [zless_iff_zdiff_zless_0, eq_iff_zdiff_eq_0,
+ zle_iff_zdiff_zle_0] @
+ map (inst "y" "n")
+ [zless_iff_zdiff_zless_0, eq_iff_zdiff_eq_0,
+ zle_iff_zdiff_zle_0];
Goal "!!i::int. (i*u + m = j*u + n) = ((i-j)*u + m = n)";
by (asm_simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]@
- zadd_ac@rel_iff_rel_0_rls) 1);
+ zadd_ac@rel_iff_rel_0_rls) 1);
qed "eq_add_iff1";
Goal "!!i::int. (i*u + m = j*u + n) = (m = (j-i)*u + n)";
@@ -79,7 +79,7 @@
val numeral_syms = [int_numeral_0_eq_0 RS sym, int_numeral_1_eq_1 RS sym];
val numeral_sym_ss = HOL_ss addsimps numeral_syms;
-fun rename_numerals th =
+fun rename_numerals th =
simplify numeral_sym_ss (Thm.transfer (the_context ()) th);
(*Utilities*)
@@ -89,14 +89,14 @@
(*Decodes a binary INTEGER*)
fun dest_numeral (Const("0", _)) = 0
| dest_numeral (Const("1", _)) = 1
- | dest_numeral (Const("Numeral.number_of", _) $ w) =
+ | dest_numeral (Const("Numeral.number_of", _) $ w) =
(HOLogic.dest_binum w
handle TERM _ => raise TERM("Int_Numeral_Simprocs.dest_numeral:1", [w]))
| dest_numeral t = raise TERM("Int_Numeral_Simprocs.dest_numeral:2", [t]);
fun find_first_numeral past (t::terms) =
- ((dest_numeral t, rev past @ terms)
- handle TERM _ => find_first_numeral (t::past) terms)
+ ((dest_numeral t, rev past @ terms)
+ handle TERM _ => find_first_numeral (t::past) terms)
| find_first_numeral past [] = raise TERM("find_first_numeral", []);
val zero = mk_numeral 0;
@@ -121,7 +121,7 @@
| dest_summing (pos, Const ("op -", _) $ t $ u, ts) =
dest_summing (pos, t, dest_summing (not pos, u, ts))
| dest_summing (pos, t, ts) =
- if pos then t::ts else uminus_const$t :: ts;
+ if pos then t::ts else uminus_const$t :: ts;
fun dest_sum t = dest_summing (true, t, []);
@@ -139,29 +139,29 @@
val dest_times = HOLogic.dest_bin "op *" HOLogic.intT;
fun dest_prod t =
- let val (t,u) = dest_times t
+ let val (t,u) = dest_times t
in dest_prod t @ dest_prod u end
handle TERM _ => [t];
-(*DON'T do the obvious simplifications; that would create special cases*)
+(*DON'T do the obvious simplifications; that would create special cases*)
fun mk_coeff (k, ts) = mk_times (mk_numeral k, ts);
(*Express t as a product of (possibly) a numeral with other sorted terms*)
fun dest_coeff sign (Const ("uminus", _) $ t) = dest_coeff (~sign) t
| dest_coeff sign t =
let val ts = sort Term.term_ord (dest_prod t)
- val (n, ts') = find_first_numeral [] ts
+ val (n, ts') = find_first_numeral [] ts
handle TERM _ => (1, ts)
in (sign*n, mk_prod ts') end;
(*Find first coefficient-term THAT MATCHES u*)
-fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
+fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
| find_first_coeff past u (t::terms) =
- let val (n,u') = dest_coeff 1 t
- in if u aconv u' then (n, rev past @ terms)
- else find_first_coeff (t::past) u terms
- end
- handle TERM _ => find_first_coeff (t::past) u terms;
+ let val (n,u') = dest_coeff 1 t
+ in if u aconv u' then (n, rev past @ terms)
+ else find_first_coeff (t::past) u terms
+ end
+ handle TERM _ => find_first_coeff (t::past) u terms;
(*Simplify Numeral0+n, n+Numeral0, Numeral1*n, n*Numeral1*)
@@ -172,24 +172,24 @@
(*To perform binary arithmetic. The "left" rewriting handles patterns
created by the simprocs, such as 3 * (5 * x). *)
val bin_simps = [int_numeral_0_eq_0 RS sym, int_numeral_1_eq_1 RS sym,
- add_number_of_left, mult_number_of_left] @
+ add_number_of_left, mult_number_of_left] @
bin_arith_simps @ bin_rel_simps;
(*To evaluate binary negations of coefficients*)
val zminus_simps = NCons_simps @
- [zminus_1_eq_m1, number_of_minus RS sym,
- bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min,
- bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min];
+ [zminus_1_eq_m1, number_of_minus RS sym,
+ bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min,
+ bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min];
(*To let us treat subtraction as addition*)
val diff_simps = [zdiff_def, zminus_zadd_distrib, zminus_zminus];
(*push the unary minus down: - x * y = x * - y *)
-val int_minus_mult_eq_1_to_2 =
+val int_minus_mult_eq_1_to_2 =
[zmult_zminus, zmult_zminus_right RS sym] MRS trans |> standard;
(*to extract again any uncancelled minuses*)
-val int_minus_from_mult_simps =
+val int_minus_from_mult_simps =
[zminus_zminus, zmult_zminus, zmult_zminus_right];
(*combine unary minus with numeric literals, however nested within a product*)
@@ -206,19 +206,19 @@
structure CancelNumeralsCommon =
struct
- val mk_sum = mk_sum
- val dest_sum = dest_sum
- val mk_coeff = mk_coeff
- val dest_coeff = dest_coeff 1
- val find_first_coeff = find_first_coeff []
+ val mk_sum = mk_sum
+ val dest_sum = dest_sum
+ val mk_coeff = mk_coeff
+ val dest_coeff = dest_coeff 1
+ val find_first_coeff = find_first_coeff []
val trans_tac = trans_tac
- val norm_tac =
+ val norm_tac =
ALLGOALS (simp_tac (HOL_ss addsimps numeral_syms@add_0s@mult_1s@
diff_simps@zminus_simps@zadd_ac))
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@int_mult_minus_simps))
THEN ALLGOALS (simp_tac (HOL_ss addsimps int_minus_from_mult_simps@
zadd_ac@zmult_ac))
- val numeral_simp_tac = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps))
+ val numeral_simp_tac = ALLGOALS (simp_tac (HOL_ss addsimps add_0s@bin_simps))
val simplify_meta_eq = simplify_meta_eq (add_0s@mult_1s)
end;
@@ -250,55 +250,51 @@
val bal_add2 = le_add_iff2 RS trans
);
-val cancel_numerals =
+val cancel_numerals =
map Bin_Simprocs.prep_simproc
[("inteq_cancel_numerals",
- Bin_Simprocs.prep_pats
- ["(l::int) + m = n", "(l::int) = m + n",
- "(l::int) - m = n", "(l::int) = m - n",
- "(l::int) * m = n", "(l::int) = m * n"],
+ ["(l::int) + m = n", "(l::int) = m + n",
+ "(l::int) - m = n", "(l::int) = m - n",
+ "(l::int) * m = n", "(l::int) = m * n"],
EqCancelNumerals.proc),
- ("intless_cancel_numerals",
- Bin_Simprocs.prep_pats
- ["(l::int) + m < n", "(l::int) < m + n",
- "(l::int) - m < n", "(l::int) < m - n",
- "(l::int) * m < n", "(l::int) < m * n"],
+ ("intless_cancel_numerals",
+ ["(l::int) + m < n", "(l::int) < m + n",
+ "(l::int) - m < n", "(l::int) < m - n",
+ "(l::int) * m < n", "(l::int) < m * n"],
LessCancelNumerals.proc),
- ("intle_cancel_numerals",
- Bin_Simprocs.prep_pats
- ["(l::int) + m <= n", "(l::int) <= m + n",
- "(l::int) - m <= n", "(l::int) <= m - n",
- "(l::int) * m <= n", "(l::int) <= m * n"],
+ ("intle_cancel_numerals",
+ ["(l::int) + m <= n", "(l::int) <= m + n",
+ "(l::int) - m <= n", "(l::int) <= m - n",
+ "(l::int) * m <= n", "(l::int) <= m * n"],
LeCancelNumerals.proc)];
structure CombineNumeralsData =
struct
- val add = op + : int*int -> int
- val mk_sum = long_mk_sum (*to work for e.g. 2*x + 3*x *)
- val dest_sum = dest_sum
- val mk_coeff = mk_coeff
- val dest_coeff = dest_coeff 1
- val left_distrib = left_zadd_zmult_distrib RS trans
+ val add = op + : int*int -> int
+ val mk_sum = long_mk_sum (*to work for e.g. 2*x + 3*x *)
+ val dest_sum = dest_sum
+ val mk_coeff = mk_coeff
+ val dest_coeff = dest_coeff 1
+ val left_distrib = left_zadd_zmult_distrib RS trans
val prove_conv = Bin_Simprocs.prove_conv_nohyps "int_combine_numerals"
val trans_tac = trans_tac
- val norm_tac =
+ val norm_tac =
ALLGOALS (simp_tac (HOL_ss addsimps numeral_syms@add_0s@mult_1s@
diff_simps@zminus_simps@zadd_ac))
THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@int_mult_minus_simps))
THEN ALLGOALS (simp_tac (HOL_ss addsimps int_minus_from_mult_simps@
zadd_ac@zmult_ac))
- val numeral_simp_tac = ALLGOALS
+ val numeral_simp_tac = ALLGOALS
(simp_tac (HOL_ss addsimps add_0s@bin_simps))
val simplify_meta_eq = simplify_meta_eq (add_0s@mult_1s)
end;
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
-
-val combine_numerals = Bin_Simprocs.prep_simproc
- ("int_combine_numerals",
- Bin_Simprocs.prep_pats ["(i::int) + j", "(i::int) - j"],
- CombineNumerals.proc);
+
+val combine_numerals =
+ Bin_Simprocs.prep_simproc
+ ("int_combine_numerals", ["(i::int) + j", "(i::int) - j"], CombineNumerals.proc);
end;
@@ -312,7 +308,7 @@
print_depth 22;
set timing;
set trace_simp;
-fun test s = (Goal s, by (Simp_tac 1));
+fun test s = (Goal s, by (Simp_tac 1));
test "l + 2 + 2 + 2 + (l + 2) + (oo + 2) = (uu::int)";
@@ -355,10 +351,10 @@
structure Int_Times_Assoc_Data : ASSOC_FOLD_DATA =
struct
- val ss = HOL_ss
- val eq_reflection = eq_reflection
+ val ss = HOL_ss
+ val eq_reflection = eq_reflection
val sg_ref = Sign.self_ref (Theory.sign_of (the_context ()))
- val T = HOLogic.intT
+ val T = HOLogic.intT
val plus = Const ("op *", [HOLogic.intT,HOLogic.intT] ---> HOLogic.intT);
val add_ac = zmult_ac
end;
@@ -372,10 +368,10 @@
structure Nat_Times_Assoc_Data : ASSOC_FOLD_DATA =
struct
- val ss = HOL_ss
- val eq_reflection = eq_reflection
+ val ss = HOL_ss
+ val eq_reflection = eq_reflection
val sg_ref = Sign.self_ref (Theory.sign_of (the_context ()))
- val T = HOLogic.natT
+ val T = HOLogic.natT
val plus = Const ("op *", [HOLogic.natT,HOLogic.natT] ---> HOLogic.natT);
val add_ac = mult_ac
end;
@@ -399,19 +395,19 @@
local
(* reduce contradictory <= to False *)
-val add_rules =
- simp_thms @ bin_arith_simps @ bin_rel_simps @
+val add_rules =
+ simp_thms @ bin_arith_simps @ bin_rel_simps @
[int_numeral_0_eq_0, int_numeral_1_eq_1,
zminus_0, zadd_0, zadd_0_right, zdiff_def,
- zadd_zminus_inverse, zadd_zminus_inverse2,
- zmult_0, zmult_0_right,
+ zadd_zminus_inverse, zadd_zminus_inverse2,
+ zmult_0, zmult_0_right,
zmult_1, zmult_1_right,
zmult_zminus, zmult_zminus_right,
zminus_zadd_distrib, zminus_zminus, zmult_assoc,
int_0, int_1, zadd_int RS sym, int_Suc];
val simprocs = [Int_Times_Assoc.conv, Int_Numeral_Simprocs.combine_numerals]@
- Int_Numeral_Simprocs.cancel_numerals @
+ Int_Numeral_Simprocs.cancel_numerals @
Bin_Simprocs.eval_numerals;
val add_mono_thms_int =
@@ -440,16 +436,12 @@
end;
-let
-val int_arith_simproc_pats =
- map (fn s => Thm.read_cterm (Theory.sign_of (the_context())) (s, HOLogic.boolT))
- ["(m::int) < n","(m::int) <= n", "(m::int) = n"];
+val fast_int_arith_simproc =
+ Simplifier.simproc (Theory.sign_of (the_context()))
+ "fast_int_arith" ["(m::int) < n","(m::int) <= n", "(m::int) = n"] Fast_Arith.lin_arith_prover;
-val fast_int_arith_simproc = mk_simproc
- "fast_int_arith" int_arith_simproc_pats Fast_Arith.lin_arith_prover;
-in
Addsimprocs [fast_int_arith_simproc]
-end;
+
(* Some test data
Goal "!!a::int. [| a <= b; c <= d; x+y<z |] ==> a+c <= b+d";