src/HOL/Integ/int_factor_simprocs.ML
author wenzelm
Thu, 18 Jan 2001 20:36:57 +0100
changeset 10931 ef2b1dd40db9
parent 10713 69c9fc1d11f2
child 11701 3d51fbf81c17
permissions -rw-r--r--
use Sign.PureN, Sign.CPureN;
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
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
     8
This file can't be combined with int_arith1,2 because it requires IntDiv.thy.
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
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    13
Goal "!!k::int. (k*m <= k*n) = ((#0 < k --> m<=n) & (k < #0 --> n<=m))";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    14
by (stac zmult_zle_cancel1 1);
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    15
by Auto_tac;  
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    16
qed "int_mult_le_cancel1";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    17
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    18
Goal "!!k::int. (k*m < k*n) = ((#0 < k & m<n) | (k < #0 & n<m))";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    19
by (stac zmult_zless_cancel1 1);
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    20
by Auto_tac;  
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    21
qed "int_mult_less_cancel1";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    22
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    23
Goal "!!k::int. (k*m = k*n) = (k = #0 | m=n)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    24
by Auto_tac;  
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    25
qed "int_mult_eq_cancel1";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    26
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    27
Goal "!!k::int. k~=#0 ==> (k*m) div (k*n) = (m div n)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    28
by (stac zdiv_zmult_zmult1 1); 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    29
by Auto_tac;  
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    30
qed "int_mult_div_cancel1";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    31
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    32
(*For ExtractCommonTermFun, cancelling common factors*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    33
Goal "(k*m) div (k*n) = (if k = (#0::int) then #0 else m div n)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    34
by (simp_tac (simpset() addsimps [int_mult_div_cancel1]) 1); 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    35
qed "int_mult_div_cancel_disj";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    36
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    37
local
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    38
  open Int_Numeral_Simprocs
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    39
in
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    40
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    41
structure CancelNumeralFactorCommon =
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    42
  struct
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    43
  val mk_coeff		= mk_coeff
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    44
  val dest_coeff	= dest_coeff 1
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    45
  val trans_tac         = trans_tac
10713
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10703
diff changeset
    46
  val norm_tac = 
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10703
diff changeset
    47
     ALLGOALS (simp_tac (HOL_ss addsimps mult_1s))
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10703
diff changeset
    48
     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@int_mult_minus_simps))
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10703
diff changeset
    49
     THEN ALLGOALS
