src/ZF/Integ/int_arith.ML
author paulson
Thu, 10 Aug 2000 11:27:34 +0200
changeset 9570 e16e168984e1
child 9576 3df14e0a3a51
permissions -rw-r--r--
installation of cancellation simprocs for the integers
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9570
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     1
(*  Title:      ZF/Integ/int_arith.ML
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     2
    ID:         $Id$
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     3
    Author:    Larry Paulson
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     4
    Copyright   2000  University of Cambridge
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     5
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     6
Simprocs for linear arithmetic.
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     7
*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     8
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
     9
(*** Simprocs for numeric literals ***)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    10
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    11
(** Combining of literal coefficients in sums of products **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    12
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    13
Goal "(x $< y) <-> (x$-y $< #0)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    14
by (simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    15
qed "zless_iff_zdiff_zless_0";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    16
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    17
Goal "[| x: int; y: int |] ==> (x = y) <-> (x$-y = #0)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    18
by (asm_simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    19
qed "eq_iff_zdiff_eq_0";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    20
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    21
Goal "(x $<= y) <-> (x$-y $<= #0)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    22
by (asm_simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    23
qed "zle_iff_zdiff_zle_0";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    24
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    25
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    26
(** For combine_numerals **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    27
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    28
Goal "i$*u $+ (j$*u $+ k) = (i$+j)$*u $+ k";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    29
by (simp_tac (simpset() addsimps [zadd_zmult_distrib]@zadd_ac) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    30
qed "left_zadd_zmult_distrib";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    31
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    32
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    33
(** For cancel_numerals **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    34
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    35
val rel_iff_rel_0_rls = map (inst "y" "?u$+?v")
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    36
                          [zless_iff_zdiff_zless_0, eq_iff_zdiff_eq_0, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    37
			   zle_iff_zdiff_zle_0] @
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    38
		        map (inst "y" "n")
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    39
                          [zless_iff_zdiff_zless_0, eq_iff_zdiff_eq_0, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    40
			   zle_iff_zdiff_zle_0];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    41
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    42
Goal "(i$*u $+ m = j$*u $+ n) <-> ((i$-j)$*u $+ m = intify(n))";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    43
by (simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    44
by (simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    45
by (simp_tac (simpset() addsimps zadd_ac) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    46
qed "eq_add_iff1";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    47
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    48
Goal "(i$*u $+ m = j$*u $+ n) <-> (intify(m) = (j$-i)$*u $+ n)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    49
by (simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    50
by (simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    51
by (simp_tac (simpset() addsimps zadd_ac) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    52
qed "eq_add_iff2";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    53
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    54
Goal "(i$*u $+ m $< j$*u $+ n) <-> ((i$-j)$*u $+ m $< n)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    55
by (asm_simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    56
                                     zadd_ac@rel_iff_rel_0_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    57
qed "less_add_iff1";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    58
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    59
Goal "(i$*u $+ m $< j$*u $+ n) <-> (m $< (j$-i)$*u $+ n)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    60
by (asm_simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    61
                                     zadd_ac@rel_iff_rel_0_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    62
qed "less_add_iff2";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    63
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    64
Goal "(i$*u $+ m $<= j$*u $+ n) <-> ((i$-j)$*u $+ m $<= intify(n))";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    65
by (simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    66
by (simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    67
by (simp_tac (simpset() addsimps zadd_ac) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    68
qed "le_add_iff1";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    69
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    70
Goal "(i$*u $+ m $<= j$*u $+ n) <-> (intify(m) $<= (j$-i)$*u $+ n)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    71
by (simp_tac (simpset() addsimps [zdiff_def, zadd_zmult_distrib]) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    72
by (simp_tac (simpset() addsimps zcompare_rls) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    73
by (simp_tac (simpset() addsimps zadd_ac) 1);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    74
qed "le_add_iff2";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    75
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    76
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    77
structure Int_Numeral_Simprocs =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    78
struct
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    79
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    80
(*Utilities*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    81
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    82
val integ_of_const = Const ("Bin.integ_of", iT --> iT);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    83
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    84
fun mk_numeral n = integ_of_const $ NumeralSyntax.mk_bin n;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    85
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    86
(*Decodes a binary INTEGER*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    87
fun dest_numeral (Const("Bin.integ_of", _) $ w) = 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    88
     (NumeralSyntax.dest_bin w
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    89
      handle Match => raise TERM("Int_Numeral_Simprocs.dest_numeral:1", [w]))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    90
  | dest_numeral t =  raise TERM("Int_Numeral_Simprocs.dest_numeral:2", [t]);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    91
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    92
fun find_first_numeral past (t::terms) =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    93
	((dest_numeral t, rev past @ terms)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    94
	 handle TERM _ => find_first_numeral (t::past) terms)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    95
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    96
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    97
val zero = mk_numeral 0;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    98
val mk_plus = FOLogic.mk_binop "Int.zadd";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
    99
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   100
val iT = Ind_Syntax.iT;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   101
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   102
val zminus_const = Const ("Int.zminus", iT --> iT);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   103
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   104
(*Thus mk_sum[t] yields t+#0; longer sums don't have a trailing zero*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   105
fun mk_sum []        = zero
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   106
  | mk_sum [t,u]     = mk_plus (t, u)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   107
  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   108
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   109
(*this version ALWAYS includes a trailing zero*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   110
fun long_mk_sum []        = zero
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   111
  | long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   112
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   113
val dest_plus = FOLogic.dest_bin "Int.zadd" iT;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   114
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   115
(*decompose additions AND subtractions as a sum*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   116
fun dest_summing (pos, Const ("Int.zadd", _) $ t $ u, ts) =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   117
        dest_summing (pos, t, dest_summing (pos, u, ts))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   118
  | dest_summing (pos, Const ("Int.zdiff", _) $ t $ u, ts) =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   119
        dest_summing (pos, t, dest_summing (not pos, u, ts))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   120
  | dest_summing (pos, t, ts) =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   121
	if pos then t::ts else zminus_const$t :: ts;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   122
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   123
fun dest_sum t = dest_summing (true, t, []);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   124
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   125
val mk_diff = FOLogic.mk_binop "Int.zdiff";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   126
val dest_diff = FOLogic.dest_bin "Int.zdiff" iT;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   127
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   128
val one = mk_numeral 1;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   129
val mk_times = FOLogic.mk_binop "Int.zmult";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   130
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   131
fun mk_prod [] = one
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   132
  | mk_prod [t] = t
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   133
  | mk_prod (t :: ts) = if t = one then mk_prod ts
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   134
                        else mk_times (t, mk_prod ts);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   135
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   136
val dest_times = FOLogic.dest_bin "Int.zmult" iT;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   137
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   138
fun dest_prod t =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   139
      let val (t,u) = dest_times t 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   140
      in  dest_prod t @ dest_prod u  end
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   141
      handle TERM _ => [t];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   142
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   143
(*DON'T do the obvious simplifications; that would create special cases*) 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   144
fun mk_coeff (k, t) = mk_times (mk_numeral k, t);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   145
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   146
(*Express t as a product of (possibly) a numeral with other sorted terms*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   147
fun dest_coeff sign (Const ("Int.zminus", _) $ t) = dest_coeff (~sign) t
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   148
  | dest_coeff sign t =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   149
    let val ts = sort Term.term_ord (dest_prod t)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   150
	val (n, ts') = find_first_numeral [] ts
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   151
                          handle TERM _ => (1, ts)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   152
    in (sign*n, mk_prod ts') end;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   153
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   154
(*Find first coefficient-term THAT MATCHES u*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   155
fun find_first_coeff past u [] = raise TERM("find_first_coeff", []) 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   156
  | find_first_coeff past u (t::terms) =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   157
	let val (n,u') = dest_coeff 1 t
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   158
	in  if u aconv u' then (n, rev past @ terms)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   159
			  else find_first_coeff (t::past) u terms
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   160
	end
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   161
	handle TERM _ => find_first_coeff (t::past) u terms;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   162
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   163
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   164
(*Simplify #1*n and n*#1 to n*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   165
val add_0s = [zadd_0_intify, zadd_0_right_intify];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   166
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   167
val mult_1s = [zmult_1_intify, zmult_1_right_intify, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   168
               zmult_minus1, zmult_minus1_right];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   169
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   170
val tc_rules = [integ_of_type, intify_in_int, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   171
                zadd_type, zdiff_type, zmult_type] @ bin.intrs;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   172
val intifys = [intify_ident, zadd_intify1, zadd_intify2,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   173
               zdiff_intify1, zdiff_intify2, zmult_intify1, zmult_intify2,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   174
               zless_intify1, zless_intify2, zle_intify1, zle_intify2];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   175
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   176
(*To perform binary arithmetic*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   177
val bin_simps = [add_integ_of_left] @ bin_arith_simps @ bin_rel_simps;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   178
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   179
(*To evaluate binary negations of coefficients*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   180
val zminus_simps = NCons_simps @
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   181
                   [integ_of_minus RS sym, 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   182
		    bin_minus_1, bin_minus_0, bin_minus_Pls, bin_minus_Min,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   183
		    bin_pred_1, bin_pred_0, bin_pred_Pls, bin_pred_Min];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   184
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   185
(*To let us treat subtraction as addition*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   186
val diff_simps = [zdiff_def, zminus_zadd_distrib, zminus_zminus];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   187
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   188
fun prep_simproc (name, pats, proc) = Simplifier.mk_simproc name pats proc;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   189
fun prep_pat s = Thm.read_cterm (Theory.sign_of (the_context ()))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   190
                      (s, TypeInfer.anyT ["logic"]);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   191
val prep_pats = map prep_pat;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   192
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   193
structure CancelNumeralsCommon =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   194
  struct
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   195
  val mk_sum    	= mk_sum
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   196
  val dest_sum		= dest_sum
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   197
  val mk_coeff		= mk_coeff
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   198
  val dest_coeff	= dest_coeff 1
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   199
  val find_first_coeff	= find_first_coeff []
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   200
  val trans_tac		= ArithData.gen_trans_tac iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   201
  val norm_tac_ss1 = ZF_ss addsimps add_0s@mult_1s@diff_simps@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   202
                                    zminus_simps@zadd_ac
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   203
  val norm_tac_ss2 = ZF_ss addsimps [zmult_zminus_right RS sym]@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   204
                                    bin_simps@zadd_ac@zmult_ac@tc_rules@intifys
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   205
  val norm_tac		= ALLGOALS (asm_simp_tac norm_tac_ss1)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   206
			  THEN ALLGOALS (asm_simp_tac norm_tac_ss2)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   207
  val numeral_simp_tac	= ALLGOALS (simp_tac (ZF_ss addsimps add_0s@bin_simps@tc_rules@intifys))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   208
  val simplify_meta_eq  = ArithData.simplify_meta_eq (add_0s@mult_1s)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   209
  end;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   210
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   211
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   212
structure EqCancelNumerals = CancelNumeralsFun
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   213
 (open CancelNumeralsCommon
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   214
  val prove_conv = ArithData.prove_conv "inteq_cancel_numerals"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   215
  val mk_bal   = FOLogic.mk_eq
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   216
  val dest_bal = FOLogic.dest_bin "op =" iT
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   217
  val bal_add1 = eq_add_iff1 RS iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   218
  val bal_add2 = eq_add_iff2 RS iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   219
);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   220
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   221
structure LessCancelNumerals = CancelNumeralsFun
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   222
 (open CancelNumeralsCommon
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   223
  val prove_conv = ArithData.prove_conv "intless_cancel_numerals"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   224
  val mk_bal   = FOLogic.mk_binrel "Int.zless"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   225
  val dest_bal = FOLogic.dest_bin "Int.zless" iT
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   226
  val bal_add1 = less_add_iff1 RS iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   227
  val bal_add2 = less_add_iff2 RS iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   228
);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   229
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   230
structure LeCancelNumerals = CancelNumeralsFun
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   231
 (open CancelNumeralsCommon
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   232
  val prove_conv = ArithData.prove_conv "intle_cancel_numerals"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   233
  val mk_bal   = FOLogic.mk_binrel "Int.zle"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   234
  val dest_bal = FOLogic.dest_bin "Int.zle" iT
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   235
  val bal_add1 = le_add_iff1 RS iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   236
  val bal_add2 = le_add_iff2 RS iff_trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   237
);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   238
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   239
val cancel_numerals = 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   240
  map prep_simproc
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   241
   [("inteq_cancel_numerals",
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   242
     prep_pats ["l $+ m = n", "l = m $+ n", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   243
		"l $- m = n", "l = m $- n", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   244
		"l $* m = n", "l = m $* n"], 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   245
     EqCancelNumerals.proc),
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   246
    ("intless_cancel_numerals", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   247
     prep_pats ["l $+ m $< n", "l $< m $+ n", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   248
		"l $- m $< n", "l $< m $- n", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   249
		"l $* m $< n", "l $< m $* n"], 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   250
     LessCancelNumerals.proc),
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   251
    ("intle_cancel_numerals", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   252
     prep_pats ["l $+ m $<= n", "l $<= m $+ n", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   253
		"l $- m $<= n", "l $<= m $- n", 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   254
		"l $* m $<= n", "l $<= m $* n"], 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   255
     LeCancelNumerals.proc)];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   256
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   257
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   258
(*version without the hyps argument*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   259
fun prove_conv_nohyps name tacs sg = ArithData.prove_conv name tacs sg [];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   260
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   261
structure CombineNumeralsData =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   262
  struct
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   263
  val add		= op + : int*int -> int 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   264
  val mk_sum    	= long_mk_sum    (*to work for e.g. #2*x $+ #3*x *)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   265
  val dest_sum		= dest_sum
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   266
  val mk_coeff		= mk_coeff
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   267
  val dest_coeff	= dest_coeff 1
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   268
  val left_distrib	= left_zadd_zmult_distrib RS trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   269
  val prove_conv        = prove_conv_nohyps "int_combine_numerals"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   270
  val trans_tac         = ArithData.gen_trans_tac trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   271
  val norm_tac_ss1 = ZF_ss addsimps add_0s@mult_1s@diff_simps@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   272
                                    zminus_simps@zadd_ac
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   273
  val norm_tac_ss2 = ZF_ss addsimps [zmult_zminus_right RS sym]@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   274
                                    bin_simps@zadd_ac@zmult_ac@tc_rules@intifys
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   275
  val norm_tac		= ALLGOALS (asm_simp_tac norm_tac_ss1)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   276
			  THEN ALLGOALS (asm_simp_tac norm_tac_ss2)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   277
  val numeral_simp_tac	= ALLGOALS (simp_tac (ZF_ss addsimps add_0s@bin_simps))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   278
  val simplify_meta_eq  = ArithData.simplify_meta_eq (add_0s@mult_1s)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   279
  end;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   280
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   281
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   282
  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   283
val combine_numerals = 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   284
    prep_simproc ("int_combine_numerals",
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   285
		  prep_pats ["i $+ j", "i $- j"],
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   286
		  CombineNumerals.proc);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   287
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   288
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   289
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   290
(** Constant folding for integer multiplication **)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   291
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   292
(*The trick is to regard products as sums, e.g. #3 $* x $* #4 as
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   293
  the "sum" of #3, x, #4; the literals are then multiplied*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   294
structure CombineNumeralsProdData =
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   295
  struct
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   296
  val add		= op * : int*int -> int
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   297
  val mk_sum    	= mk_prod
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   298
  val dest_sum		= dest_prod
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   299
  fun mk_coeff (k, t) = mk_numeral k
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   300
  val dest_coeff	= dest_coeff 1
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   301
  val left_distrib	= zmult_assoc RS sym RS trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   302
  val prove_conv        = prove_conv_nohyps "int_combine_numerals_prod"
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   303
  val trans_tac         = ArithData.gen_trans_tac trans
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   304
  val norm_tac_ss1 = ZF_ss addsimps mult_1s@diff_simps@zminus_simps
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   305
  val norm_tac_ss2 = ZF_ss addsimps [zmult_zminus_right RS sym]@
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   306
                                    bin_simps@zmult_ac@tc_rules@intifys
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   307
  val norm_tac		= ALLGOALS (asm_simp_tac norm_tac_ss1)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   308
			  THEN ALLGOALS (asm_simp_tac norm_tac_ss2)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   309
  val numeral_simp_tac	= ALLGOALS (simp_tac (ZF_ss addsimps bin_simps))
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   310
  val simplify_meta_eq  = ArithData.simplify_meta_eq (mult_1s)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   311
  end;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   312
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   313
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   314
structure CombineNumeralsProd = CombineNumeralsFun(CombineNumeralsProdData);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   315
  
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   316
val combine_numerals_prod = 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   317
    prep_simproc ("int_combine_numerals_prod",
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   318
		  prep_pats ["i $* j", "i $* j"],
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   319
		  CombineNumeralsProd.proc);
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   320
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   321
end;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   322
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   323
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   324
Addsimprocs Int_Numeral_Simprocs.cancel_numerals;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   325
Addsimprocs [Int_Numeral_Simprocs.combine_numerals,
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   326
	     Int_Numeral_Simprocs.combine_numerals_prod];
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   327
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   328
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   329
(*examples:*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   330
(*
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   331
print_depth 22;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   332
set timing;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   333
set trace_simp;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   334
fun test s = (Goal s; by (Asm_simp_tac 1)); 
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   335
val sg = #sign (rep_thm (topthm()));
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   336
val t = FOLogic.dest_Trueprop (Logic.strip_assums_concl(getgoal 1));
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   337
val (t,_) = FOLogic.dest_eq t;
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   338
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   339
(*combine_numerals_prod (products of separate literals) *)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   340
test "#5 $* x $* #3 = y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   341
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   342
test "y2 $+ ?x42 = y $+ y2";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   343
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   344
test "oo : int ==> l $+ (l $+ #2) $+ oo = oo";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   345
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   346
test "#9$*x $+ y = x$*#23 $+ z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   347
test "y $+ x = x $+ z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   348
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   349
test "x : int ==> x $+ y $+ z = x $+ z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   350
test "x : int ==> y $+ (z $+ x) = z $+ x";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   351
test "z : int ==> x $+ y $+ z = (z $+ y) $+ (x $+ w)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   352
test "z : int ==> x$*y $+ z = (z $+ y) $+ (y$*x $+ w)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   353
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   354
test "#-3 $* x $+ y $<= x $* #2 $+ z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   355
test "y $+ x $<= x $+ z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   356
test "x $+ y $+ z $<= x $+ z";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   357
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   358
test "y $+ (z $+ x) $< z $+ x";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   359
test "x $+ y $+ z $< (z $+ y) $+ (x $+ w)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   360
test "x$*y $+ z $< (z $+ y) $+ (y$*x $+ w)";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   361
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   362
test "l $+ #2 $+ #2 $+ #2 $+ (l $+ #2) $+ (oo $+ #2) = uu";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   363
test "u : int ==> #2 $* u = u";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   364
test "(i $+ j $+ #12 $+ k) $- #15 = y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   365
test "(i $+ j $+ #12 $+ k) $- #5 = y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   366
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   367
test "y $- b $< b";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   368
test "y $- (#3 $* b $+ c) $< b $- #2 $* c";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   369
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   370
test "(#2 $* x $- (u $* v) $+ y) $- v $* #3 $* u = w";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   371
test "(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u $* #4 = w";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   372
test "(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u = w";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   373
test "u $* v $- (x $* u $* v $+ (u $* v) $* #4 $+ y) = w";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   374
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   375
test "(i $+ j $+ #12 $+ k) = u $+ #15 $+ y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   376
test "(i $+ j $* #2 $+ #12 $+ k) = j $+ #5 $+ y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   377
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   378
test "#2 $* y $+ #3 $* z $+ #6 $* w $+ #2 $* y $+ #3 $* z $+ #2 $* u = #2 $* y' $+ #3 $* z' $+ #6 $* w' $+ #2 $* y' $+ #3 $* z' $+ u $+ vv";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   379
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   380
test "a $+ $-(b$+c) $+ b = d";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   381
test "a $+ $-(b$+c) $- b = d";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   382
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   383
(*negative numerals*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   384
test "(i $+ j $+ #-2 $+ k) $- (u $+ #5 $+ y) = zz";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   385
test "(i $+ j $+ #-3 $+ k) $< u $+ #5 $+ y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   386
test "(i $+ j $+ #3 $+ k) $< u $+ #-6 $+ y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   387
test "(i $+ j $+ #-12 $+ k) $- #15 = y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   388
test "(i $+ j $+ #12 $+ k) $- #-15 = y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   389
test "(i $+ j $+ #-12 $+ k) $- #-15 = y";
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   390
*)
e16e168984e1 installation of cancellation simprocs for the integers
paulson
parents:
diff changeset
   391