src/HOL/Real/real_arith.ML
author paulson
Thu, 01 Jan 2004 10:06:32 +0100
changeset 14334 6137d24eef79
parent 14321 55c688d2eefa
child 14336 8f731d3cd65b
permissions -rw-r--r--
tweaking of lemmas in RealDef, RealOrd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Real/real_arith.ML
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     3
    Author:     Tobias Nipkow, TU Muenchen
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
     4
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     5
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
     6
Simprocs: Common factor cancellation & Rational coefficient handling
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     7
*)
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
     8
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
     9
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    10
(****Common factor cancellation****)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    11
14293
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    12
(*To quote from Provers/Arith/cancel_numeral_factor.ML:
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    13
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    14
This simproc Cancels common coefficients in balanced expressions:
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    15
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    16
     u*#m ~~ u'*#m'  ==  #n*u ~~ #n'*u'
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    17
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    18
where ~~ is an appropriate balancing operation (e.g. =, <=, <, div, /)
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    19
and d = gcd(m,m') and n=m/d and n'=m'/d.
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    20
*)
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
    21
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
    22
local
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    23
  open Real_Numeral_Simprocs
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    24
in
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    25
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    26
val rel_real_number_of = [eq_real_number_of, less_real_number_of,
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    27
                          le_real_number_of_eq_not_less]
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    28
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    29
structure CancelNumeralFactorCommon =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    30
  struct
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    31
  val mk_coeff          = mk_coeff
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    32
  val dest_coeff        = dest_coeff 1
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    33
  val trans_tac         = trans_tac
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    34
  val norm_tac =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    35
     ALLGOALS (simp_tac (HOL_ss addsimps real_minus_from_mult_simps @ mult_1s))
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    36
     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps))
