src/HOL/Hyperreal/hypreal_arith.ML
author kleing
Wed, 07 Jan 2004 07:52:12 +0100
changeset 14343 6bc647f472b9
parent 14334 6137d24eef79
child 14352 a8b1a44d8264
permissions -rw-r--r--
map_idI
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14309
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
     1
(*  Title:      HOL/Hyperreal/hypreal_arith.ML
10751
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
     2
    ID:         $Id$
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
     3
    Author:     Tobias Nipkow, TU Muenchen
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
     4
    Copyright   1999 TU Muenchen
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
     5
14309
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
     6
Simprocs: Common factor cancellation & Rational coefficient handling
10751
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
     7
*)
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
     8
14309
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
     9
(****Common factor cancellation****)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    10
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    11
local
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    12
  open Hyperreal_Numeral_Simprocs
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    13
in
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    14
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    15
val rel_hypreal_number_of = [eq_hypreal_number_of, less_hypreal_number_of,
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    16
                          le_hypreal_number_of_eq_not_less];
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    17
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    18
structure CancelNumeralFactorCommon =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    19
  struct
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    20
  val mk_coeff          = mk_coeff
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    21
  val dest_coeff        = dest_coeff 1
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    22
  val trans_tac         = Real_Numeral_Simprocs.trans_tac
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    23
  val norm_tac =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    24
     ALLGOALS (simp_tac (HOL_ss addsimps hypreal_minus_from_mult_simps @ mult_1s))
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    25
     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@hypreal_mult_minus_simps))
14331
8dbbb7cf3637 re-organized numeric lemmas
paulson
parents: 14309
diff changeset
    26
     THEN ALLGOALS (simp_tac (HOL_ss addsimps mult_ac))
