src/HOL/Integ/int_factor_simprocs.ML
author haftmann
Wed, 06 Sep 2006 13:48:02 +0200
changeset 20485 3078fd2eec7b
parent 20044 92cc2f4c7335
child 21416 f23e4e75dfd3
permissions -rw-r--r--
got rid of Numeral.bin type
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
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
     6
Factor cancellation simprocs for the integers (and for fields).
10536
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
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    11
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    12
(*To quote from Provers/Arith/cancel_numeral_factor.ML:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    13
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    14
Cancels common coefficients in balanced expressions:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    15
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    16
     u*#m ~~ u'*#m'  ==  #n*u ~~ #n'*u'
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    17
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    18
where ~~ is an appropriate balancing operation (e.g. =, <=, <, div, /)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    19
and d = gcd(m,m') and n=m/d and n'=m'/d.
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    20
*)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    21
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    22
val rel_number_of = [eq_number_of_eq, less_number_of_eq_neg, le_number_of_eq];
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    23
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    24
(** Factor cancellation theorems for integer division (div, not /) **)
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    25
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    26
Goal "!!k::int. k~=0 ==> (k*m) div (k*n) = (m div n)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    27
by (stac zdiv_zmult_zmult1 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    28
by Auto_tac;
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    29
qed "int_mult_div_cancel1";
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    30
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    31
(*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
    32
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
    33
by (simp_tac (simpset() addsimps [int_mult_div_cancel1]) 1);
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    34
qed "int_mult_div_cancel_disj";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
    35
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
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
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    43
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
    44
  val dest_coeff        = dest_coeff 1
16973
b2a894562b8f simprocs: Simplifier.inherit_bounds;
wenzelm
parents: 15271
diff changeset
    45
  val trans_tac         = fn _ => trans_tac
18328
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    46
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    47
  val norm_ss1 = HOL_ss addsimps minus_from_mult_simps @ mult_1s
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    48
  val norm_ss2 = HOL_ss addsimps simps @ mult_minus_simps
18328
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    49
  val norm_ss3 = HOL_ss addsimps mult_ac
16973
b2a894562b8f simprocs: Simplifier.inherit_bounds;
wenzelm
parents: 15271
diff changeset
    50
  fun norm_tac ss =
18328
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    51
    ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss1))
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    52
    THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss2))
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    53
    THEN ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss3))
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    54
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    55
  val numeral_simp_ss = HOL_ss addsimps rel_number_of @ simps
18328
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
    56
  fun numeral_simp_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss numeral_simp_ss))