14334
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14321
diff changeset
    37
     THEN ALLGOALS (simp_tac (HOL_ss addsimps mult_ac))
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    38
  val numeral_simp_tac  =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    39
         ALLGOALS (simp_tac (HOL_ss addsimps rel_real_number_of@bin_simps))
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    40
  val simplify_meta_eq  = simplify_meta_eq
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    41
  end
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    42
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    43
structure DivCancelNumeralFactor = CancelNumeralFactorFun
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    44
 (open CancelNumeralFactorCommon
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    45
  val prove_conv = Bin_Simprocs.prove_conv
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    46
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    47
  val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14293
diff changeset
    48
  val cancel = mult_divide_cancel_left RS trans
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    49
  val neg_exchanges = false
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    50
)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    51
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    52
structure EqCancelNumeralFactor = CancelNumeralFactorFun
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    53
 (open CancelNumeralFactorCommon
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    54
  val prove_conv = Bin_Simprocs.prove_conv
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    55
  val mk_bal   = HOLogic.mk_eq
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    56
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14293
diff changeset
    57
  val cancel = mult_cancel_left RS trans
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    58
  val neg_exchanges = false
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    59
)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    60
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    61
structure LessCancelNumeralFactor = CancelNumeralFactorFun
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    62
 (open CancelNumeralFactorCommon
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    63
  val prove_conv = Bin_Simprocs.prove_conv
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    64
  val mk_bal   = HOLogic.mk_binrel "op <"
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    65
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14293
diff changeset
    66
  val cancel = mult_less_cancel_left RS trans
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    67
  val neg_exchanges = true
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    68
)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    69
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    70
structure LeCancelNumeralFactor = CancelNumeralFactorFun
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    71
 (open CancelNumeralFactorCommon
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    72
  val prove_conv = Bin_Simprocs.prove_conv
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    73
  val mk_bal   = HOLogic.mk_binrel "op <="
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    74
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14293
diff changeset
    75
  val cancel = mult_le_cancel_left RS trans
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    76
  val neg_exchanges = true
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    77
)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    78
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    79
val real_cancel_numeral_factors_relations =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    80
  map prep_simproc
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    81
   [("realeq_cancel_numeral_factor",
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    82
     ["(l::real) * m = n", "(l::real) = m * n"],
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    83
     EqCancelNumeralFactor.proc),
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    84
    ("realless_cancel_numeral_factor",
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    85
     ["(l::real) * m < n", "(l::real) < m * n"],
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    86
     LessCancelNumeralFactor.proc),
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    87
    ("realle_cancel_numeral_factor",
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    88
     ["(l::real) * m <= n", "(l::real) <= m * n"],
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    89
     LeCancelNumeralFactor.proc)]
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    90
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    91
val real_cancel_numeral_factors_divide = prep_simproc
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    92
        ("realdiv_cancel_numeral_factor",
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    93
         ["((l::real) * m) / n", "(l::real) / (m * n)",
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    94
          "((number_of v)::real) / (number_of w)"],
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    95
         DivCancelNumeralFactor.proc)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    96
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    97
val real_cancel_numeral_factors =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    98
    real_cancel_numeral_factors_relations @
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
    99
    [real_cancel_numeral_factors_divide]
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   100
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   101
end;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   102
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   103
Addsimprocs real_cancel_numeral_factors;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   104
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   105
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   106
(*examples:
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   107
print_depth 22;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   108
set timing;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   109
set trace_simp;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   110
fun test s = (Goal s; by (Simp_tac 1));
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   111
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   112
test "0 <= (y::real) * -2";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   113
test "9*x = 12 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   114
test "(9*x) / (12 * (y::real)) = z";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   115
test "9*x < 12 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   116
test "9*x <= 12 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   117
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   118
test "-99*x = 132 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   119
test "(-99*x) / (132 * (y::real)) = z";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   120
test "-99*x < 132 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   121
test "-99*x <= 132 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   122
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   123
test "999*x = -396 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   124
test "(999*x) / (-396 * (y::real)) = z";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   125
test "999*x < -396 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   126
test "999*x <= -396 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   127
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   128
test  "(- ((2::real) * x) <= 2 * y)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   129
test "-99*x = -81 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   130
test "(-99*x) / (-81 * (y::real)) = z";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   131
test "-99*x <= -81 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   132
test "-99*x < -81 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   133
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   134
test "-2 * x = -1 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   135
test "-2 * x = -(y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   136
test "(-2 * x) / (-1 * (y::real)) = z";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   137
test "-2 * x < -(y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   138
test "-2 * x <= -1 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   139
test "-x < -23 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   140
test "-x <= -23 * (y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   141
*)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   142
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   143
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   144
(** Declarations for ExtractCommonTerm **)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   145
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   146
local
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   147
  open Real_Numeral_Simprocs
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   148
in
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   149
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   150
structure CancelFactorCommon =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   151
  struct
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   152
  val mk_sum            = long_mk_prod
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   153
  val dest_sum          = dest_prod
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   154
  val mk_coeff          = mk_coeff
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   155
  val dest_coeff        = dest_coeff
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   156
  val find_first        = find_first []
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   157
  val trans_tac         = trans_tac
