src/HOL/Real/RealArith0.ML
author berghofe
Fri, 11 Jul 2003 14:55:17 +0200
changeset 14102 8af7334af4b3
parent 13485 acf39e924091
child 14268 5cf13e80be0e
permissions -rw-r--r--
- Installed specific code generator for equality enforcing that arguments do not have function types, which would result in an error message during compilation. - Added test case generators for basic types.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Real/RealArith.ML
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     2
    ID:         $Id$
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     5
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     6
Assorted facts that need binary literals and the arithmetic decision procedure
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     7
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     8
Also, common factor cancellation
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
     9
*)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    10
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    11
Goal "x - - y = x + (y::real)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    12
by (Simp_tac 1);
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    13
qed "real_diff_minus_eq";
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    14
Addsimps [real_diff_minus_eq];
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    15
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    16
(** Division and inverse **)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    17
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    18
Goal "0/x = (0::real)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    19
by (simp_tac (simpset() addsimps [real_divide_def]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    20
qed "real_0_divide";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    21
Addsimps [real_0_divide];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    22
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    23
Goal "((0::real) < inverse x) = (0 < x)";
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    24
by (case_tac "x=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    25
by (asm_simp_tac (HOL_ss addsimps [INVERSE_ZERO]) 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    26
by (auto_tac (claset() addDs [real_inverse_less_0],
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    27
              simpset() addsimps [linorder_neq_iff, real_inverse_gt_0]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    28
qed "real_0_less_inverse_iff";
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
    29
Addsimps [real_0_less_inverse_iff];
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    30
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    31
Goal "(inverse x < (0::real)) = (x < 0)";
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    32
by (case_tac "x=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    33
by (asm_simp_tac (HOL_ss addsimps [INVERSE_ZERO]) 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    34
by (auto_tac (claset() addDs [real_inverse_less_0],
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    35
              simpset() addsimps [linorder_neq_iff, real_inverse_gt_0]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    36
qed "real_inverse_less_0_iff";
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
    37
Addsimps [real_inverse_less_0_iff];
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    38
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    39
Goal "((0::real) <= inverse x) = (0 <= x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    40
by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    41
qed "real_0_le_inverse_iff";
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
    42
Addsimps [real_0_le_inverse_iff];
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    43
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    44
Goal "(inverse x <= (0::real)) = (x <= 0)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    45
by (simp_tac (simpset() addsimps [linorder_not_less RS sym]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    46
qed "real_inverse_le_0_iff";
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
    47
Addsimps [real_inverse_le_0_iff];
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    48
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    49
Goalw [real_divide_def] "x/(0::real) = 0";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    50
by (stac INVERSE_ZERO 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    51
by (Simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    52
qed "REAL_DIVIDE_ZERO";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    53
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    54
Goal "inverse (x::real) = 1/x";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    55
by (simp_tac (simpset() addsimps [real_divide_def]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    56
qed "real_inverse_eq_divide";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    57
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    58
Goal "((0::real) < x/y) = (0 < x & 0 < y | x < 0 & y < 0)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    59
by (simp_tac (simpset() addsimps [real_divide_def, real_0_less_mult_iff]) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    60
qed "real_0_less_divide_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    61
Addsimps [inst "x" "number_of ?w" real_0_less_divide_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    62
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    63
Goal "(x/y < (0::real)) = (0 < x & y < 0 | x < 0 & 0 < y)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    64
by (simp_tac (simpset() addsimps [real_divide_def, real_mult_less_0_iff]) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    65
qed "real_divide_less_0_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    66
Addsimps [inst "x" "number_of ?w" real_divide_less_0_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    67
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    68
Goal "((0::real) <= x/y) = ((x <= 0 | 0 <= y) & (0 <= x | y <= 0))";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    69
by (simp_tac (simpset() addsimps [real_divide_def, real_0_le_mult_iff]) 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    70
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    71
qed "real_0_le_divide_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    72
Addsimps [inst "x" "number_of ?w" real_0_le_divide_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    73
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    74
Goal "(x/y <= (0::real)) = ((x <= 0 | y <= 0) & (0 <= x | 0 <= y))";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    75
by (simp_tac (simpset() addsimps [real_divide_def, real_mult_le_0_iff]) 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    76
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    77
qed "real_divide_le_0_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    78
Addsimps [inst "x" "number_of ?w" real_divide_le_0_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    79
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    80
Goal "(inverse(x::real) = 0) = (x = 0)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    81
by (auto_tac (claset(), simpset() addsimps [INVERSE_ZERO]));
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    82
by (rtac ccontr 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    83
by (blast_tac (claset() addDs [real_inverse_not_zero]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    84
qed "real_inverse_zero_iff";
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
    85
Addsimps [real_inverse_zero_iff];
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    86
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    87
Goal "(x/y = 0) = (x=0 | y=(0::real))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    88
by (auto_tac (claset(), simpset() addsimps [real_divide_def]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    89
qed "real_divide_eq_0_iff";
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
    90
Addsimps [real_divide_eq_0_iff];
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    91
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
    92
Goal "h ~= (0::real) ==> h/h = 1";
10778
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
    93
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_inv_left]) 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
    94
qed "real_divide_self_eq";
10778
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
    95
Addsimps [real_divide_self_eq];
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
    96
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    97
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    98
(**** Factor cancellation theorems for "real" ****)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
    99
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   100
(** Cancellation laws for k*m < k*n and m*k < n*k, also for <= and =,
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   101
    but not (yet?) for k*m < n*k. **)
12483
0a01efff43e9 new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents: 12018
diff changeset
   102
(* unused?? bind_thm ("real_mult_minus_right", real_minus_mult_eq2 RS sym); *)
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   103
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   104
Goal "(-y < -x) = ((x::real) < y)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   105
by (arith_tac 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   106
qed "real_minus_less_minus";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   107
Addsimps [real_minus_less_minus];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   108
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   109
Goal "[| i<j;  k < (0::real) |] ==> j*k < i*k";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   110
by (rtac (real_minus_less_minus RS iffD1) 1);
12483
0a01efff43e9 new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents: 12018
diff changeset
   111
by (auto_tac (claset(),
0a01efff43e9 new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents: 12018
diff changeset
   112
              simpset() delsimps [real_mult_minus_eq2]
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   113
                        addsimps [real_minus_mult_eq2]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   114
qed "real_mult_less_mono1_neg";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   115
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   116
Goal "[| i<j;  k < (0::real) |] ==> k*j < k*i";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   117
by (rtac (real_minus_less_minus RS iffD1) 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   118
by (auto_tac (claset(),
12483
0a01efff43e9 new rewrite rules for use by arith_tac to take care of uminus.
nipkow
parents: 12018
diff changeset
   119
              simpset() delsimps [real_mult_minus_eq1]
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   120
                        addsimps [real_minus_mult_eq1]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   121
qed "real_mult_less_mono2_neg";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   122
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   123
Goal "[| i <= j;  k <= (0::real) |] ==> j*k <= i*k";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   124
by (auto_tac (claset(),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   125
              simpset() addsimps [order_le_less, real_mult_less_mono1_neg]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   126
qed "real_mult_le_mono1_neg";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   127
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   128
Goal "[| i <= j;  k <= (0::real) |] ==> k*j <= k*i";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   129
by (dtac real_mult_le_mono1_neg 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   130
by (ALLGOALS (asm_full_simp_tac (simpset() addsimps [real_mult_commute])));
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   131
qed "real_mult_le_mono2_neg";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   132
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   133
Goal "(m*k < n*k) = (((0::real) < k & m<n) | (k < 0 & n<m))";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   134
by (case_tac "k = (0::real)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   135
by (auto_tac (claset(),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   136
              simpset() addsimps [linorder_neq_iff,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   137
                          real_mult_less_mono1, real_mult_less_mono1_neg]));
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   138
by (auto_tac (claset(),
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   139
              simpset() addsimps [linorder_not_less,
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   140
                                  inst "y1" "m*k" (linorder_not_le RS sym),
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   141
                                  inst "y1" "m" (linorder_not_le RS sym)]));
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   142
by (TRYALL (etac notE));
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   143
by (auto_tac (claset(),
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   144
              simpset() addsimps [order_less_imp_le, real_mult_le_mono1,
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   145
                                            real_mult_le_mono1_neg]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   146
qed "real_mult_less_cancel2";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   147
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   148
Goal "(m*k <= n*k) = (((0::real) < k --> m<=n) & (k < 0 --> n<=m))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   149
by (simp_tac (simpset() addsimps [linorder_not_less RS sym,
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   150
                                  real_mult_less_cancel2]) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   151
qed "real_mult_le_cancel2";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   152
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   153
Goal "(k*m < k*n) = (((0::real) < k & m<n) | (k < 0 & n<m))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   154
by (simp_tac (simpset() addsimps [inst "z" "k" real_mult_commute,
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   155
                                  real_mult_less_cancel2]) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   156
qed "real_mult_less_cancel1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   157
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   158
Goal "!!k::real. (k*m <= k*n) = ((0 < k --> m<=n) & (k < 0 --> n<=m))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   159
by (simp_tac (simpset() addsimps [linorder_not_less RS sym,
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   160
                                  real_mult_less_cancel1]) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   161
qed "real_mult_le_cancel1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   162
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   163
Goal "!!k::real. (k*m = k*n) = (k = 0 | m=n)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   164
by (case_tac "k=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   165
by (auto_tac (claset(), simpset() addsimps [real_mult_left_cancel]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   166
qed "real_mult_eq_cancel1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   167
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   168
Goal "!!k::real. (m*k = n*k) = (k = 0 | m=n)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   169
by (case_tac "k=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   170
by (auto_tac (claset(), simpset() addsimps [real_mult_right_cancel]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   171
qed "real_mult_eq_cancel2";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   172
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   173
Goal "!!k::real. k~=0 ==> (k*m) / (k*n) = (m/n)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   174
by (asm_simp_tac
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   175
    (simpset() addsimps [real_divide_def, real_inverse_distrib]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   176
by (subgoal_tac "k * m * (inverse k * inverse n) = \
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   177
\                (k * inverse k) * (m * inverse n)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   178
by (asm_full_simp_tac (simpset() addsimps []) 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   179
by (asm_full_simp_tac (HOL_ss addsimps real_mult_ac) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   180
qed "real_mult_div_cancel1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   181
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   182
(*For ExtractCommonTerm*)
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   183
Goal "(k*m) / (k*n) = (if k = (0::real) then 0 else m/n)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   184
by (simp_tac (simpset() addsimps [real_mult_div_cancel1]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   185
qed "real_mult_div_cancel_disj";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   186
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   187
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   188
local
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   189
  open Real_Numeral_Simprocs
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   190
in
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   191
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   192
val rel_real_number_of = [eq_real_number_of, less_real_number_of,
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   193
                          le_real_number_of_eq_not_less]
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   194
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   195
structure CancelNumeralFactorCommon =
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   196
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   197
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   198
  val dest_coeff        = dest_coeff 1
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   199
  val trans_tac         = trans_tac
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   200
  val norm_tac =
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   201
     ALLGOALS (simp_tac (HOL_ss addsimps real_minus_from_mult_simps @ mult_1s))
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   202
     THEN ALLGOALS (simp_tac (HOL_ss addsimps bin_simps@real_mult_minus_simps))
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   203
     THEN ALLGOALS (simp_tac (HOL_ss addsimps real_mult_ac))
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   204
  val numeral_simp_tac  =
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   205
         ALLGOALS (simp_tac (HOL_ss addsimps rel_real_number_of@bin_simps))
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   206
  val simplify_meta_eq  = simplify_meta_eq
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   207
  end
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   208
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   209
structure DivCancelNumeralFactor = CancelNumeralFactorFun
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   210
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   211
  val prove_conv = Bin_Simprocs.prove_conv
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   212
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   213
  val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   214
  val cancel = real_mult_div_cancel1 RS trans
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   215
  val neg_exchanges = false
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   216
)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   217
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   218
structure EqCancelNumeralFactor = CancelNumeralFactorFun
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   219
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   220
  val prove_conv = Bin_Simprocs.prove_conv
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   221
  val mk_bal   = HOLogic.mk_eq
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   222
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   223
  val cancel = real_mult_eq_cancel1 RS trans
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   224
  val neg_exchanges = false
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   225
)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   226
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   227
structure LessCancelNumeralFactor = CancelNumeralFactorFun
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   228
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   229
  val prove_conv = Bin_Simprocs.prove_conv
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   230
  val mk_bal   = HOLogic.mk_binrel "op <"
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   231
  val dest_bal = HOLogic.dest_bin "op <" HOLogic.realT
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   232
  val cancel = real_mult_less_cancel1 RS trans
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   233
  val neg_exchanges = true
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   234
)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   235
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   236
structure LeCancelNumeralFactor = CancelNumeralFactorFun
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   237
 (open CancelNumeralFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   238
  val prove_conv = Bin_Simprocs.prove_conv
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   239
  val mk_bal   = HOLogic.mk_binrel "op <="
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   240
  val dest_bal = HOLogic.dest_bin "op <=" HOLogic.realT
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   241
  val cancel = real_mult_le_cancel1 RS trans
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   242
  val neg_exchanges = true
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   243
)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   244
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   245
val real_cancel_numeral_factors_relations =
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   246
  map prep_simproc
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   247
   [("realeq_cancel_numeral_factor",
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   248
     ["(l::real) * m = n", "(l::real) = m * n"],
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   249
     EqCancelNumeralFactor.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   250
    ("realless_cancel_numeral_factor",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   251
     ["(l::real) * m < n", "(l::real) < m * n"],
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   252
     LessCancelNumeralFactor.proc),
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   253
    ("realle_cancel_numeral_factor",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   254
     ["(l::real) * m <= n", "(l::real) <= m * n"],
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   255
     LeCancelNumeralFactor.proc)]
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
   256
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
   257
val real_cancel_numeral_factors_divide = prep_simproc
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   258
        ("realdiv_cancel_numeral_factor",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   259
         ["((l::real) * m) / n", "(l::real) / (m * n)",
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   260
          "((number_of v)::real) / (number_of w)"],
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   261
         DivCancelNumeralFactor.proc)
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
   262
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   263
val real_cancel_numeral_factors =
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   264
    real_cancel_numeral_factors_relations @
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   265
    [real_cancel_numeral_factors_divide]
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   266
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   267
end;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   268
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   269
Addsimprocs real_cancel_numeral_factors;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   270
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   271
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   272
(*examples:
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   273
print_depth 22;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   274
set timing;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   275
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   276
fun test s = (Goal s; by (Simp_tac 1));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   277
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   278
test "0 <= (y::real) * -2";
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   279
test "9*x = 12 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   280
test "(9*x) / (12 * (y::real)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   281
test "9*x < 12 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   282
test "9*x <= 12 * (y::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   283
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   284
test "-99*x = 132 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   285
test "(-99*x) / (132 * (y::real)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   286
test "-99*x < 132 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   287
test "-99*x <= 132 * (y::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   288
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   289
test "999*x = -396 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   290
test "(999*x) / (-396 * (y::real)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   291
test "999*x < -396 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   292
test "999*x <= -396 * (y::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   293
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   294
test  "(- ((2::real) * x) <= 2 * y)";
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   295
test "-99*x = -81 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   296
test "(-99*x) / (-81 * (y::real)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   297
test "-99*x <= -81 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   298
test "-99*x < -81 * (y::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   299
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   300
test "-2 * x = -1 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   301
test "-2 * x = -(y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   302
test "(-2 * x) / (-1 * (y::real)) = z";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   303
test "-2 * x < -(y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   304
test "-2 * x <= -1 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   305
test "-x < -23 * (y::real)";
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   306
test "-x <= -23 * (y::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   307
*)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   308
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   309
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   310
(** Declarations for ExtractCommonTerm **)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   311
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   312
local
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   313
  open Real_Numeral_Simprocs
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   314
in
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   315
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   316
structure CancelFactorCommon =
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   317
  struct
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   318
  val mk_sum            = long_mk_prod
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   319
  val dest_sum          = dest_prod
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   320
  val mk_coeff          = mk_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   321
  val dest_coeff        = dest_coeff
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   322
  val find_first        = find_first []
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   323
  val trans_tac         = trans_tac
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   324
  val norm_tac = ALLGOALS (simp_tac (HOL_ss addsimps mult_1s@real_mult_ac))
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   325
  end;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   326
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   327
structure EqCancelFactor = ExtractCommonTermFun
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   328
 (open CancelFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   329
  val prove_conv = Bin_Simprocs.prove_conv
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   330
  val mk_bal   = HOLogic.mk_eq
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   331
  val dest_bal = HOLogic.dest_bin "op =" HOLogic.realT
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   332
  val simplify_meta_eq  = cancel_simplify_meta_eq real_mult_eq_cancel1
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   333
);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   334
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   335
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   336
structure DivideCancelFactor = ExtractCommonTermFun
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   337
 (open CancelFactorCommon
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   338
  val prove_conv = Bin_Simprocs.prove_conv
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   339
  val mk_bal   = HOLogic.mk_binop "HOL.divide"
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   340
  val dest_bal = HOLogic.dest_bin "HOL.divide" HOLogic.realT
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   341
  val simplify_meta_eq  = cancel_simplify_meta_eq real_mult_div_cancel_disj
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   342
);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   343
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   344
val real_cancel_factor =
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   345
  map prep_simproc
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   346
   [("real_eq_cancel_factor", ["(l::real) * m = n", "(l::real) = m * n"], EqCancelFactor.proc),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   347
    ("real_divide_cancel_factor", ["((l::real) * m) / n", "(l::real) / (m * n)"],
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   348
     DivideCancelFactor.proc)];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   349
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   350
end;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   351
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   352
Addsimprocs real_cancel_factor;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   353
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   354
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   355
(*examples:
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   356
print_depth 22;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   357
set timing;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   358
set trace_simp;
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   359
fun test s = (Goal s; by (Asm_simp_tac 1));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   360
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   361
test "x*k = k*(y::real)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   362
test "k = k*(y::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   363
test "a*(b*c) = (b::real)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   364
test "a*(b*c) = d*(b::real)*(x*a)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   365
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   366
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   367
test "(x*k) / (k*(y::real)) = (uu::real)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   368
test "(k) / (k*(y::real)) = (uu::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   369
test "(a*(b*c)) / ((b::real)) = (uu::real)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   370
test "(a*(b*c)) / (d*(b::real)*(x*a)) = (uu::real)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   371
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   372
(*FIXME: what do we do about this?*)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   373
test "a*(b*c)/(y*z) = d*(b::real)*(x*a)/z";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   374
*)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   375
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   376
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   377
(*** Simplification of inequalities involving literal divisors ***)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   378
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   379
Goal "0<z ==> ((x::real) <= y/z) = (x*z <= y)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   380
by (subgoal_tac "(x*z <= y) = (x*z <= (y/z)*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   381
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   382
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   383
by (stac real_mult_le_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   384
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   385
qed "pos_real_le_divide_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   386
Addsimps [inst "z" "number_of ?w" pos_real_le_divide_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   387
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   388
Goal "z<0 ==> ((x::real) <= y/z) = (y <= x*z)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   389
by (subgoal_tac "(y <= x*z) = ((y/z)*z <= x*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   390
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   391
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   392
by (stac real_mult_le_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   393
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   394
qed "neg_real_le_divide_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   395
Addsimps [inst "z" "number_of ?w" neg_real_le_divide_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   396
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   397
Goal "0<z ==> (y/z <= (x::real)) = (y <= x*z)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   398
by (subgoal_tac "(y <= x*z) = ((y/z)*z <= x*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   399
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   400
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   401
by (stac real_mult_le_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   402
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   403
qed "pos_real_divide_le_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   404
Addsimps [inst "z" "number_of ?w" pos_real_divide_le_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   405
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   406
Goal "z<0 ==> (y/z <= (x::real)) = (x*z <= y)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   407
by (subgoal_tac "(x*z <= y) = (x*z <= (y/z)*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   408
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   409
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   410
by (stac real_mult_le_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   411
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   412
qed "neg_real_divide_le_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   413
Addsimps [inst "z" "number_of ?w" neg_real_divide_le_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   414
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   415
Goal "0<z ==> ((x::real) < y/z) = (x*z < y)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   416
by (subgoal_tac "(x*z < y) = (x*z < (y/z)*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   417
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   418
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   419
by (stac real_mult_less_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   420
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   421
qed "pos_real_less_divide_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   422
Addsimps [inst "z" "number_of ?w" pos_real_less_divide_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   423
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   424
Goal "z<0 ==> ((x::real) < y/z) = (y < x*z)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   425
by (subgoal_tac "(y < x*z) = ((y/z)*z < x*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   426
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   427
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   428
by (stac real_mult_less_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   429
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   430
qed "neg_real_less_divide_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   431
Addsimps [inst "z" "number_of ?w" neg_real_less_divide_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   432
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   433
Goal "0<z ==> (y/z < (x::real)) = (y < x*z)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   434
by (subgoal_tac "(y < x*z) = ((y/z)*z < x*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   435
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   436
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   437
by (stac real_mult_less_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   438
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   439
qed "pos_real_divide_less_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   440
Addsimps [inst "z" "number_of ?w" pos_real_divide_less_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   441
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   442
Goal "z<0 ==> (y/z < (x::real)) = (x*z < y)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   443
by (subgoal_tac "(x*z < y) = (x*z < (y/z)*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   444
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   445
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   446
by (stac real_mult_less_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   447
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   448
qed "neg_real_divide_less_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   449
Addsimps [inst "z" "number_of ?w" neg_real_divide_less_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   450
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   451
Goal "z~=0 ==> ((x::real) = y/z) = (x*z = y)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   452
by (subgoal_tac "(x*z = y) = (x*z = (y/z)*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   453
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   454
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   455
by (stac real_mult_eq_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   456
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   457
qed "real_eq_divide_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   458
Addsimps [inst "z" "number_of ?w" real_eq_divide_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   459
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   460
Goal "z~=0 ==> (y/z = (x::real)) = (y = x*z)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   461
by (subgoal_tac "(y = x*z) = ((y/z)*z = x*z)" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   462
by (asm_simp_tac (simpset() addsimps [real_divide_def, real_mult_assoc]) 2);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   463
by (etac ssubst 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   464
by (stac real_mult_eq_cancel2 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   465
by (Asm_simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   466
qed "real_divide_eq_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   467
Addsimps [inst "z" "number_of ?w" real_divide_eq_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   468
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   469
Goal "(m/k = n/k) = (k = 0 | m = (n::real))";
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   470
by (case_tac "k=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   471
by (asm_simp_tac (simpset() addsimps [REAL_DIVIDE_ZERO]) 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   472
by (asm_simp_tac (simpset() addsimps [real_divide_eq_eq, real_eq_divide_eq,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   473
                                      real_mult_eq_cancel2]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   474
qed "real_divide_eq_cancel2";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   475
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   476
Goal "(k/m = k/n) = (k = 0 | m = (n::real))";
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   477
by (case_tac "m=0 | n = 0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   478
by (auto_tac (claset(),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   479
              simpset() addsimps [REAL_DIVIDE_ZERO, real_divide_eq_eq,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   480
                                  real_eq_divide_eq, real_mult_eq_cancel1]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   481
qed "real_divide_eq_cancel1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   482
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   483
(*Moved from RealOrd.ML to use 0 *)
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   484
Goal "[| 0 < r; 0 < x|] ==> (inverse x < inverse (r::real)) = (r < x)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   485
by (auto_tac (claset() addIs [real_inverse_less_swap], simpset()));
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   486
by (res_inst_tac [("t","r")] (real_inverse_inverse RS subst) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   487
by (res_inst_tac [("t","x")] (real_inverse_inverse RS subst) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   488
by (auto_tac (claset() addIs [real_inverse_less_swap],
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   489
              simpset() delsimps [real_inverse_inverse]
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   490
                        addsimps [real_inverse_gt_0]));
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   491
qed "real_inverse_less_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   492
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   493
Goal "[| 0 < r; 0 < x|] ==> (inverse x <= inverse r) = (r <= (x::real))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   494
by (asm_simp_tac (simpset() addsimps [linorder_not_less RS sym,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   495
                                      real_inverse_less_iff]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   496
qed "real_inverse_le_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   497
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   498
(** Division by 1, -1 **)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   499
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   500
Goal "(x::real)/1 = x";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   501
by (simp_tac (simpset() addsimps [real_divide_def]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   502
qed "real_divide_1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   503
Addsimps [real_divide_1];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   504
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   505
Goal "x/-1 = -(x::real)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   506
by (Simp_tac 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   507
qed "real_divide_minus1";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   508
Addsimps [real_divide_minus1];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   509
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   510
Goal "-1/(x::real) = - (1/x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   511
by (simp_tac (simpset() addsimps [real_divide_def, real_minus_inverse]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   512
qed "real_minus1_divide";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   513
Addsimps [real_minus1_divide];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   514
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   515
Goal "[| (0::real) < d1; 0 < d2 |] ==> EX e. 0 < e & e < d1 & e < d2";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   516
by (res_inst_tac [("x","(min d1 d2)/2")] exI 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   517
by (asm_simp_tac (simpset() addsimps [min_def]) 1);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   518
qed "real_lbound_gt_zero";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   519
10778
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   520
Goal "(inverse x = inverse y) = (x = (y::real))";
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   521
by (case_tac "x=0 | y=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   522
by (auto_tac (claset(),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   523
              simpset() addsimps [real_inverse_eq_divide,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   524
                                  DIVISION_BY_ZERO]));
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   525
by (dres_inst_tac [("f","%u. x*y*u")] arg_cong 1);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   526
by (Asm_full_simp_tac 1);
10778
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   527
qed "real_inverse_eq_iff";
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   528
Addsimps [real_inverse_eq_iff];
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   529
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   530
Goal "(z/x = z/y) = (z = 0 | x = (y::real))";
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   531
by (case_tac "x=0 | y=0" 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   532
by (auto_tac (claset(),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   533
              simpset() addsimps [DIVISION_BY_ZERO]));
10778
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   534
by (dres_inst_tac [("f","%u. x*y*u")] arg_cong 1);
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   535
by Auto_tac;
10778
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   536
qed "real_divide_eq_iff";
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   537
Addsimps [real_divide_eq_iff];
2c6605049646 more tidying, especially to remove real_of_posnat
paulson
parents: 10752
diff changeset
   538
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   539
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   540
(*** General rewrites to improve automation, like those for type "int" ***)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   541
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   542
(** The next several equations can make the simplifier loop! **)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   543
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   544
Goal "(x < - y) = (y < - (x::real))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   545
by Auto_tac;
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   546
qed "real_less_minus";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   547
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   548
Goal "(- x < y) = (- y < (x::real))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   549
by Auto_tac;
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   550
qed "real_minus_less";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   551
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   552
Goal "(x <= - y) = (y <= - (x::real))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   553
by Auto_tac;
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   554
qed "real_le_minus";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   555
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   556
Goal "(- x <= y) = (- y <= (x::real))";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   557
by Auto_tac;
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   558
qed "real_minus_le";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   559
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   560
Goal "(x = - y) = (y = - (x::real))";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   561
by Auto_tac;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   562
qed "real_equation_minus";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   563
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   564
Goal "(- x = y) = (- (y::real) = x)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   565
by Auto_tac;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   566
qed "real_minus_equation";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   567
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   568
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   569
Goal "(x + - a = (0::real)) = (x=a)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   570
by (arith_tac 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   571
qed "real_add_minus_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   572
Addsimps [real_add_minus_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   573
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   574
Goal "(-b = -a) = (b = (a::real))";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   575
by (arith_tac 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   576
qed "real_minus_eq_cancel";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   577
Addsimps [real_minus_eq_cancel];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   578
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   579
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   580
(*Distributive laws for literals*)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   581
Addsimps (map (inst "w" "number_of ?v")
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   582
          [real_add_mult_distrib, real_add_mult_distrib2,
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   583
           real_diff_mult_distrib, real_diff_mult_distrib2]);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   584
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   585
Addsimps (map (inst "x" "number_of ?v")
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   586
          [real_less_minus, real_le_minus, real_equation_minus]);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   587
Addsimps (map (inst "y" "number_of ?v")
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   588
          [real_minus_less, real_minus_le, real_minus_equation]);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   589
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   590
(*Equations and inequations involving 1*)
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   591
Addsimps (map (simplify (simpset()) o inst "x" "1")
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   592
          [real_less_minus, real_le_minus, real_equation_minus]);
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   593
Addsimps (map (simplify (simpset()) o inst "y" "1")
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   594
          [real_minus_less, real_minus_le, real_minus_equation]);
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   595
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   596
(*** Simprules combining x+y and 0 ***)
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   597
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   598
Goal "(x+y = (0::real)) = (y = -x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   599
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   600
qed "real_add_eq_0_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   601
AddIffs [real_add_eq_0_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   602
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   603
Goal "(x+y < (0::real)) = (y < -x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   604
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   605
qed "real_add_less_0_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   606
AddIffs [real_add_less_0_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   607
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   608
Goal "((0::real) < x+y) = (-x < y)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   609
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   610
qed "real_0_less_add_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   611
AddIffs [real_0_less_add_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   612
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   613
Goal "(x+y <= (0::real)) = (y <= -x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   614
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   615
qed "real_add_le_0_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   616
AddIffs [real_add_le_0_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   617
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   618
Goal "((0::real) <= x+y) = (-x <= y)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   619
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   620
qed "real_0_le_add_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   621
AddIffs [real_0_le_add_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   622
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   623
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   624
(** Simprules combining x-y and 0; see also real_less_iff_diff_less_0, etc.,
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   625
    in RealBin
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   626
**)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   627
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   628
Goal "((0::real) < x-y) = (y < x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   629
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   630
qed "real_0_less_diff_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   631
AddIffs [real_0_less_diff_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   632
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   633
Goal "((0::real) <= x-y) = (y <= x)";
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 12483
diff changeset
   634
by Auto_tac;
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   635
qed "real_0_le_diff_iff";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   636
AddIffs [real_0_le_diff_iff];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   637
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   638
(*
10752
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
   639
FIXME: we should have this, as for type int, but many proofs would break.
c4f1bf2acf4c tidying, and separation of HOL-Hyperreal from HOL-Real
paulson
parents: 10722
diff changeset
   640
It replaces x+-y by x-y.
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   641
Addsimps [symmetric real_diff_def];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   642
*)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   643
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   644
Goal "-(x-y) = y - (x::real)";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   645
by (arith_tac 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   646
qed "real_minus_diff_eq";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   647
Addsimps [real_minus_diff_eq];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   648
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   649
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   650
(*** Density of the Reals ***)
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   651
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   652
Goal "x < y ==> x < (x+y) / (2::real)";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   653
by Auto_tac;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   654
qed "real_less_half_sum";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   655
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   656
Goal "x < y ==> (x+y)/(2::real) < y";
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   657
by Auto_tac;
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   658
qed "real_gt_half_sum";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   659
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   660
Goal "x < y ==> EX r::real. x < r & r < y";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   661
by (blast_tac (claset() addSIs [real_less_half_sum, real_gt_half_sum]) 1);
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   662
qed "real_dense";
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   663
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   664
12018
ec054019c910 Numerals and simprocs for types real and hypreal. The abstract
paulson
parents: 11704
diff changeset
   665
(*Replaces "inverse #nn" by 1/#nn *)
10722
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   666
Addsimps [inst "x" "number_of ?w" real_inverse_eq_divide];
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   667
55c8367bab05 rational linear arithmetic
nipkow
parents:
diff changeset
   668