src/HOL/Integ/int_factor_simprocs.ML
author paulson
Tue, 10 Feb 2004 12:02:11 +0100
changeset 14378 69c4d5997669
parent 14113 7b3513ba0f86
child 14387 e96d5c42c4b0
permissions -rw-r--r--
generic of_nat and of_int functions, and generalization of iszero and neg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     1
(*  Title:      HOL/int_factor_simprocs.ML
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     2
    ID:         $Id$
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     4
    Copyright   2000  University of Cambridge
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     5
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     6
Factor cancellation simprocs for the integers.
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     7
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
     8
This file can't be combined with int_arith1 because it requires IntDiv.thy.
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     9
*)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    10
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    11
(** Factor cancellation theorems for "int" **)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    12
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    13
Goal "!!k::int. k~=0 ==> (k*m) div (k*n) = (m div n)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    14
by (stac zdiv_zmult_zmult1 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    15
by Auto_tac;
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    16
qed "int_mult_div_cancel1";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    17
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    18
(*For ExtractCommonTermFun, cancelling common factors*)
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    19
Goal "(k*m) div (k*n) = (if k = (0::int) then 0 else m div n)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    20
by (simp_tac (simpset() addsimps [int_mult_div_cancel1]) 1);
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    21
qed "int_mult_div_cancel_disj";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    22
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
    23
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    24
local
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    25
  open Int_Numeral_Simprocs
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    26
in
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    27
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    28
structure CancelNumeralFactorCommon =
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    29
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    30
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    31
  val dest_coeff        = dest_coeff 1
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    32
  val trans_tac         = trans_tac
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    33
  val norm_tac =
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11868
diff changeset
    34
     ALLGOALS (simp_tac (HOL_ss addsimps int_minus_from_mult_simps@mult_1s))
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10703
diff changeset
    35
     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@int_mult_minus_simps))