14334
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14321
diff changeset
   158
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@mult_ac))
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   159
  end;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   160
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   161
structure EqCancelFactor = ExtractCommonTermFun
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   162
 (open CancelFactorCommon
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   163
  val prove_conv = Bin_Simprocs.prove_conv
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   164
  val mk_bal   = HOLogic.mk_eq
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   165
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14293
diff changeset
   166
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_cancel_left
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   167
);
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   168
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   169
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   170
structure DivideCancelFactor = ExtractCommonTermFun
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   171
 (open CancelFactorCommon
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   172
  val prove_conv = Bin_Simprocs.prove_conv
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   173
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   174
  val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 14293
diff changeset
   175
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_divide_cancel_eq_if
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   176
);
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   177
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   178
val real_cancel_factor =
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   179
  map prep_simproc
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   180
   [("real_eq_cancel_factor", ["(l::real) * m = n", "(l::real) = m * n"], EqCancelFactor.proc),
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   181
    ("real_divide_cancel_factor", ["((l::real) * m) / n", "(l::real) / (m * n)"],
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   182
     DivideCancelFactor.proc)];
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   183
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   184
end;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   185
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   186
Addsimprocs real_cancel_factor;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   187
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   188
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   189
(*examples:
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   190
print_depth 22;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   191
set timing;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   192
set trace_simp;
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   193
fun test s = (Goal s; by (Asm_simp_tac 1));
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   194
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   195
test "x*k = k*(y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   196
test "k = k*(y::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   197
test "a*(b*c) = (b::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   198
test "a*(b*c) = d*(b::real)*(x*a)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   199
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   200
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   201
test "(x*k) / (k*(y::real)) = (uu::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   202
test "(k) / (k*(y::real)) = (uu::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   203
test "(a*(b*c)) / ((b::real)) = (uu::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   204
test "(a*(b*c)) / (d*(b::real)*(x*a)) = (uu::real)";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   205
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   206
(*FIXME: what do we do about this?*)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   207
test "a*(b*c)/(y*z) = d*(b::real)*(x*a)/z";
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   208
*)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   209
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   210
(****Augmentation of real linear arithmetic with 
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   211
     rational coefficient handling****)
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   212
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   213
local
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   214
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   215
(* reduce contradictory <= to False *)
14288
d149e3cbdb39 Moving some theorems from Real/RealArith0.ML
paulson
parents: 10758
diff changeset
   216
val simps = [True_implies_equals,
14334
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14321
diff changeset
   217
             inst "a" "(number_of ?v)::real" right_distrib,
14289
deb8e1e62002 combining Real/{RealArith0,real_arith}.ML
paulson
parents: 14288
diff changeset
   218
             divide_1,times_divide_eq_right,times_divide_eq_left];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   219
14293
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
   220
val simprocs = [real_cancel_numeral_factors_divide,
22542982bffd moving some division theorems to Ring_and_Field
paulson
parents: 14289
diff changeset
   221
                real_cancel_numeral_factors_divide];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   222
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   223
fun cvar(th,_ $ (_ $ _ $ var)) = cterm_of (#sign(rep_thm th)) var;
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   224
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   225
val real_mult_mono_thms =
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   226
 [(rotate_prems 1 real_mult_less_mono2,
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   227
   cvar(real_mult_less_mono2, hd(prems_of real_mult_less_mono2))),
14334
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14321
diff changeset
   228
  (real_mult_left_mono,
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14321
diff changeset
   229
   cvar(real_mult_left_mono, hd(tl(prems_of real_mult_left_mono))))]
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   230
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   231
in
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   232
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   233
val real_arith_setup =
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   234
 [Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} =>
10722
55c8367bab05 rational linear arithmetic
nipkow
parents: 10693
diff changeset
   235
   {add_mono_thms = add_mono_thms,
10693
9e4a0e84d0d6 moved mk_bin from Numerals to HOLogic
nipkow
parents: 10574
diff changeset
   236
    mult_mono_thms = mult_mono_thms @ real_mult_mono_thms,
10722
55c8367bab05 rational linear arithmetic
nipkow
parents: 10693
diff changeset
   237
    inj_thms = inj_thms,
55c8367bab05 rational linear arithmetic
nipkow
parents: 10693
diff changeset
   238
    lessD = lessD,
55c8367bab05 rational linear arithmetic
nipkow
parents: 10693
diff changeset
   239
    simpset = simpset addsimps simps addsimprocs simprocs})];
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   240
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   241
end;
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   242
10722
55c8367bab05 rational linear arithmetic
nipkow
parents: 10693
diff changeset
   243
(*
55c8367bab05 rational linear arithmetic
nipkow
parents: 10693
diff changeset
   244
Procedure "assoc_fold" needed?
9436
62bb04ab4b01 rearranged setup of arithmetic procedures, avoiding global reference values;
wenzelm
parents:
diff changeset
   245
*)