src/HOL/Real/real_arith.ML
author wenzelm
Thu Jan 19 21:22:08 2006 +0100 (2006-01-19 ago)
changeset 18708 4b3dadb4fe33
parent 17876 b9c92f384109
child 20254 58b71535ed00
permissions -rw-r--r--
setup: theory -> theory;
     1 (*  Title:      HOL/Real/real_arith.ML
     2     ID:         $Id$
     3     Author:     Tobias Nipkow, TU Muenchen
     4     Copyright   1999 TU Muenchen
     5 
     6 Simprocs for common factor cancellation & Rational coefficient handling
     7 
     8 Instantiation of the generic linear arithmetic package for type real.
     9 *)
    10 
    11 val real_le_def = thm "real_le_def";
    12 val real_diff_def = thm "real_diff_def";
    13 val real_divide_def = thm "real_divide_def";
    14 
    15 val realrel_in_real = thm"realrel_in_real";
    16 val real_add_commute = thm"real_add_commute";
    17 val real_add_assoc = thm"real_add_assoc";
    18 val real_add_zero_left = thm"real_add_zero_left";
    19 
    20 val real_mult_commute = thm"real_mult_commute";
    21 val real_mult_assoc = thm"real_mult_assoc";
    22 val real_mult_1 = thm"real_mult_1";
    23 val real_mult_1_right = thm"real_mult_1_right";
    24 val preal_le_linear = thm"preal_le_linear";
    25 val real_mult_inverse_left = thm"real_mult_inverse_left";
    26 val real_not_refl2 = thm"real_not_refl2";
    27 val real_of_preal_add = thm"real_of_preal_add";
    28 val real_of_preal_mult = thm"real_of_preal_mult";
    29 val real_of_preal_trichotomy = thm"real_of_preal_trichotomy";
    30 val real_of_preal_minus_less_zero = thm"real_of_preal_minus_less_zero";
    31 val real_of_preal_not_minus_gt_zero = thm"real_of_preal_not_minus_gt_zero";
    32 val real_of_preal_zero_less = thm"real_of_preal_zero_less";
    33 val real_le_imp_less_or_eq = thm"real_le_imp_less_or_eq";
    34 val real_le_refl = thm"real_le_refl";
    35 val real_le_linear = thm"real_le_linear";
    36 val real_le_trans = thm"real_le_trans";
    37 val real_less_le = thm"real_less_le";
    38 val real_less_sum_gt_zero = thm"real_less_sum_gt_zero";
    39 val real_gt_zero_preal_Ex = thm "real_gt_zero_preal_Ex";
    40 val real_gt_preal_preal_Ex = thm "real_gt_preal_preal_Ex";
    41 val real_ge_preal_preal_Ex = thm "real_ge_preal_preal_Ex";
    42 val real_less_all_preal = thm "real_less_all_preal";
    43 val real_less_all_real2 = thm "real_less_all_real2";
    44 val real_of_preal_le_iff = thm "real_of_preal_le_iff";
    45 val real_mult_order = thm "real_mult_order";
    46 val real_add_less_le_mono = thm "real_add_less_le_mono";
    47 val real_add_le_less_mono = thm "real_add_le_less_mono";
    48 val real_add_order = thm "real_add_order";
    49 val real_le_add_order = thm "real_le_add_order";
    50 val real_le_square = thm "real_le_square";
    51 val real_mult_less_mono2 = thm "real_mult_less_mono2";
    52 
    53 val real_mult_less_iff1 = thm "real_mult_less_iff1";
    54 val real_mult_le_cancel_iff1 = thm "real_mult_le_cancel_iff1";
    55 val real_mult_le_cancel_iff2 = thm "real_mult_le_cancel_iff2";
    56 val real_mult_less_mono = thm "real_mult_less_mono";
    57 val real_mult_less_mono' = thm "real_mult_less_mono'";
    58 val real_sum_squares_cancel = thm "real_sum_squares_cancel";
    59 val real_sum_squares_cancel2 = thm "real_sum_squares_cancel2";
    60 
    61 val real_mult_left_cancel = thm"real_mult_left_cancel";
    62 val real_mult_right_cancel = thm"real_mult_right_cancel";
    63 val real_inverse_unique = thm "real_inverse_unique";
    64 val real_inverse_gt_one = thm "real_inverse_gt_one";
    65 
    66 val real_of_int_zero = thm"real_of_int_zero";
    67 val real_of_one = thm"real_of_one";
    68 val real_of_int_add = thm"real_of_int_add";
    69 val real_of_int_minus = thm"real_of_int_minus";
    70 val real_of_int_diff = thm"real_of_int_diff";
    71 val real_of_int_mult = thm"real_of_int_mult";
    72 val real_of_int_real_of_nat = thm"real_of_int_real_of_nat";
    73 val real_of_int_inject = thm"real_of_int_inject";
    74 val real_of_int_less_iff = thm"real_of_int_less_iff";
    75 val real_of_int_le_iff = thm"real_of_int_le_iff";
    76 val real_of_nat_zero = thm "real_of_nat_zero";
    77 val real_of_nat_one = thm "real_of_nat_one";
    78 val real_of_nat_add = thm "real_of_nat_add";
    79 val real_of_nat_Suc = thm "real_of_nat_Suc";
    80 val real_of_nat_less_iff = thm "real_of_nat_less_iff";
    81 val real_of_nat_le_iff = thm "real_of_nat_le_iff";
    82 val real_of_nat_ge_zero = thm "real_of_nat_ge_zero";
    83 val real_of_nat_Suc_gt_zero = thm "real_of_nat_Suc_gt_zero";
    84 val real_of_nat_mult = thm "real_of_nat_mult";
    85 val real_of_nat_inject = thm "real_of_nat_inject";
    86 val real_of_nat_diff = thm "real_of_nat_diff";
    87 val real_of_nat_zero_iff = thm "real_of_nat_zero_iff";
    88 val real_of_nat_gt_zero_cancel_iff = thm "real_of_nat_gt_zero_cancel_iff";
    89 val real_of_nat_le_zero_cancel_iff = thm "real_of_nat_le_zero_cancel_iff";
    90 val not_real_of_nat_less_zero = thm "not_real_of_nat_less_zero";
    91 val real_of_nat_ge_zero_cancel_iff = thm "real_of_nat_ge_zero_cancel_iff";
    92 val real_number_of = thm"real_number_of";
    93 val real_of_nat_number_of = thm"real_of_nat_number_of";
    94 val real_of_int_of_nat_eq = thm"real_of_int_of_nat_eq";
    95 
    96 
    97 (****Instantiation of the generic linear arithmetic package****)
    98 
    99 local
   100 
   101 val simps = [real_of_nat_zero, real_of_nat_Suc, real_of_nat_add, 
   102        real_of_nat_mult, real_of_int_zero, real_of_one, real_of_int_add,
   103        real_of_int_minus, real_of_int_diff,
   104        real_of_int_mult, real_of_int_of_nat_eq,
   105        real_of_nat_number_of, real_number_of];
   106 
   107 val int_inj_thms = [real_of_int_le_iff RS iffD2, real_of_int_less_iff RS iffD2,
   108                     real_of_int_inject RS iffD2];
   109 
   110 val nat_inj_thms = [real_of_nat_le_iff RS iffD2, real_of_nat_less_iff RS iffD2,
   111                     real_of_nat_inject RS iffD2];
   112 
   113 in
   114 
   115 val fast_real_arith_simproc =
   116  Simplifier.simproc (Theory.sign_of (the_context ()))
   117   "fast_real_arith" ["(m::real) < n","(m::real) <= n", "(m::real) = n"]
   118   Fast_Arith.lin_arith_prover;
   119 
   120 val real_arith_setup =
   121   Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} =>
   122    {add_mono_thms = add_mono_thms,
   123     mult_mono_thms = mult_mono_thms,
   124     inj_thms = int_inj_thms @ nat_inj_thms @ inj_thms,
   125     lessD = lessD,  (*Can't change LA_Data_Ref.lessD: the reals are dense!*)
   126     neqE = neqE,
   127     simpset = simpset addsimps simps}) #>
   128   arith_inj_const ("RealDef.real", HOLogic.natT --> HOLogic.realT) #>
   129   arith_inj_const ("RealDef.real", HOLogic.intT --> HOLogic.realT) #>
   130   (fn thy => (change_simpset_of thy (fn ss => ss addsimprocs [fast_real_arith_simproc]); thy));
   131 
   132 (* some thms for injection nat => real:
   133 real_of_nat_zero
   134 real_of_nat_add
   135 *)
   136 
   137 end;
   138 
   139 
   140 (* Some test data [omitting examples that assume the ordering to be discrete!]
   141 Goal "!!a::real. [| a <= b; c <= d; x+y<z |] ==> a+c <= b+d";
   142 by (fast_arith_tac 1);
   143 qed "";
   144 
   145 Goal "!!a::real. [| a <= b; b+b <= c |] ==> a+a <= c";
   146 by (fast_arith_tac 1);
   147 qed "";
   148 
   149 Goal "!!a::real. [| a+b <= i+j; a<=b; i<=j |] ==> a+a <= j+j";
   150 by (fast_arith_tac 1);
   151 qed "";
   152 
   153 Goal "!!a::real. a+b+c <= i+j+k & a<=b & b<=c & i<=j & j<=k --> a+a+a <= k+k+k";
   154 by (arith_tac 1);
   155 qed "";
   156 
   157 Goal "!!a::real. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
   158 \     ==> a <= l";
   159 by (fast_arith_tac 1);
   160 qed "";
   161 
   162 Goal "!!a::real. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
   163 \     ==> a+a+a+a <= l+l+l+l";
   164 by (fast_arith_tac 1);
   165 qed "";
   166 
   167 Goal "!!a::real. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
   168 \     ==> a+a+a+a+a <= l+l+l+l+i";
   169 by (fast_arith_tac 1);
   170 qed "";
   171 
   172 Goal "!!a::real. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
   173 \     ==> a+a+a+a+a+a <= l+l+l+l+i+l";
   174 by (fast_arith_tac 1);
   175 qed "";
   176 
   177 Goal "!!a::real. [| a+b+c+d <= i+j+k+l; a<=b; b<=c; c<=d; i<=j; j<=k; k<=l |] \
   178 \     ==> 6*a <= 5*l+i";
   179 by (fast_arith_tac 1);
   180 qed "";
   181 
   182 Goal "a<=b ==> a < b+(1::real)";
   183 by (fast_arith_tac 1);
   184 qed "";
   185 
   186 Goal "a<=b ==> a-(3::real) < b";
   187 by (fast_arith_tac 1);
   188 qed "";
   189 
   190 Goal "a<=b ==> a-(1::real) < b";
   191 by (fast_arith_tac 1);
   192 qed "";
   193 
   194 *)
   195 
   196 
   197