14113
7b3513ba0f86 Fixing a simproc bug
paulson
parents: 13485
diff changeset
    36
     THEN ALLGOALS (simp_tac (HOL_ss addsimps zmult_ac))
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    37
  val numeral_simp_tac  = ALLGOALS (simp_tac (HOL_ss addsimps bin_simps))
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    38
  val simplify_meta_eq  = simplify_meta_eq mult_1s
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    39
  end
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    40
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    41
structure DivCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    42
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
    43
  val prove_conv = Bin_Simprocs.prove_conv
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    44
  val mk_bal   = HOLogic.mk_binop "Divides.op div"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    45
  val dest_bal = HOLogic.dest_bin "Divides.op div" HOLogic.intT
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    46
  val cancel = int_mult_div_cancel1 RS trans
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    47
  val neg_exchanges = false
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    48
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    49
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    50
structure EqCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    51
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
    52
  val prove_conv = Bin_Simprocs.prove_conv
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    53
  val mk_bal   = HOLogic.mk_eq
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    54
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.intT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
    55
  val cancel = mult_cancel_left RS trans
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    56
  val neg_exchanges = false
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    57
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    58
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    59
structure LessCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    60
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
    61
  val prove_conv = Bin_Simprocs.prove_conv
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    62
  val mk_bal   = HOLogic.mk_binrel "op <"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    63
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.intT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
    64
  val cancel = mult_less_cancel_left RS trans
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    65
  val neg_exchanges = true
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    66
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    67
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    68
structure LeCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    69
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
    70
  val prove_conv = Bin_Simprocs.prove_conv
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    71
  val mk_bal   = HOLogic.mk_binrel "op <="
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    72
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.intT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
    73
  val cancel = mult_le_cancel_left RS trans
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    74
  val neg_exchanges = true
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    75
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    76
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    77
val int_cancel_numeral_factors =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    78
  map Bin_Simprocs.prep_simproc
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    79
   [("inteq_cancel_numeral_factors", ["(l::int) * m = n", "(l::int) = m * n"],
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    80
     EqCancelNumeralFactor.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    81
    ("intless_cancel_numeral_factors", ["(l::int) * m < n", "(l::int) < m * n"],
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    82
     LessCancelNumeralFactor.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    83
    ("intle_cancel_numeral_factors", ["(l::int) * m <= n", "(l::int) <= m * n"],
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    84
     LeCancelNumeralFactor.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    85
    ("intdiv_cancel_numeral_factors", ["((l::int) * m) div n", "(l::int) div (m * n)"],
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    86
     DivCancelNumeralFactor.proc)];
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    87
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    88
end;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    89
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    90
Addsimprocs int_cancel_numeral_factors;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    91
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    92
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    93
(*examples:
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    94
print_depth 22;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    95
set timing;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    96
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    97
fun test s = (Goal s; by (Simp_tac 1));
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    98
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
    99
test "9*x = 12 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   100
test "(9*x) div (12 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   101
test "9*x < 12 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   102
test "9*x <= 12 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   103
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   104
test "-99*x = 132 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   105
test "(-99*x) div (132 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   106
test "-99*x < 132 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   107
test "-99*x <= 132 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   108
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   109
test "999*x = -396 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   110
test "(999*x) div (-396 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   111
test "999*x < -396 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   112
test "999*x <= -396 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   113
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   114
test "-99*x = -81 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   115
test "(-99*x) div (-81 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   116
test "-99*x <= -81 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   117
test "-99*x < -81 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   118
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   119
test "-2 * x = -1 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   120
test "-2 * x = -(y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   121
test "(-2 * x) div (-1 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   122
test "-2 * x < -(y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   123
test "-2 * x <= -1 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   124
test "-x < -23 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   125
test "-x <= -23 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   126
*)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   127
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   128
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   129
(** Declarations for ExtractCommonTerm **)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   130
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   131
local
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   132
  open Int_Numeral_Simprocs
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   133
in
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   134
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   135
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   136
(*this version ALWAYS includes a trailing one*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   137
fun long_mk_prod []        = one
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   138
  | long_mk_prod (t :: ts) = mk_times (t, mk_prod ts);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   139
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   140
(*Find first term that matches u*)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   141
fun find_first past u []         = raise TERM("find_first", [])
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   142
  | find_first past u (t::terms) =
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   143
        if u aconv t then (rev past @ terms)
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   144
        else find_first (t::past) u terms
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   145
        handle TERM _ => find_first (t::past) u terms;
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   146
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   147
(*Final simplification: cancel + and *  *)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   148
fun cancel_simplify_meta_eq cancel_th th =
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   149
    Int_Numeral_Simprocs.simplify_meta_eq
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   150
        [zmult_1, zmult_1_right]
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   151
        (([th, cancel_th]) MRS trans);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   152
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   153
structure CancelFactorCommon =
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   154
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   155
  val mk_sum            = long_mk_prod
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   156
  val dest_sum          = dest_prod
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   157
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   158
  val dest_coeff        = dest_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   159
  val find_first        = find_first []
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   160
  val trans_tac         = trans_tac
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   161
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@zmult_ac))
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   162
  end;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   163
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   164
structure EqCancelFactor = ExtractCommonTermFun
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   165
 (open CancelFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   166
  val prove_conv = Bin_Simprocs.prove_conv
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   167
  val mk_bal   = HOLogic.mk_eq
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   168
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.intT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
   169
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_cancel_left
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   170
);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   171
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   172
structure DivideCancelFactor = ExtractCommonTermFun
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   173
 (open CancelFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   174
  val prove_conv = Bin_Simprocs.prove_conv
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   175
  val mk_bal   = HOLogic.mk_binop "Divides.op div"
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   176
  val dest_bal = HOLogic.dest_bin "Divides.op div" HOLogic.intT
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   177
  val simplify_meta_eq  = cancel_simplify_meta_eq int_mult_div_cancel_disj
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   178
);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   179
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   180
val int_cancel_factor =
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   181
  map Bin_Simprocs.prep_simproc
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   182
   [("int_eq_cancel_factor", ["(l::int) * m = n", "(l::int) = m * n"], EqCancelFactor.proc),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   183
    ("int_divide_cancel_factor", ["((l::int) * m) div n", "(l::int) div (m * n)"],
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   184
     DivideCancelFactor.proc)];
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   185
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   186
end;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   187
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   188
Addsimprocs int_cancel_factor;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   189
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   190
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   191
(*examples:
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   192
print_depth 22;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   193
set timing;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   194
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   195
fun test s = (Goal s; by (Asm_simp_tac 1));
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   196
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   197
test "x*k = k*(y::int)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   198
test "k = k*(y::int)";
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   199
test "a*(b*c) = (b::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   200
test "a*(b*c) = d*(b::int)*(x*a)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   201
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   202
test "(x*k) div (k*(y::int)) = (uu::int)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   203
test "(k) div (k*(y::int)) = (uu::int)";
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   204
test "(a*(b*c)) div ((b::int)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   205
test "(a*(b*c)) div (d*(b::int)*(x*a)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   206
*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   207