src/ZF/int_arith.ML
author wenzelm
Wed, 03 Nov 2010 10:18:05 +0100
changeset 40312 dff9f73a3763
parent 38715 6513ea67d95d
child 40313 54e8be8b4de0
permissions -rw-r--r--
more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR; proper signature constraint;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     1
(*  Title:      ZF/int_arith.ML
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     Larry Paulson
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     3
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     4
Simprocs for linear arithmetic.
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     5
*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     6
40312
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
     7
signature INT_NUMERAL_SIMPROCS =
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
     8
sig
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
     9
  val cancel_numerals: simproc list
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    10
  val combine_numerals: simproc
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    11
  val combine_numerals_prod: simproc
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    12
end
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    13
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    14
structure Int_Numeral_Simprocs: INT_NUMERAL_SIMPROCS =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    15
struct
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    16
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    17
(* abstract syntax operations *)
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    18
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    19
fun mk_bit 0 = @{term "0"}
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    20
  | mk_bit 1 = @{term "succ(0)"}
40312
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    21
  | mk_bit _ = raise TERM ("mk_bit", []);
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    22
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    23
fun dest_bit @{term "0"} = 0
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    24
  | dest_bit @{term "succ(0)"} = 1
40312
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    25
  | dest_bit t = raise TERM ("dest_bit", [t]);
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    26
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    27
fun mk_bin i =
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    28
  let
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    29
    fun term_of [] = @{term Pls}
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    30
      | term_of [~1] = @{term Min}
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    31
      | term_of (b :: bs) = @{term Bit} $ term_of bs $ mk_bit b;
35123
e286d5df187a modernized structures;
wenzelm
parents: 35112
diff changeset
    32
  in term_of (Numeral_Syntax.make_binary i) end;
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    33
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    34
fun dest_bin tm =
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    35
  let
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    36
    fun bin_of @{term Pls} = []
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    37
      | bin_of @{term Min} = [~1]
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    38
      | bin_of (@{term Bit} $ bs $ b) = dest_bit b :: bin_of bs
40312
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    39
      | bin_of _ = raise TERM ("dest_bin", [tm]);
35123
e286d5df187a modernized structures;
wenzelm
parents: 35112
diff changeset
    40
  in Numeral_Syntax.dest_binary (bin_of tm) end;
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    41
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    42
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    43
(*Utilities*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    44
35112
ff6f60e6ab85 numeral syntax: clarify parse trees vs. actual terms;
wenzelm
parents: 35020
diff changeset
    45
fun mk_numeral i = @{const integ_of} $ mk_bin i;
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    46
40312
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    47
fun dest_numeral (Const(@{const_name integ_of}, _) $ w) = dest_bin w
dff9f73a3763 more conventional exceptions for abstract syntax operations -- eliminated ancient SYS_ERROR;
wenzelm
parents: 38715
diff changeset
    48
  | dest_numeral t = raise TERM ("dest_numeral", [t]);
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    49
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    50
fun find_first_numeral past (t::terms) =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    51
        ((dest_numeral t, rev past @ terms)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    52
         handle TERM _ => find_first_numeral (t::past) terms)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    53
  | find_first_numeral past [] = raise TERM("find_first_numeral", []);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    54
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    55
val zero = mk_numeral 0;
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
    56
val mk_plus = FOLogic.mk_binop @{const_name "zadd"};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    57
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    58
(*Thus mk_sum[t] yields t+#0; longer sums don't have a trailing zero*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    59
fun mk_sum []        = zero
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    60
  | mk_sum [t,u]     = mk_plus (t, u)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    61
  | mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    62
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    63
(*this version ALWAYS includes a trailing zero*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    64
fun long_mk_sum []        = zero
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    65
  | long_mk_sum (t :: ts) = mk_plus (t, mk_sum ts);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    66
26190
cf51a23c0cd0 tuned ML code, more antiquotations;
wenzelm
parents: 26059
diff changeset
    67
val dest_plus = FOLogic.dest_bin @{const_name "zadd"} @{typ i};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    68
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    69
(*decompose additions AND subtractions as a sum*)
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
    70
fun dest_summing (pos, Const (@{const_name "zadd"}, _) $ t $ u, ts) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    71
        dest_summing (pos, t, dest_summing (pos, u, ts))
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
    72
  | dest_summing (pos, Const (@{const_name "zdiff"}, _) $ t $ u, ts) =
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    73
        dest_summing (pos, t, dest_summing (not pos, u, ts))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    74
  | dest_summing (pos, t, ts) =
27237
c94eefffc3a5 converted ML proofs;
wenzelm
parents: 27154
diff changeset
    75
        if pos then t::ts else @{const zminus} $ t :: ts;
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    76
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    77
fun dest_sum t = dest_summing (true, t, []);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    78
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
    79
val mk_diff = FOLogic.mk_binop @{const_name "zdiff"};
26190
cf51a23c0cd0 tuned ML code, more antiquotations;
wenzelm
parents: 26059
diff changeset
    80
val dest_diff = FOLogic.dest_bin @{const_name "zdiff"} @{typ i};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    81
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    82
val one = mk_numeral 1;
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
    83
val mk_times = FOLogic.mk_binop @{const_name "zmult"};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    84
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    85
fun mk_prod [] = one
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    86
  | mk_prod [t] = t
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    87
  | mk_prod (t :: ts) = if t = one then mk_prod ts
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    88
                        else mk_times (t, mk_prod ts);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    89
26190
cf51a23c0cd0 tuned ML code, more antiquotations;
wenzelm
parents: 26059
diff changeset
    90
val dest_times = FOLogic.dest_bin @{const_name "zmult"} @{typ i};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    91
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    92
fun dest_prod t =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    93
      let val (t,u) = dest_times t
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    94
      in  dest_prod t @ dest_prod u  end
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    95
      handle TERM _ => [t];
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    96
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    97
(*DON'T do the obvious simplifications; that would create special cases*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    98
fun mk_coeff (k, t) = mk_times (mk_numeral k, t);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    99
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   100
(*Express t as a product of (possibly) a numeral with other sorted terms*)
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
   101
fun dest_coeff sign (Const (@{const_name "zminus"}, _) $ t) = dest_coeff (~sign) t
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   102
  | dest_coeff sign t =
35408
b48ab741683b modernized structure Term_Ord;
wenzelm
parents: 35123
diff changeset
   103
    let val ts = sort Term_Ord.term_ord (dest_prod t)
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   104
        val (n, ts') = find_first_numeral [] ts
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   105
                          handle TERM _ => (1, ts)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   106
    in (sign*n, mk_prod ts') end;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   107
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   108
(*Find first coefficient-term THAT MATCHES u*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   109
fun find_first_coeff past u [] = raise TERM("find_first_coeff", [])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   110
  | find_first_coeff past u (t::terms) =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   111
        let val (n,u') = dest_coeff 1 t
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   112
        in  if u aconv u' then (n, rev past @ terms)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   113
                          else find_first_coeff (t::past) u terms
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   114
        end
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   115
        handle TERM _ => find_first_coeff (t::past) u terms;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   116
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   117
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   118
(*Simplify #1*n and n*#1 to n*)
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   119
val add_0s = [@{thm zadd_0_intify}, @{thm zadd_0_right_intify}];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   120
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   121
val mult_1s = [@{thm zmult_1_intify}, @{thm zmult_1_right_intify},
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   122
               @{thm zmult_minus1}, @{thm zmult_minus1_right}];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   123
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   124
val tc_rules = [@{thm integ_of_type}, @{thm intify_in_int},
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   125
                @{thm int_of_type}, @{thm zadd_type}, @{thm zdiff_type}, @{thm zmult_type}] @ 
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   126
               @{thms bin.intros};
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   127
val intifys = [@{thm intify_ident}, @{thm zadd_intify1}, @{thm zadd_intify2},
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   128
               @{thm zdiff_intify1}, @{thm zdiff_intify2}, @{thm zmult_intify1}, @{thm zmult_intify2},
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   129
               @{thm zless_intify1}, @{thm zless_intify2}, @{thm zle_intify1}, @{thm zle_intify2}];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   130
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   131
(*To perform binary arithmetic*)
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   132
val bin_simps = [@{thm add_integ_of_left}] @ @{thms bin_arith_simps} @ @{thms bin_rel_simps};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   133
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   134
(*To evaluate binary negations of coefficients*)
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   135
val zminus_simps = @{thms NCons_simps} @
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   136
                   [@{thm integ_of_minus} RS @{thm sym},
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   137
                    @{thm bin_minus_1}, @{thm bin_minus_0}, @{thm bin_minus_Pls}, @{thm bin_minus_Min},
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   138
                    @{thm bin_pred_1}, @{thm bin_pred_0}, @{thm bin_pred_Pls}, @{thm bin_pred_Min}];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   139
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   140
(*To let us treat subtraction as addition*)
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   141
val diff_simps = [@{thm zdiff_def}, @{thm zminus_zadd_distrib}, @{thm zminus_zminus}];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   142
35020
862a20ffa8e2 prefer explicit @{lemma} over adhoc forward reasoning;
wenzelm
parents: 32957
diff changeset
   143
(*push the unary minus down*)
862a20ffa8e2 prefer explicit @{lemma} over adhoc forward reasoning;
wenzelm
parents: 32957
diff changeset
   144
val int_minus_mult_eq_1_to_2 = @{lemma "$- w $* z = w $* $- z" by simp};
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   145
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   146
(*to extract again any uncancelled minuses*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   147
val int_minus_from_mult_simps =
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   148
    [@{thm zminus_zminus}, @{thm zmult_zminus}, @{thm zmult_zminus_right}];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   149
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   150
(*combine unary minus with numeric literals, however nested within a product*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   151
val int_mult_minus_simps =
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   152
    [@{thm zmult_assoc}, @{thm zmult_zminus} RS @{thm sym}, int_minus_mult_eq_1_to_2];
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   153
32155
e2bf2f73b0c8 more @{theory} antiquotations;
wenzelm
parents: 32149
diff changeset
   154
fun prep_simproc thy (name, pats, proc) =
38715
6513ea67d95d renamed Simplifier.simproc(_i) to Simplifier.simproc_global(_i) to emphasize that this is not the real thing;
wenzelm
parents: 35409
diff changeset
   155
  Simplifier.simproc_global thy name pats proc;
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   156
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   157
structure CancelNumeralsCommon =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   158
  struct
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   159
  val mk_sum            = (fn T:typ => mk_sum)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   160
  val dest_sum          = dest_sum
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   161
  val mk_coeff          = mk_coeff
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   162
  val dest_coeff        = dest_coeff 1
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   163
  val find_first_coeff  = find_first_coeff []
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   164
  fun trans_tac _       = ArithData.gen_trans_tac @{thm iff_trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   165
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   166
  val norm_ss1 = ZF_ss addsimps add_0s @ mult_1s @ diff_simps @ zminus_simps @ @{thms zadd_ac}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   167
  val norm_ss2 = ZF_ss addsimps bin_simps @ int_mult_minus_simps @ intifys
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   168
  val norm_ss3 = ZF_ss addsimps int_minus_from_mult_simps @ @{thms zadd_ac} @ @{thms zmult_ac} @ tc_rules @ intifys
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   169
  fun norm_tac ss =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   170
    ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss1))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   171
    THEN ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss2))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   172
    THEN ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss3))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   173
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   174
  val numeral_simp_ss = ZF_ss addsimps add_0s @ bin_simps @ tc_rules @ intifys
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   175
  fun numeral_simp_tac ss =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   176
    ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss))
32149
ef59550a55d3 renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 30607
diff changeset
   177
    THEN ALLGOALS (asm_simp_tac (simpset_of (Simplifier.the_context ss)))
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   178
  val simplify_meta_eq  = ArithData.simplify_meta_eq (add_0s @ mult_1s)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   179
  end;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   180
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   181
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   182
structure EqCancelNumerals = CancelNumeralsFun
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   183
 (open CancelNumeralsCommon
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   184
  val prove_conv = ArithData.prove_conv "inteq_cancel_numerals"
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   185
  val mk_bal   = FOLogic.mk_eq
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   186
  val dest_bal = FOLogic.dest_eq
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   187
  val bal_add1 = @{thm eq_add_iff1} RS @{thm iff_trans}
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   188
  val bal_add2 = @{thm eq_add_iff2} RS @{thm iff_trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   189
);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   190
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   191
structure LessCancelNumerals = CancelNumeralsFun
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   192
 (open CancelNumeralsCommon
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   193
  val prove_conv = ArithData.prove_conv "intless_cancel_numerals"
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
   194
  val mk_bal   = FOLogic.mk_binrel @{const_name "zless"}
26190
cf51a23c0cd0 tuned ML code, more antiquotations;
wenzelm
parents: 26059
diff changeset
   195
  val dest_bal = FOLogic.dest_bin @{const_name "zless"} @{typ i}
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   196
  val bal_add1 = @{thm less_add_iff1} RS @{thm iff_trans}
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   197
  val bal_add2 = @{thm less_add_iff2} RS @{thm iff_trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   198
);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   199
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   200
structure LeCancelNumerals = CancelNumeralsFun
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   201
 (open CancelNumeralsCommon
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   202
  val prove_conv = ArithData.prove_conv "intle_cancel_numerals"
26059
b67a225b50fd removed unnecessary theory qualifiers;
wenzelm
parents: 26056
diff changeset
   203
  val mk_bal   = FOLogic.mk_binrel @{const_name "zle"}
26190
cf51a23c0cd0 tuned ML code, more antiquotations;
wenzelm
parents: 26059
diff changeset
   204
  val dest_bal = FOLogic.dest_bin @{const_name "zle"} @{typ i}
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   205
  val bal_add1 = @{thm le_add_iff1} RS @{thm iff_trans}
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   206
  val bal_add2 = @{thm le_add_iff2} RS @{thm iff_trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   207
);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   208
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   209
val cancel_numerals =
32155
e2bf2f73b0c8 more @{theory} antiquotations;
wenzelm
parents: 32149
diff changeset
   210
  map (prep_simproc @{theory})
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   211
   [("inteq_cancel_numerals",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   212
     ["l $+ m = n", "l = m $+ n",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   213
      "l $- m = n", "l = m $- n",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   214
      "l $* m = n", "l = m $* n"],
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   215
     K EqCancelNumerals.proc),
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   216
    ("intless_cancel_numerals",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   217
     ["l $+ m $< n", "l $< m $+ n",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   218
      "l $- m $< n", "l $< m $- n",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   219
      "l $* m $< n", "l $< m $* n"],
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   220
     K LessCancelNumerals.proc),
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   221
    ("intle_cancel_numerals",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   222
     ["l $+ m $<= n", "l $<= m $+ n",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   223
      "l $- m $<= n", "l $<= m $- n",
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   224
      "l $* m $<= n", "l $<= m $* n"],
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   225
     K LeCancelNumerals.proc)];
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   226
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   227
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   228
(*version without the hyps argument*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   229
fun prove_conv_nohyps name tacs sg = ArithData.prove_conv name tacs sg [];
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   230
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   231
structure CombineNumeralsData =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   232
  struct
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 23146
diff changeset
   233
  type coeff            = int
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 23146
diff changeset
   234
  val iszero            = (fn x => x = 0)
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 23146
diff changeset
   235
  val add               = op + 
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   236
  val mk_sum            = (fn T:typ => long_mk_sum) (*to work for #2*x $+ #3*x *)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   237
  val dest_sum          = dest_sum
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   238
  val mk_coeff          = mk_coeff
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   239
  val dest_coeff        = dest_coeff 1
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   240
  val left_distrib      = @{thm left_zadd_zmult_distrib} RS @{thm trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   241
  val prove_conv        = prove_conv_nohyps "int_combine_numerals"
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   242
  fun trans_tac _       = ArithData.gen_trans_tac @{thm trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   243
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   244
  val norm_ss1 = ZF_ss addsimps add_0s @ mult_1s @ diff_simps @ zminus_simps @ @{thms zadd_ac} @ intifys
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   245
  val norm_ss2 = ZF_ss addsimps bin_simps @ int_mult_minus_simps @ intifys
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   246
  val norm_ss3 = ZF_ss addsimps int_minus_from_mult_simps @ @{thms zadd_ac} @ @{thms zmult_ac} @ tc_rules @ intifys
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   247
  fun norm_tac ss =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   248
    ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss1))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   249
    THEN ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss2))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   250
    THEN ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss3))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   251
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   252
  val numeral_simp_ss = ZF_ss addsimps add_0s @ bin_simps @ tc_rules @ intifys
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   253
  fun numeral_simp_tac ss =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   254
    ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   255
  val simplify_meta_eq  = ArithData.simplify_meta_eq (add_0s @ mult_1s)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   256
  end;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   257
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   258
structure CombineNumerals = CombineNumeralsFun(CombineNumeralsData);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   259
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   260
val combine_numerals =
32155
e2bf2f73b0c8 more @{theory} antiquotations;
wenzelm
parents: 32149
diff changeset
   261
  prep_simproc @{theory}
e2bf2f73b0c8 more @{theory} antiquotations;
wenzelm
parents: 32149
diff changeset
   262
    ("int_combine_numerals", ["i $+ j", "i $- j"], K CombineNumerals.proc);
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   263
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   264
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   265
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   266
(** Constant folding for integer multiplication **)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   267
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   268
(*The trick is to regard products as sums, e.g. #3 $* x $* #4 as
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   269
  the "sum" of #3, x, #4; the literals are then multiplied*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   270
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   271
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   272
structure CombineNumeralsProdData =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   273
  struct
24630
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 23146
diff changeset
   274
  type coeff            = int
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 23146
diff changeset
   275
  val iszero            = (fn x => x = 0)
351a308ab58d simplified type int (eliminated IntInf.int, integer);
wenzelm
parents: 23146
diff changeset
   276
  val add               = op *
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   277
  val mk_sum            = (fn T:typ => mk_prod)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   278
  val dest_sum          = dest_prod
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   279
  fun mk_coeff(k,t) = if t=one then mk_numeral k
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   280
                      else raise TERM("mk_coeff", [])
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   281
  fun dest_coeff t = (dest_numeral t, one)  (*We ONLY want pure numerals.*)
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   282
  val left_distrib      = @{thm zmult_assoc} RS @{thm sym} RS @{thm trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   283
  val prove_conv        = prove_conv_nohyps "int_combine_numerals_prod"
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   284
  fun trans_tac _       = ArithData.gen_trans_tac @{thm trans}
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   285
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   286
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   287
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   288
val norm_ss1 = ZF_ss addsimps mult_1s @ diff_simps @ zminus_simps
35409
5c5bb83f2bae more antiquotations;
wenzelm
parents: 35408
diff changeset
   289
  val norm_ss2 = ZF_ss addsimps [@{thm zmult_zminus_right} RS @{thm sym}] @
24893
b8ef7afe3a6b modernized specifications;
wenzelm
parents: 24630
diff changeset
   290
    bin_simps @ @{thms zmult_ac} @ tc_rules @ intifys
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   291
  fun norm_tac ss =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   292
    ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss1))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   293
    THEN ALLGOALS (asm_simp_tac (Simplifier.inherit_context ss norm_ss2))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   294
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   295
  val numeral_simp_ss = ZF_ss addsimps bin_simps @ tc_rules @ intifys
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   296
  fun numeral_simp_tac ss =
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   297
    ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss))
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   298
  val simplify_meta_eq  = ArithData.simplify_meta_eq (mult_1s);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   299
  end;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   300
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   301
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   302
structure CombineNumeralsProd = CombineNumeralsFun(CombineNumeralsProdData);
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   303
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   304
val combine_numerals_prod =
32155
e2bf2f73b0c8 more @{theory} antiquotations;
wenzelm
parents: 32149
diff changeset
   305
  prep_simproc @{theory}
e2bf2f73b0c8 more @{theory} antiquotations;
wenzelm
parents: 32149
diff changeset
   306
    ("int_combine_numerals_prod", ["i $* j"], K CombineNumeralsProd.proc);
23146
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   307
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   308
end;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   309
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   310
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   311
Addsimprocs Int_Numeral_Simprocs.cancel_numerals;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   312
Addsimprocs [Int_Numeral_Simprocs.combine_numerals,
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
             Int_Numeral_Simprocs.combine_numerals_prod];
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   314
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   315
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
(*examples:*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
(*
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   318
print_depth 22;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   319
set timing;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
set trace_simp;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
fun test s = (Goal s; by (Asm_simp_tac 1));
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
val sg = #sign (rep_thm (topthm()));
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   323
val t = FOLogic.dest_Trueprop (Logic.strip_assums_concl(getgoal 1));
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   324
val (t,_) = FOLogic.dest_eq t;
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   325
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
(*combine_numerals_prod (products of separate literals) *)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
test "#5 $* x $* #3 = y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
test "y2 $+ ?x42 = y $+ y2";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   331
test "oo : int ==> l $+ (l $+ #2) $+ oo = oo";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   332
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   333
test "#9$*x $+ y = x$*#23 $+ z";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   334
test "y $+ x = x $+ z";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   335
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   336
test "x : int ==> x $+ y $+ z = x $+ z";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
test "x : int ==> y $+ (z $+ x) = z $+ x";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
test "z : int ==> x $+ y $+ z = (z $+ y) $+ (x $+ w)";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
test "z : int ==> x$*y $+ z = (z $+ y) $+ (y$*x $+ w)";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   341
test "#-3 $* x $+ y $<= x $* #2 $+ z";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   342
test "y $+ x $<= x $+ z";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
test "x $+ y $+ z $<= x $+ z";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
test "y $+ (z $+ x) $< z $+ x";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   346
test "x $+ y $+ z $< (z $+ y) $+ (x $+ w)";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   347
test "x$*y $+ z $< (z $+ y) $+ (y$*x $+ w)";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   348
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   349
test "l $+ #2 $+ #2 $+ #2 $+ (l $+ #2) $+ (oo $+ #2) = uu";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   350
test "u : int ==> #2 $* u = u";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
test "(i $+ j $+ #12 $+ k) $- #15 = y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   352
test "(i $+ j $+ #12 $+ k) $- #5 = y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   353
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   354
test "y $- b $< b";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   355
test "y $- (#3 $* b $+ c) $< b $- #2 $* c";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
test "(#2 $* x $- (u $* v) $+ y) $- v $* #3 $* u = w";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   358
test "(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u $* #4 = w";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   359
test "(#2 $* x $* u $* v $+ (u $* v) $* #4 $+ y) $- v $* u = w";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   360
test "u $* v $- (x $* u $* v $+ (u $* v) $* #4 $+ y) = w";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   361
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
test "(i $+ j $+ #12 $+ k) = u $+ #15 $+ y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   363
test "(i $+ j $* #2 $+ #12 $+ k) = j $+ #5 $+ y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   364
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   365
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";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   366
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   367
test "a $+ $-(b$+c) $+ b = d";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   368
test "a $+ $-(b$+c) $- b = d";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   369
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   370
(*negative numerals*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   371
test "(i $+ j $+ #-2 $+ k) $- (u $+ #5 $+ y) = zz";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   372
test "(i $+ j $+ #-3 $+ k) $< u $+ #5 $+ y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   373
test "(i $+ j $+ #3 $+ k) $< u $+ #-6 $+ y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   374
test "(i $+ j $+ #-12 $+ k) $- #15 = y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   375
test "(i $+ j $+ #12 $+ k) $- #-15 = y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   376
test "(i $+ j $+ #-12 $+ k) $- #-15 = y";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   377
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   378
(*Multiplying separated numerals*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   379
Goal "#6 $* ($# x $* #2) =  uu";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   380
Goal "#4 $* ($# x $* $# x) $* (#2 $* $# x) =  uu";
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   381
*)
0bc590051d95 moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   382