69c9fc1d11f2 simproc bug fix: negative literals and large terms
paulson
parents: 10703
diff changeset
    50
            (simp_tac (HOL_ss addsimps int_minus_from_mult_simps@zmult_ac))
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    51
  val numeral_simp_tac	= ALLGOALS (simp_tac (HOL_ss addsimps bin_simps))
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    52
  val simplify_meta_eq  = simplify_meta_eq mult_1s
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    53
  end
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    54
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    55
structure DivCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    56
 (open CancelNumeralFactorCommon
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    57
  val prove_conv = prove_conv "intdiv_cancel_numeral_factor"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    58
  val mk_bal   = HOLogic.mk_binop "Divides.op div"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    59
  val dest_bal = HOLogic.dest_bin "Divides.op div" HOLogic.intT
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    60
  val cancel = int_mult_div_cancel1 RS trans
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    61
  val neg_exchanges = false
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    62
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    63
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    64
structure EqCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    65
 (open CancelNumeralFactorCommon
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    66
  val prove_conv = prove_conv "inteq_cancel_numeral_factor"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    67
  val mk_bal   = HOLogic.mk_eq
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    68
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.intT
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    69
  val cancel = int_mult_eq_cancel1 RS trans
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    70
  val neg_exchanges = false
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    71
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    72
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    73
structure LessCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    74
 (open CancelNumeralFactorCommon
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    75
  val prove_conv = prove_conv "intless_cancel_numeral_factor"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    76
  val mk_bal   = HOLogic.mk_binrel "op <"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    77
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.intT
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    78
  val cancel = int_mult_less_cancel1 RS trans
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    79
  val neg_exchanges = true
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    80
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    81
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    82
structure LeCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    83
 (open CancelNumeralFactorCommon
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    84
  val prove_conv = prove_conv "intle_cancel_numeral_factor"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    85
  val mk_bal   = HOLogic.mk_binrel "op <="
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    86
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.intT
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    87
  val cancel = int_mult_le_cancel1 RS trans
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    88
  val neg_exchanges = true
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    89
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    90
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    91
val int_cancel_numeral_factors = 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    92
  map prep_simproc
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    93
   [("inteq_cancel_numeral_factors",
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    94
     prep_pats ["(l::int) * m = n", "(l::int) = m * n"], 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    95
     EqCancelNumeralFactor.proc),
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    96
    ("intless_cancel_numeral_factors", 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    97
     prep_pats ["(l::int) * m < n", "(l::int) < m * n"], 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    98
     LessCancelNumeralFactor.proc),
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    99
    ("intle_cancel_numeral_factors", 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   100
     prep_pats ["(l::int) * m <= n", "(l::int) <= m * n"], 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   101
     LeCancelNumeralFactor.proc),
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   102
    ("intdiv_cancel_numeral_factors", 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   103
     prep_pats ["((l::int) * m) div n", "(l::int) div (m * n)"], 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   104
     DivCancelNumeralFactor.proc)];
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   105
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   106
end;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   107
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   108
Addsimprocs int_cancel_numeral_factors;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   109
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   110
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   111
(*examples:
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   112
print_depth 22;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   113
set timing;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   114
set trace_simp;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   115
fun test s = (Goal s; by (Simp_tac 1)); 
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   116
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   117
test "#9*x = #12 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   118
test "(#9*x) div (#12 * (y::int)) = z";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   119
test "#9*x < #12 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   120
test "#9*x <= #12 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   121
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   122
test "#-99*x = #132 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   123
test "(#-99*x) div (#132 * (y::int)) = z";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   124
test "#-99*x < #132 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   125
test "#-99*x <= #132 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   126
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   127
test "#999*x = #-396 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   128
test "(#999*x) div (#-396 * (y::int)) = z";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   129
test "#999*x < #-396 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   130
test "#999*x <= #-396 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   131
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   132
test "#-99*x = #-81 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   133
test "(#-99*x) div (#-81 * (y::int)) = z";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   134
test "#-99*x <= #-81 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   135
test "#-99*x < #-81 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   136
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   137
test "#-2 * x = #-1 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   138
test "#-2 * x = -(y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   139
test "(#-2 * x) div (#-1 * (y::int)) = z";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   140
test "#-2 * x < -(y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   141
test "#-2 * x <= #-1 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   142
test "-x < #-23 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   143
test "-x <= #-23 * (y::int)";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   144
*)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   145
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
(** Declarations for ExtractCommonTerm **)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   148
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   149
local
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   150
  open Int_Numeral_Simprocs
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   151
in
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
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   154
(*this version ALWAYS includes a trailing one*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   155
fun long_mk_prod []        = one
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   156
  | long_mk_prod (t :: ts) = mk_times (t, mk_prod ts);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   157
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   158
(*Find first term that matches u*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   159
fun find_first past u []         = raise TERM("find_first", []) 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   160
  | find_first past u (t::terms) =
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   161
	if u aconv t then (rev past @ terms)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   162
        else find_first (t::past) u terms
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   163
	handle TERM _ => find_first (t::past) u terms;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   164
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   165
(*Final simplification: cancel + and *  *)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   166
fun cancel_simplify_meta_eq cancel_th th = 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   167
    Int_Numeral_Simprocs.simplify_meta_eq 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   168
        [zmult_1, zmult_1_right] 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   169
        (([th, cancel_th]) MRS trans);
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
structure CancelFactorCommon =
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   172
  struct
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   173
  val mk_sum    	= long_mk_prod
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   174
  val dest_sum		= dest_prod
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   175
  val mk_coeff		= mk_coeff
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   176
  val dest_coeff	= dest_coeff
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   177
  val find_first	= find_first []
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   178
  val trans_tac         = trans_tac
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   179
  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
   180
  end;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   181
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   182
structure EqCancelFactor = ExtractCommonTermFun
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   183
 (open CancelFactorCommon
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   184
  val prove_conv = prove_conv "int_eq_cancel_factor"
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   185
  val mk_bal   = HOLogic.mk_eq
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   186
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.intT
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   187
  val simplify_meta_eq  = cancel_simplify_meta_eq int_mult_eq_cancel1
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   188
);
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
structure DivideCancelFactor = ExtractCommonTermFun
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   191
 (open CancelFactorCommon
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   192
  val prove_conv = prove_conv "int_divide_cancel_factor"
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   193
  val mk_bal   = HOLogic.mk_binop "Divides.op div"
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   194
  val dest_bal = HOLogic.dest_bin "Divides.op div" HOLogic.intT
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   195
  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
   196
);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   197
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   198
val int_cancel_factor = 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   199
  map prep_simproc
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   200
   [("int_eq_cancel_factor",
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   201
     prep_pats ["(l::int) * m = n", "(l::int) = m * n"], 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   202
     EqCancelFactor.proc),
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   203
    ("int_divide_cancel_factor", 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   204
     prep_pats ["((l::int) * m) div n", "(l::int) div (m * n)"], 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   205
     DivideCancelFactor.proc)];
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
end;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   208
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   209
Addsimprocs int_cancel_factor;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   210
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   211
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   212
(*examples:
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   213
print_depth 22;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   214
set timing;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   215
set trace_simp;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   216
fun test s = (Goal s; by (Asm_simp_tac 1)); 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   217
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   218
test "x*k = k*(y::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   219
test "k = k*(y::int)"; 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   220
test "a*(b*c) = (b::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   221
test "a*(b*c) = d*(b::int)*(x*a)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   222
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   223
test "(x*k) div (k*(y::int)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   224
test "(k) div (k*(y::int)) = (uu::int)"; 
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   225
test "(a*(b*c)) div ((b::int)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   226
test "(a*(b*c)) div (d*(b::int)*(x*a)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   227
*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   228