14309
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    27
  val numeral_simp_tac  =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    28
         ALLGOALS (simp_tac (HOL_ss addsimps rel_hypreal_number_of@bin_simps))
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    29
  val simplify_meta_eq  = simplify_meta_eq
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    30
  end
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    31
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    32
structure DivCancelNumeralFactor = CancelNumeralFactorFun
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    33
 (open CancelNumeralFactorCommon
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    34
  val prove_conv = Bin_Simprocs.prove_conv
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    35
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    36
  val dest_bal = HOLogic.dest_bin "HOL.divide" hyprealT
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    37
  val cancel = mult_divide_cancel_left RS trans
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    38
  val neg_exchanges = false
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    39
)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    40
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    41
structure EqCancelNumeralFactor = CancelNumeralFactorFun
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    42
 (open CancelNumeralFactorCommon
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    43
  val prove_conv = Bin_Simprocs.prove_conv
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    44
  val mk_bal   = HOLogic.mk_eq
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    45
  val dest_bal = HOLogic.dest_bin "op =" hyprealT
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    46
  val cancel = mult_cancel_left RS trans
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    47
  val neg_exchanges = false
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    48
)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    49
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    50
structure LessCancelNumeralFactor = CancelNumeralFactorFun
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    51
 (open CancelNumeralFactorCommon
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    52
  val prove_conv = Bin_Simprocs.prove_conv
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    53
  val mk_bal   = HOLogic.mk_binrel "op <"
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    54
  val dest_bal = HOLogic.dest_bin "op <" hyprealT
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    55
  val cancel = mult_less_cancel_left RS trans
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    56
  val neg_exchanges = true
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    57
)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    58
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    59
structure LeCancelNumeralFactor = CancelNumeralFactorFun
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    60
 (open CancelNumeralFactorCommon
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    61
  val prove_conv = Bin_Simprocs.prove_conv
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    62
  val mk_bal   = HOLogic.mk_binrel "op <="
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    63
  val dest_bal = HOLogic.dest_bin "op <=" hyprealT
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    64
  val cancel = mult_le_cancel_left RS trans
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    65
  val neg_exchanges = true
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    66
)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    67
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    68
val hypreal_cancel_numeral_factors_relations =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    69
  map prep_simproc
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    70
   [("hyprealeq_cancel_numeral_factor",
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    71
     ["(l::hypreal) * m = n", "(l::hypreal) = m * n"],
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    72
     EqCancelNumeralFactor.proc),
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    73
    ("hyprealless_cancel_numeral_factor",
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    74
     ["(l::hypreal) * m < n", "(l::hypreal) < m * n"],
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    75
     LessCancelNumeralFactor.proc),
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    76
    ("hyprealle_cancel_numeral_factor",
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    77
     ["(l::hypreal) * m <= n", "(l::hypreal) <= m * n"],
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    78
     LeCancelNumeralFactor.proc)];
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    79
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    80
val hypreal_cancel_numeral_factors_divide = prep_simproc
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    81
        ("hyprealdiv_cancel_numeral_factor",
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    82
         ["((l::hypreal) * m) / n", "(l::hypreal) / (m * n)",
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    83
          "((number_of v)::hypreal) / (number_of w)"],
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    84
         DivCancelNumeralFactor.proc);
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    85
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    86
val hypreal_cancel_numeral_factors =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    87
    hypreal_cancel_numeral_factors_relations @
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    88
    [hypreal_cancel_numeral_factors_divide];
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    89
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    90
end;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    91
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    92
Addsimprocs hypreal_cancel_numeral_factors;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    93
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    94
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    95
(*examples:
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    96
print_depth 22;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    97
set timing;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    98
set trace_simp;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
    99
fun test s = (Goal s; by (Simp_tac 1));
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   100
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   101
test "0 <= (y::hypreal) * -2";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   102
test "9*x = 12 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   103
test "(9*x) / (12 * (y::hypreal)) = z";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   104
test "9*x < 12 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   105
test "9*x <= 12 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   106
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   107
test "-99*x = 123 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   108
test "(-99*x) / (123 * (y::hypreal)) = z";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   109
test "-99*x < 123 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   110
test "-99*x <= 123 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   111
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   112
test "999*x = -396 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   113
test "(999*x) / (-396 * (y::hypreal)) = z";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   114
test "999*x < -396 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   115
test "999*x <= -396 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   116
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   117
test "-99*x = -81 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   118
test "(-99*x) / (-81 * (y::hypreal)) = z";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   119
test "-99*x <= -81 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   120
test "-99*x < -81 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   121
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   122
test "-2 * x = -1 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   123
test "-2 * x = -(y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   124
test "(-2 * x) / (-1 * (y::hypreal)) = z";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   125
test "-2 * x < -(y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   126
test "-2 * x <= -1 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   127
test "-x < -23 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   128
test "-x <= -23 * (y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   129
*)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   130
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   131
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   132
(** Declarations for ExtractCommonTerm **)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   133
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   134
local
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   135
  open Hyperreal_Numeral_Simprocs
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   136
in
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   137
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   138
structure CancelFactorCommon =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   139
  struct
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   140
  val mk_sum            = long_mk_prod
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   141
  val dest_sum          = dest_prod
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   142
  val mk_coeff          = mk_coeff
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   143
  val dest_coeff        = dest_coeff
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   144
  val find_first        = find_first []
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   145
  val trans_tac         = Real_Numeral_Simprocs.trans_tac