16973
b2a894562b8f simprocs: Simplifier.inherit_bounds;
wenzelm
parents: 15271
diff changeset
    57
  val simplify_meta_eq = 
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    58
	Int_Numeral_Simprocs.simplify_meta_eq
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    59
	     [add_0, add_0_right,
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    60
	      mult_zero_left, mult_zero_right, mult_num1, mult_1_right];
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    61
  end
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    62
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    63
(*Version for integer division*)
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    64
structure DivCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    65
 (open CancelNumeralFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    66
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    67
  val mk_bal   = HOLogic.mk_binop "Divides.op div"
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    68
  val dest_bal = HOLogic.dest_bin "Divides.op div" HOLogic.intT
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    69
  val cancel = int_mult_div_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
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    73
(*Version for fields*)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    74
structure FieldDivCancelNumeralFactor = CancelNumeralFactorFun
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    75
 (open CancelNumeralFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    76
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    77
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    78
  val dest_bal = HOLogic.dest_bin "HOL.divide" Term.dummyT
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    79
  val cancel = mult_divide_cancel_left RS trans
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    80
  val neg_exchanges = false
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    81
)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    82
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    83
(*Version for ordered rings: mult_cancel_left requires an ordering*)
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    84
structure EqCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    85
 (open CancelNumeralFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    86
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    87
  val mk_bal   = HOLogic.mk_eq
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    88
  val dest_bal = HOLogic.dest_bin "op =" Term.dummyT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
    89
  val cancel = mult_cancel_left RS trans
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    90
  val neg_exchanges = false
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    91
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
    92
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    93
(*Version for (unordered) fields*)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    94
structure FieldEqCancelNumeralFactor = CancelNumeralFactorFun
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    95
 (open CancelNumeralFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
    96
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    97
  val mk_bal   = HOLogic.mk_eq
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    98
  val dest_bal = HOLogic.dest_bin "op =" Term.dummyT
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
    99
  val cancel = field_mult_cancel_left RS trans
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   100
  val neg_exchanges = false
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   101
)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   102
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   103
structure LessCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   104
 (open CancelNumeralFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   105
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
19277
f7602e74d948 renamed op < <= to Orderings.less(_eq)
haftmann
parents: 18442
diff changeset
   106
  val mk_bal   = HOLogic.mk_binrel "Orderings.less"
f7602e74d948 renamed op < <= to Orderings.less(_eq)
haftmann
parents: 18442
diff changeset
   107
  val dest_bal = HOLogic.dest_bin "Orderings.less" Term.dummyT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
   108
  val cancel = mult_less_cancel_left RS trans
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   109
  val neg_exchanges = true
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   110
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   111
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   112
structure LeCancelNumeralFactor = CancelNumeralFactorFun
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   113
 (open CancelNumeralFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   114
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
19277
f7602e74d948 renamed op < <= to Orderings.less(_eq)
haftmann
parents: 18442
diff changeset
   115
  val mk_bal   = HOLogic.mk_binrel "Orderings.less_eq"
f7602e74d948 renamed op < <= to Orderings.less(_eq)
haftmann
parents: 18442
diff changeset
   116
  val dest_bal = HOLogic.dest_bin "Orderings.less_eq" Term.dummyT
14378
69c4d5997669 generic of_nat and of_int functions, and generalization of iszero
paulson
parents: 14113
diff changeset
   117
  val cancel = mult_le_cancel_left RS trans
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   118
  val neg_exchanges = true
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   119
)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   120
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   121
val ring_cancel_numeral_factors =
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   122
  map Int_Numeral_Base_Simprocs.prep_simproc
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   123
   [("ring_eq_cancel_numeral_factor",
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   124
     ["(l::'a::{ordered_idom,number_ring}) * m = n",
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   125
      "(l::'a::{ordered_idom,number_ring}) = m * n"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   126
     K EqCancelNumeralFactor.proc),
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   127
    ("ring_less_cancel_numeral_factor",
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   128
     ["(l::'a::{ordered_idom,number_ring}) * m < n",
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   129
      "(l::'a::{ordered_idom,number_ring}) < m * n"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   130
     K LessCancelNumeralFactor.proc),
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   131
    ("ring_le_cancel_numeral_factor",
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   132
     ["(l::'a::{ordered_idom,number_ring}) * m <= n",
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   133
      "(l::'a::{ordered_idom,number_ring}) <= m * n"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   134
     K LeCancelNumeralFactor.proc),
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   135
    ("int_div_cancel_numeral_factors",
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   136
     ["((l::int) * m) div n", "(l::int) div (m * n)"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   137
     K DivCancelNumeralFactor.proc)];
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   138
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   139
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   140
val field_cancel_numeral_factors =
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   141
  map Int_Numeral_Base_Simprocs.prep_simproc
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   142
   [("field_eq_cancel_numeral_factor",
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   143
     ["(l::'a::{field,number_ring}) * m = n",
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   144
      "(l::'a::{field,number_ring}) = m * n"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   145
     K FieldEqCancelNumeralFactor.proc),
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   146
    ("field_cancel_numeral_factor",
14426
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   147
     ["((l::'a::{division_by_zero,field,number_ring}) * m) / n",
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   148
      "(l::'a::{division_by_zero,field,number_ring}) / (m * n)",
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   149
      "((number_of v)::'a::{division_by_zero,field,number_ring}) / (number_of w)"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   150
     K FieldDivCancelNumeralFactor.proc)]
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   151
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   152
end;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   153
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   154
Addsimprocs ring_cancel_numeral_factors;
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   155
Addsimprocs field_cancel_numeral_factors;
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   156
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   157
(*examples:
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   158
print_depth 22;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   159
set timing;
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   160
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   161
fun test s = (Goal s; by (Simp_tac 1));
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   162
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   163
test "9*x = 12 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   164
test "(9*x) div (12 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   165
test "9*x < 12 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   166
test "9*x <= 12 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   167
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   168
test "-99*x = 132 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   169
test "(-99*x) div (132 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   170
test "-99*x < 132 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   171
test "-99*x <= 132 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   172
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   173
test "999*x = -396 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   174
test "(999*x) div (-396 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   175
test "999*x < -396 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   176
test "999*x <= -396 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   177
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   178
test "-99*x = -81 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   179
test "(-99*x) div (-81 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   180
test "-99*x <= -81 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   181
test "-99*x < -81 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   182
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   183
test "-2 * x = -1 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   184
test "-2 * x = -(y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   185
test "(-2 * x) div (-1 * (y::int)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   186
test "-2 * x < -(y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   187
test "-2 * x <= -1 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   188
test "-x < -23 * (y::int)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   189
test "-x <= -23 * (y::int)";
10536
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   190
*)
8f34ecae1446 invoking CancelNumeralFactorFun
paulson
parents:
diff changeset
   191
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   192
(*And the same examples for fields such as rat or real:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   193
test "0 <= (y::rat) * -2";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   194
test "9*x = 12 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   195
test "(9*x) / (12 * (y::rat)) = z";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   196
test "9*x < 12 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   197
test "9*x <= 12 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   198
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   199
test "-99*x = 132 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   200
test "(-99*x) / (132 * (y::rat)) = z";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   201
test "-99*x < 132 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   202
test "-99*x <= 132 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   203
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   204
test "999*x = -396 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   205
test "(999*x) / (-396 * (y::rat)) = z";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   206
test "999*x < -396 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   207
test "999*x <= -396 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   208
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   209
test  "(- ((2::rat) * x) <= 2 * y)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   210
test "-99*x = -81 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   211
test "(-99*x) / (-81 * (y::rat)) = z";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   212
test "-99*x <= -81 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   213
test "-99*x < -81 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   214
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   215
test "-2 * x = -1 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   216
test "-2 * x = -(y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   217
test "(-2 * x) / (-1 * (y::rat)) = z";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   218
test "-2 * x < -(y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   219
test "-2 * x <= -1 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   220
test "-x < -23 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   221
test "-x <= -23 * (y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   222
*)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   223
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   224
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   225
(** Declarations for ExtractCommonTerm **)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   226
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   227
local
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   228
  open Int_Numeral_Simprocs
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   229
in
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   230
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   231
(*Find first term that matches u*)
18442
b35d7312c64f resolved shadowing of Library.find_first
haftmann
parents: 18328
diff changeset
   232
fun find_first_t past u []         = raise TERM ("find_first_t", [])
b35d7312c64f resolved shadowing of Library.find_first
haftmann
parents: 18328
diff changeset
   233
  | find_first_t past u (t::terms) =
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   234
        if u aconv t then (rev past @ terms)
18442
b35d7312c64f resolved shadowing of Library.find_first
haftmann
parents: 18328
diff changeset
   235
        else find_first_t (t::past) u terms
b35d7312c64f resolved shadowing of Library.find_first
haftmann
parents: 18328
diff changeset
   236
        handle TERM _ => find_first_t (t::past) u terms;
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   237
15271
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   238
(** Final simplification for the CancelFactor simprocs **)
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   239
val simplify_one = 
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   240
    Int_Numeral_Simprocs.simplify_meta_eq  
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   241
       [mult_1_left, mult_1_right, zdiv_1, numeral_1_eq_1];
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   242
16973
b2a894562b8f simprocs: Simplifier.inherit_bounds;
wenzelm
parents: 15271
diff changeset
   243
fun cancel_simplify_meta_eq cancel_th ss th =
b2a894562b8f simprocs: Simplifier.inherit_bounds;
wenzelm
parents: 15271
diff changeset
   244
    simplify_one ss (([th, cancel_th]) MRS trans);
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   245
14426
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   246
(*At present, long_mk_prod creates Numeral1, so this requires the axclass
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   247
  number_ring*)
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   248
structure CancelFactorCommon =
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   249
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   250
  val mk_sum            = long_mk_prod
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   251
  val dest_sum          = dest_prod
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   252
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   253
  val dest_coeff        = dest_coeff
18442
b35d7312c64f resolved shadowing of Library.find_first
haftmann
parents: 18328
diff changeset
   254
  val find_first        = find_first_t []
16973
b2a894562b8f simprocs: Simplifier.inherit_bounds;
wenzelm
parents: 15271
diff changeset
   255
  val trans_tac         = fn _ => trans_tac
18328
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
   256
  val norm_ss = HOL_ss addsimps mult_1s @ mult_ac
841261f303a1 simprocs: static evaluation of simpset;
wenzelm
parents: 17877
diff changeset
   257
  fun norm_tac ss = ALLGOALS (simp_tac (Simplifier.inherit_context ss norm_ss))
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   258
  end;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   259
14738
83f1a514dcb4 changes made due to new Ring_and_Field theory
obua
parents: 14426
diff changeset
   260
(*mult_cancel_left requires an ordered comm_ring_1, such as int. The version in
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   261
  rat_arith.ML works for all fields.*)
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   262
structure EqCancelFactor = ExtractCommonTermFun
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   263
 (open CancelFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   264
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   265
  val mk_bal   = HOLogic.mk_eq
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   266
  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
   267
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_cancel_left
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   268
);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   269
14387
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   270
(*int_mult_div_cancel_disj is for integer division (div). The version in
e96d5c42c4b0 Polymorphic treatment of binary arithmetic using axclasses
paulson
parents: 14378
diff changeset
   271
  rat_arith.ML works for all fields, using real division (/).*)
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   272
structure DivideCancelFactor = ExtractCommonTermFun
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   273
 (open CancelFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   274
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   275
  val mk_bal   = HOLogic.mk_binop "Divides.op div"
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   276
  val dest_bal = HOLogic.dest_bin "Divides.op div" HOLogic.intT
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   277
  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
   278
);
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   279
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   280
val int_cancel_factor =
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   281
  map Int_Numeral_Base_Simprocs.prep_simproc
15271
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   282
   [("ring_eq_cancel_factor", ["(l::int) * m = n", "(l::int) = m * n"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   283
    K EqCancelFactor.proc),
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   284
    ("int_divide_cancel_factor", ["((l::int) * m) div n", "(l::int) div (m*n)"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   285
     K DivideCancelFactor.proc)];
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   286
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   287
(** Versions for all fields, including unordered ones (type complex).*)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   288
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   289
structure FieldEqCancelFactor = ExtractCommonTermFun
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   290
 (open CancelFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   291
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   292
  val mk_bal   = HOLogic.mk_eq
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   293
  val dest_bal = HOLogic.dest_bin "op =" Term.dummyT
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   294
  val simplify_meta_eq  = cancel_simplify_meta_eq field_mult_cancel_left
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   295
);
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   296
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   297
structure FieldDivideCancelFactor = ExtractCommonTermFun
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   298
 (open CancelFactorCommon
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   299
  val prove_conv = Int_Numeral_Base_Simprocs.prove_conv
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   300
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   301
  val dest_bal = HOLogic.dest_bin "HOL.divide" Term.dummyT
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   302
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_divide_cancel_eq_if
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   303
);
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   304
15271
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   305
(*The number_ring class is necessary because the simprocs refer to the
14426
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   306
  binary number 1.  FIXME: probably they could use 1 instead.*)
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   307
val field_cancel_factor =
20485
3078fd2eec7b got rid of Numeral.bin type
haftmann
parents: 20044
diff changeset
   308
  map Int_Numeral_Base_Simprocs.prep_simproc
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   309
   [("field_eq_cancel_factor",
14426
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   310
     ["(l::'a::{field,number_ring}) * m = n",
15271
3c32a26510c4 fixed some awkward problems with nat/int simprocs
paulson
parents: 14738
diff changeset
   311
      "(l::'a::{field,number_ring}) = m * n"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   312
     K FieldEqCancelFactor.proc),
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   313
    ("field_divide_cancel_factor",
14426
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   314
     ["((l::'a::{division_by_zero,field,number_ring}) * m) / n",
de890c247b38 fixed bugs in the setup of arithmetic procedures
paulson
parents: 14390
diff changeset
   315
      "(l::'a::{division_by_zero,field,number_ring}) / (m * n)"],
20044
92cc2f4c7335 simprocs: no theory argument -- use simpset context instead;
wenzelm
parents: 19277
diff changeset
   316
     K FieldDivideCancelFactor.proc)];
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   317
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   318
end;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   319
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   320
Addsimprocs int_cancel_factor;
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   321
Addsimprocs field_cancel_factor;
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   322
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   323
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   324
(*examples:
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   325
print_depth 22;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   326
set timing;
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   327
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   328
fun test s = (Goal s; by (Asm_simp_tac 1));
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   329
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   330
test "x*k = k*(y::int)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   331
test "k = k*(y::int)";
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   332
test "a*(b*c) = (b::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   333
test "a*(b*c) = d*(b::int)*(x*a)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   334
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   335
test "(x*k) div (k*(y::int)) = (uu::int)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12018
diff changeset
   336
test "(k) div (k*(y::int)) = (uu::int)";
10703
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   337
test "(a*(b*c)) div ((b::int)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   338
test "(a*(b*c)) div (d*(b::int)*(x*a)) = (uu::int)";
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   339
*)
ba98f00cec4f inserting the simproc int_cancel_factor
paulson
parents: 10536
diff changeset
   340
14390
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   341
(*And the same examples for fields such as rat or real:
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   342
print_depth 22;
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   343
set timing;
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   344
set trace_simp;
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   345
fun test s = (Goal s; by (Asm_simp_tac 1));
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   346
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   347
test "x*k = k*(y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   348
test "k = k*(y::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   349
test "a*(b*c) = (b::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   350
test "a*(b*c) = d*(b::rat)*(x*a)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   351
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   352
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   353
test "(x*k) / (k*(y::rat)) = (uu::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   354
test "(k) / (k*(y::rat)) = (uu::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   355
test "(a*(b*c)) / ((b::rat)) = (uu::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   356
test "(a*(b*c)) / (d*(b::rat)*(x*a)) = (uu::rat)";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   357
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   358
(*FIXME: what do we do about this?*)
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   359
test "a*(b*c)/(y*z) = d*(b::rat)*(x*a)/z";
55fe71faadda further tweaks to the numeric theories
paulson
parents: 14387
diff changeset
   360
*)