14331
8dbbb7cf3637 re-organized numeric lemmas
paulson
parents: 14309
diff changeset
   146
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@mult_ac))
14309
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   147
  end;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   148
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   149
structure EqCancelFactor = ExtractCommonTermFun
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   150
 (open CancelFactorCommon
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   151
  val prove_conv = Bin_Simprocs.prove_conv
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   152
  val mk_bal   = HOLogic.mk_eq
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   153
  val dest_bal = HOLogic.dest_bin "op =" hyprealT
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   154
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_cancel_left
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   155
);
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   156
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   157
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   158
structure DivideCancelFactor = ExtractCommonTermFun
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   159
 (open CancelFactorCommon
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   160
  val prove_conv = Bin_Simprocs.prove_conv
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   161
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   162
  val dest_bal = HOLogic.dest_bin "HOL.divide" hyprealT
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   163
  val simplify_meta_eq  = cancel_simplify_meta_eq mult_divide_cancel_eq_if
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   164
);
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   165
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   166
val hypreal_cancel_factor =
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   167
  map prep_simproc
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   168
   [("hypreal_eq_cancel_factor", ["(l::hypreal) * m = n", "(l::hypreal) = m * n"],
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   169
     EqCancelFactor.proc),
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   170
    ("hypreal_divide_cancel_factor", ["((l::hypreal) * m) / n", "(l::hypreal) / (m * n)"],
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   171
     DivideCancelFactor.proc)];
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   172
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   173
end;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   174
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   175
Addsimprocs hypreal_cancel_factor;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   176
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   177
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   178
(*examples:
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   179
print_depth 22;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   180
set timing;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   181
set trace_simp;
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   182
fun test s = (Goal s; by (Asm_simp_tac 1));
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   183
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   184
test "x*k = k*(y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   185
test "k = k*(y::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   186
test "a*(b*c) = (b::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   187
test "a*(b*c) = d*(b::hypreal)*(x*a)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   188
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   189
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   190
test "(x*k) / (k*(y::hypreal)) = (uu::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   191
test "(k) / (k*(y::hypreal)) = (uu::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   192
test "(a*(b*c)) / ((b::hypreal)) = (uu::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   193
test "(a*(b*c)) / (d*(b::hypreal)*(x*a)) = (uu::hypreal)";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   194
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   195
(*FIXME: what do we do about this?*)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   196
test "a*(b*c)/(y*z) = d*(b::hypreal)*(x*a)/z";
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   197
*)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   198
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   199
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   200
(****Augmentation of real linear arithmetic with 
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   201
     rational coefficient handling****)
f508492af9b4 moving HyperArith0.ML to other theories
paulson
parents: 14305
diff changeset
   202
10751
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   203
local
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   204
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   205
(* reduce contradictory <= to False *)
14331
8dbbb7cf3637 re-organized numeric lemmas
paulson
parents: 14309
diff changeset
   206
val simps = [True_implies_equals,
8dbbb7cf3637 re-organized numeric lemmas
paulson
parents: 14309
diff changeset
   207
             inst "a" "(number_of ?v)::hypreal" right_distrib,
14305
f17ca9f6dc8c tidying first part of HyperArith0.ML, using generic lemmas
paulson
parents: 10751
diff changeset
   208
             divide_1,times_divide_eq_right,times_divide_eq_left];
10751
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   209
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   210
val simprocs = [hypreal_cancel_numeral_factors_divide];
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   211
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   212
fun cvar(th,_ $ (_ $ _ $ var)) = cterm_of (#sign(rep_thm th)) var;
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   213
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   214
val hypreal_mult_mono_thms =
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   215
 [(rotate_prems 1 hypreal_mult_less_mono2,
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   216
   cvar(hypreal_mult_less_mono2, hd(prems_of hypreal_mult_less_mono2))),
14334
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14331
diff changeset
   217
  (mult_left_mono,
6137d24eef79 tweaking of lemmas in RealDef, RealOrd
paulson
parents: 14331
diff changeset
   218
   cvar(mult_left_mono, hd(tl(prems_of mult_left_mono))))]
10751
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   219
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   220
in
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   221
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   222
val hypreal_arith_setup =
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   223
 [Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} =>
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   224
   {add_mono_thms = add_mono_thms,
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   225
    mult_mono_thms = mult_mono_thms @ hypreal_mult_mono_thms,
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   226
    inj_thms = inj_thms,
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   227
    lessD = lessD,
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   228
    simpset = simpset addsimps simps addsimprocs simprocs})];
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   229
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   230
end;
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   231
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   232
(*
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   233
Procedure "assoc_fold" needed?
a81ea5d3dd41 separation of HOL-Hyperreal from HOL-Real
paulson
parents:
diff changeset
   234
*)