src/HOL/Ring_and_Field.thy
author obua
Tue Apr 19 10:59:31 2005 +0200 (2005-04-19)
changeset 15769 38c8ea8521e7
parent 15580 900291ee0af8
child 15923 01d5d0c1c078
permissions -rw-r--r--
Removed mult_commute axiom from comm_semiring axclass.
paulson@14265
     1
(*  Title:   HOL/Ring_and_Field.thy
paulson@14265
     2
    ID:      $Id$
wenzelm@14770
     3
    Author:  Gertrud Bauer, Steven Obua, Lawrence C Paulson and Markus Wenzel
paulson@14265
     4
*)
paulson@14265
     5
obua@14738
     6
header {* (Ordered) Rings and Fields *}
paulson@14265
     7
paulson@15229
     8
theory Ring_and_Field
nipkow@15140
     9
imports OrderedGroup
nipkow@15131
    10
begin
paulson@14504
    11
obua@14738
    12
text {*
obua@14738
    13
  The theory of partially ordered rings is taken from the books:
obua@14738
    14
  \begin{itemize}
obua@14738
    15
  \item \emph{Lattice Theory} by Garret Birkhoff, American Mathematical Society 1979 
obua@14738
    16
  \item \emph{Partially Ordered Algebraic Systems}, Pergamon Press 1963
obua@14738
    17
  \end{itemize}
obua@14738
    18
  Most of the used notions can also be looked up in 
obua@14738
    19
  \begin{itemize}
wenzelm@14770
    20
  \item \url{http://www.mathworld.com} by Eric Weisstein et. al.
obua@14738
    21
  \item \emph{Algebra I} by van der Waerden, Springer.
obua@14738
    22
  \end{itemize}
obua@14738
    23
*}
paulson@14504
    24
obua@14738
    25
axclass semiring \<subseteq> ab_semigroup_add, semigroup_mult
obua@14738
    26
  left_distrib: "(a + b) * c = a * c + b * c"
obua@14738
    27
  right_distrib: "a * (b + c) = a * b + a * c"
paulson@14504
    28
obua@14738
    29
axclass semiring_0 \<subseteq> semiring, comm_monoid_add
paulson@14504
    30
obua@14940
    31
axclass semiring_0_cancel \<subseteq> semiring_0, cancel_ab_semigroup_add
obua@14940
    32
obua@14738
    33
axclass comm_semiring \<subseteq> ab_semigroup_add, ab_semigroup_mult  
obua@14738
    34
  distrib: "(a + b) * c = a * c + b * c"
paulson@14504
    35
obua@14738
    36
instance comm_semiring \<subseteq> semiring
obua@14738
    37
proof
obua@14738
    38
  fix a b c :: 'a
obua@14738
    39
  show "(a + b) * c = a * c + b * c" by (simp add: distrib)
obua@14738
    40
  have "a * (b + c) = (b + c) * a" by (simp add: mult_ac)
obua@14738
    41
  also have "... = b * a + c * a" by (simp only: distrib)
obua@14738
    42
  also have "... = a * b + a * c" by (simp add: mult_ac)
obua@14738
    43
  finally show "a * (b + c) = a * b + a * c" by blast
paulson@14504
    44
qed
paulson@14504
    45
obua@14738
    46
axclass comm_semiring_0 \<subseteq> comm_semiring, comm_monoid_add
paulson@14504
    47
obua@14738
    48
instance comm_semiring_0 \<subseteq> semiring_0 ..
paulson@14504
    49
obua@14940
    50
axclass comm_semiring_0_cancel \<subseteq> comm_semiring_0, cancel_ab_semigroup_add
obua@14940
    51
obua@14940
    52
instance comm_semiring_0_cancel \<subseteq> semiring_0_cancel ..
obua@14940
    53
obua@14738
    54
axclass axclass_0_neq_1 \<subseteq> zero, one
paulson@14265
    55
  zero_neq_one [simp]: "0 \<noteq> 1"
paulson@14265
    56
obua@14738
    57
axclass semiring_1 \<subseteq> axclass_0_neq_1, semiring_0, monoid_mult
paulson@14504
    58
obua@14738
    59
axclass comm_semiring_1 \<subseteq> axclass_0_neq_1, comm_semiring_0, comm_monoid_mult (* previously almost_semiring *)
obua@14738
    60
obua@14738
    61
instance comm_semiring_1 \<subseteq> semiring_1 ..
paulson@14421
    62
obua@14738
    63
axclass axclass_no_zero_divisors \<subseteq> zero, times
obua@14738
    64
  no_zero_divisors: "a \<noteq> 0 \<Longrightarrow> b \<noteq> 0 \<Longrightarrow> a * b \<noteq> 0"
paulson@14504
    65
obua@14940
    66
axclass semiring_1_cancel \<subseteq> semiring_1, cancel_ab_semigroup_add
obua@14940
    67
obua@14940
    68
instance semiring_1_cancel \<subseteq> semiring_0_cancel ..
obua@14940
    69
obua@14738
    70
axclass comm_semiring_1_cancel \<subseteq> comm_semiring_1, cancel_ab_semigroup_add (* previously semiring *)
obua@14738
    71
obua@14940
    72
instance comm_semiring_1_cancel \<subseteq> semiring_1_cancel ..
obua@14940
    73
obua@14940
    74
instance comm_semiring_1_cancel \<subseteq> comm_semiring_0_cancel ..
obua@14940
    75
obua@14738
    76
axclass ring \<subseteq> semiring, ab_group_add
obua@14738
    77
obua@14940
    78
instance ring \<subseteq> semiring_0_cancel ..
paulson@14504
    79
obua@14738
    80
axclass comm_ring \<subseteq> comm_semiring_0, ab_group_add
obua@14738
    81
obua@14738
    82
instance comm_ring \<subseteq> ring ..
paulson@14504
    83
obua@14940
    84
instance comm_ring \<subseteq> comm_semiring_0_cancel ..
obua@14738
    85
obua@14738
    86
axclass ring_1 \<subseteq> ring, semiring_1
paulson@14265
    87
obua@14940
    88
instance ring_1 \<subseteq> semiring_1_cancel ..
obua@14940
    89
obua@14738
    90
axclass comm_ring_1 \<subseteq> comm_ring, comm_semiring_1 (* previously ring *)
obua@14738
    91
obua@14738
    92
instance comm_ring_1 \<subseteq> ring_1 ..
paulson@14421
    93
obua@14738
    94
instance comm_ring_1 \<subseteq> comm_semiring_1_cancel ..
paulson@14265
    95
obua@14738
    96
axclass idom \<subseteq> comm_ring_1, axclass_no_zero_divisors
paulson@14421
    97
obua@14738
    98
axclass field \<subseteq> comm_ring_1, inverse
paulson@14265
    99
  left_inverse [simp]: "a \<noteq> 0 ==> inverse a * a = 1"
paulson@14430
   100
  divide_inverse:      "a / b = a * inverse b"
paulson@14265
   101
obua@14940
   102
lemma mult_zero_left [simp]: "0 * a = (0::'a::semiring_0_cancel)"
obua@14738
   103
proof -
obua@14738
   104
  have "0*a + 0*a = 0*a + 0"
obua@14738
   105
    by (simp add: left_distrib [symmetric])
obua@14738
   106
  thus ?thesis 
obua@14738
   107
    by (simp only: add_left_cancel)
obua@14738
   108
qed
paulson@14265
   109
obua@14940
   110
lemma mult_zero_right [simp]: "a * 0 = (0::'a::semiring_0_cancel)"
obua@14738
   111
proof -
obua@14738
   112
  have "a*0 + a*0 = a*0 + 0"
obua@14738
   113
    by (simp add: right_distrib [symmetric])
obua@14738
   114
  thus ?thesis 
obua@14738
   115
    by (simp only: add_left_cancel)
obua@14738
   116
qed
obua@14738
   117
obua@14738
   118
lemma field_mult_eq_0_iff [simp]: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
obua@14738
   119
proof cases
obua@14738
   120
  assume "a=0" thus ?thesis by simp
obua@14738
   121
next
obua@14738
   122
  assume anz [simp]: "a\<noteq>0"
obua@14738
   123
  { assume "a * b = 0"
obua@14738
   124
    hence "inverse a * (a * b) = 0" by simp
obua@14738
   125
    hence "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])}
obua@14738
   126
  thus ?thesis by force
obua@14738
   127
qed
obua@14738
   128
obua@14738
   129
instance field \<subseteq> idom
obua@14738
   130
by (intro_classes, simp)
obua@14738
   131
  
paulson@14265
   132
axclass division_by_zero \<subseteq> zero, inverse
paulson@14268
   133
  inverse_zero [simp]: "inverse 0 = 0"
paulson@14265
   134
paulson@14265
   135
subsection {* Distribution rules *}
paulson@14265
   136
paulson@14265
   137
theorems ring_distrib = right_distrib left_distrib
paulson@14265
   138
paulson@14272
   139
text{*For the @{text combine_numerals} simproc*}
paulson@14421
   140
lemma combine_common_factor:
obua@14738
   141
     "a*e + (b*e + c) = (a+b)*e + (c::'a::semiring)"
paulson@14272
   142
by (simp add: left_distrib add_ac)
paulson@14272
   143
paulson@14265
   144
lemma minus_mult_left: "- (a * b) = (-a) * (b::'a::ring)"
paulson@14265
   145
apply (rule equals_zero_I)
paulson@14265
   146
apply (simp add: left_distrib [symmetric]) 
paulson@14265
   147
done
paulson@14265
   148
paulson@14265
   149
lemma minus_mult_right: "- (a * b) = a * -(b::'a::ring)"
paulson@14265
   150
apply (rule equals_zero_I)
paulson@14265
   151
apply (simp add: right_distrib [symmetric]) 
paulson@14265
   152
done
paulson@14265
   153
paulson@14268
   154
lemma minus_mult_minus [simp]: "(- a) * (- b) = a * (b::'a::ring)"
paulson@14268
   155
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
paulson@14268
   156
paulson@14365
   157
lemma minus_mult_commute: "(- a) * b = a * (- b::'a::ring)"
paulson@14365
   158
  by (simp add: minus_mult_left [symmetric] minus_mult_right [symmetric])
paulson@14365
   159
paulson@14265
   160
lemma right_diff_distrib: "a * (b - c) = a * b - a * (c::'a::ring)"
paulson@14265
   161
by (simp add: right_distrib diff_minus 
paulson@14265
   162
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   163
paulson@14272
   164
lemma left_diff_distrib: "(a - b) * c = a * c - b * (c::'a::ring)"
obua@14738
   165
by (simp add: left_distrib diff_minus 
obua@14738
   166
              minus_mult_left [symmetric] minus_mult_right [symmetric]) 
paulson@14265
   167
obua@14738
   168
axclass pordered_semiring \<subseteq> semiring_0, pordered_ab_semigroup_add 
obua@14738
   169
  mult_left_mono: "a <= b \<Longrightarrow> 0 <= c \<Longrightarrow> c * a <= c * b"
obua@14738
   170
  mult_right_mono: "a <= b \<Longrightarrow> 0 <= c \<Longrightarrow> a * c <= b * c"
paulson@14267
   171
obua@14738
   172
axclass pordered_cancel_semiring \<subseteq> pordered_semiring, cancel_ab_semigroup_add
paulson@14268
   173
obua@14940
   174
instance pordered_cancel_semiring \<subseteq> semiring_0_cancel ..
obua@14940
   175
obua@14738
   176
axclass ordered_semiring_strict \<subseteq> semiring_0, ordered_cancel_ab_semigroup_add
obua@14738
   177
  mult_strict_left_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
obua@14738
   178
  mult_strict_right_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> a * c < b * c"
paulson@14341
   179
obua@14940
   180
instance ordered_semiring_strict \<subseteq> semiring_0_cancel ..
obua@14940
   181
obua@14738
   182
instance ordered_semiring_strict \<subseteq> pordered_cancel_semiring
obua@14738
   183
apply intro_classes
obua@14738
   184
apply (case_tac "a < b & 0 < c")
obua@14738
   185
apply (auto simp add: mult_strict_left_mono order_less_le)
obua@14738
   186
apply (auto simp add: mult_strict_left_mono order_le_less)
obua@14738
   187
apply (simp add: mult_strict_right_mono)
paulson@14270
   188
done
paulson@14270
   189
obua@14738
   190
axclass pordered_comm_semiring \<subseteq> comm_semiring_0, pordered_ab_semigroup_add
obua@14738
   191
  mult_mono: "a <= b \<Longrightarrow> 0 <= c \<Longrightarrow> c * a <= c * b"
paulson@14270
   192
obua@14738
   193
axclass pordered_cancel_comm_semiring \<subseteq> pordered_comm_semiring, cancel_ab_semigroup_add
paulson@14270
   194
obua@14738
   195
instance pordered_cancel_comm_semiring \<subseteq> pordered_comm_semiring ..
paulson@14270
   196
obua@14738
   197
axclass ordered_comm_semiring_strict \<subseteq> comm_semiring_0, ordered_cancel_ab_semigroup_add
obua@14738
   198
  mult_strict_mono: "a < b \<Longrightarrow> 0 < c \<Longrightarrow> c * a < c * b"
paulson@14265
   199
obua@14738
   200
instance pordered_comm_semiring \<subseteq> pordered_semiring
obua@14738
   201
by (intro_classes, insert mult_mono, simp_all add: mult_commute, blast+)
paulson@14265
   202
obua@14738
   203
instance pordered_cancel_comm_semiring \<subseteq> pordered_cancel_semiring ..
paulson@14265
   204
obua@14738
   205
instance ordered_comm_semiring_strict \<subseteq> ordered_semiring_strict
obua@14738
   206
by (intro_classes, insert mult_strict_mono, simp_all add: mult_commute, blast+)
paulson@14272
   207
obua@14738
   208
instance ordered_comm_semiring_strict \<subseteq> pordered_cancel_comm_semiring
obua@14738
   209
apply (intro_classes)
obua@14738
   210
apply (case_tac "a < b & 0 < c")
obua@14738
   211
apply (auto simp add: mult_strict_left_mono order_less_le)
obua@14738
   212
apply (auto simp add: mult_strict_left_mono order_le_less)
paulson@14272
   213
done
paulson@14272
   214
obua@14738
   215
axclass pordered_ring \<subseteq> ring, pordered_semiring 
paulson@14270
   216
obua@14738
   217
instance pordered_ring \<subseteq> pordered_ab_group_add ..
paulson@14270
   218
obua@14738
   219
instance pordered_ring \<subseteq> pordered_cancel_semiring ..
paulson@14270
   220
obua@14738
   221
axclass lordered_ring \<subseteq> pordered_ring, lordered_ab_group_abs
paulson@14270
   222
obua@14940
   223
instance lordered_ring \<subseteq> lordered_ab_group_meet ..
obua@14940
   224
obua@14940
   225
instance lordered_ring \<subseteq> lordered_ab_group_join ..
obua@14940
   226
obua@14738
   227
axclass axclass_abs_if \<subseteq> minus, ord, zero
obua@14738
   228
  abs_if: "abs a = (if (a < 0) then (-a) else a)"
paulson@14270
   229
obua@14738
   230
axclass ordered_ring_strict \<subseteq> ring, ordered_semiring_strict, axclass_abs_if
paulson@14270
   231
obua@14738
   232
instance ordered_ring_strict \<subseteq> lordered_ab_group ..
paulson@14270
   233
obua@14738
   234
instance ordered_ring_strict \<subseteq> lordered_ring
obua@14738
   235
by (intro_classes, simp add: abs_if join_eq_if)
paulson@14270
   236
obua@14738
   237
axclass pordered_comm_ring \<subseteq> comm_ring, pordered_comm_semiring
paulson@14270
   238
obua@14738
   239
axclass ordered_semidom \<subseteq> comm_semiring_1_cancel, ordered_comm_semiring_strict (* previously ordered_semiring *)
obua@14738
   240
  zero_less_one [simp]: "0 < 1"
paulson@14270
   241
obua@14738
   242
axclass ordered_idom \<subseteq> comm_ring_1, ordered_comm_semiring_strict, axclass_abs_if (* previously ordered_ring *)
paulson@14270
   243
obua@14738
   244
instance ordered_idom \<subseteq> ordered_ring_strict ..
paulson@14272
   245
obua@14738
   246
axclass ordered_field \<subseteq> field, ordered_idom
paulson@14272
   247
paulson@14272
   248
lemma eq_add_iff1:
paulson@14272
   249
     "(a*e + c = b*e + d) = ((a-b)*e + c = (d::'a::ring))"
obua@14738
   250
apply (simp add: diff_minus left_distrib)
paulson@14272
   251
apply (simp add: diff_minus left_distrib add_ac)
obua@14738
   252
apply (simp add: compare_rls minus_mult_left [symmetric])
paulson@14272
   253
done
paulson@14272
   254
paulson@14272
   255
lemma eq_add_iff2:
paulson@14272
   256
     "(a*e + c = b*e + d) = (c = (b-a)*e + (d::'a::ring))"
paulson@14272
   257
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   258
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   259
done
paulson@14272
   260
paulson@14272
   261
lemma less_add_iff1:
obua@14738
   262
     "(a*e + c < b*e + d) = ((a-b)*e + c < (d::'a::pordered_ring))"
paulson@14272
   263
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   264
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   265
done
paulson@14272
   266
paulson@14272
   267
lemma less_add_iff2:
obua@14738
   268
     "(a*e + c < b*e + d) = (c < (b-a)*e + (d::'a::pordered_ring))"
paulson@14272
   269
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   270
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   271
done
paulson@14272
   272
paulson@14272
   273
lemma le_add_iff1:
obua@14738
   274
     "(a*e + c \<le> b*e + d) = ((a-b)*e + c \<le> (d::'a::pordered_ring))"
paulson@14272
   275
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   276
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   277
done
paulson@14272
   278
paulson@14272
   279
lemma le_add_iff2:
obua@14738
   280
     "(a*e + c \<le> b*e + d) = (c \<le> (b-a)*e + (d::'a::pordered_ring))"
paulson@14272
   281
apply (simp add: diff_minus left_distrib add_ac)
paulson@14272
   282
apply (simp add: compare_rls minus_mult_left [symmetric]) 
paulson@14272
   283
done
paulson@14272
   284
paulson@14270
   285
subsection {* Ordering Rules for Multiplication *}
paulson@14270
   286
paulson@14348
   287
lemma mult_left_le_imp_le:
obua@14738
   288
     "[|c*a \<le> c*b; 0 < c|] ==> a \<le> (b::'a::ordered_semiring_strict)"
paulson@14348
   289
  by (force simp add: mult_strict_left_mono linorder_not_less [symmetric])
paulson@14348
   290
 
paulson@14348
   291
lemma mult_right_le_imp_le:
obua@14738
   292
     "[|a*c \<le> b*c; 0 < c|] ==> a \<le> (b::'a::ordered_semiring_strict)"
paulson@14348
   293
  by (force simp add: mult_strict_right_mono linorder_not_less [symmetric])
paulson@14348
   294
paulson@14348
   295
lemma mult_left_less_imp_less:
obua@14738
   296
     "[|c*a < c*b; 0 \<le> c|] ==> a < (b::'a::ordered_semiring_strict)"
paulson@14348
   297
  by (force simp add: mult_left_mono linorder_not_le [symmetric])
paulson@14348
   298
 
paulson@14348
   299
lemma mult_right_less_imp_less:
obua@14738
   300
     "[|a*c < b*c; 0 \<le> c|] ==> a < (b::'a::ordered_semiring_strict)"
paulson@14348
   301
  by (force simp add: mult_right_mono linorder_not_le [symmetric])
paulson@14348
   302
paulson@14265
   303
lemma mult_strict_left_mono_neg:
obua@14738
   304
     "[|b < a; c < 0|] ==> c * a < c * (b::'a::ordered_ring_strict)"
paulson@14265
   305
apply (drule mult_strict_left_mono [of _ _ "-c"])
paulson@14265
   306
apply (simp_all add: minus_mult_left [symmetric]) 
paulson@14265
   307
done
paulson@14265
   308
obua@14738
   309
lemma mult_left_mono_neg:
obua@14738
   310
     "[|b \<le> a; c \<le> 0|] ==> c * a \<le>  c * (b::'a::pordered_ring)"
obua@14738
   311
apply (drule mult_left_mono [of _ _ "-c"])
obua@14738
   312
apply (simp_all add: minus_mult_left [symmetric]) 
obua@14738
   313
done
obua@14738
   314
paulson@14265
   315
lemma mult_strict_right_mono_neg:
obua@14738
   316
     "[|b < a; c < 0|] ==> a * c < b * (c::'a::ordered_ring_strict)"
paulson@14265
   317
apply (drule mult_strict_right_mono [of _ _ "-c"])
paulson@14265
   318
apply (simp_all add: minus_mult_right [symmetric]) 
paulson@14265
   319
done
paulson@14265
   320
obua@14738
   321
lemma mult_right_mono_neg:
obua@14738
   322
     "[|b \<le> a; c \<le> 0|] ==> a * c \<le>  (b::'a::pordered_ring) * c"
obua@14738
   323
apply (drule mult_right_mono [of _ _ "-c"])
obua@14738
   324
apply (simp)
obua@14738
   325
apply (simp_all add: minus_mult_right [symmetric]) 
obua@14738
   326
done
paulson@14265
   327
paulson@14265
   328
subsection{* Products of Signs *}
paulson@14265
   329
obua@14738
   330
lemma mult_pos: "[| (0::'a::ordered_semiring_strict) < a; 0 < b |] ==> 0 < a*b"
paulson@14265
   331
by (drule mult_strict_left_mono [of 0 b], auto)
paulson@14265
   332
obua@14738
   333
lemma mult_pos_le: "[| (0::'a::pordered_cancel_semiring) \<le> a; 0 \<le> b |] ==> 0 \<le> a*b"
obua@14738
   334
by (drule mult_left_mono [of 0 b], auto)
obua@14738
   335
obua@14738
   336
lemma mult_pos_neg: "[| (0::'a::ordered_semiring_strict) < a; b < 0 |] ==> a*b < 0"
paulson@14265
   337
by (drule mult_strict_left_mono [of b 0], auto)
paulson@14265
   338
obua@14738
   339
lemma mult_pos_neg_le: "[| (0::'a::pordered_cancel_semiring) \<le> a; b \<le> 0 |] ==> a*b \<le> 0"
obua@14738
   340
by (drule mult_left_mono [of b 0], auto)
obua@14738
   341
obua@14738
   342
lemma mult_pos_neg2: "[| (0::'a::ordered_semiring_strict) < a; b < 0 |] ==> b*a < 0" 
obua@14738
   343
by (drule mult_strict_right_mono[of b 0], auto)
obua@14738
   344
obua@14738
   345
lemma mult_pos_neg2_le: "[| (0::'a::pordered_cancel_semiring) \<le> a; b \<le> 0 |] ==> b*a \<le> 0" 
obua@14738
   346
by (drule mult_right_mono[of b 0], auto)
obua@14738
   347
obua@14738
   348
lemma mult_neg: "[| a < (0::'a::ordered_ring_strict); b < 0 |] ==> 0 < a*b"
paulson@14265
   349
by (drule mult_strict_right_mono_neg, auto)
paulson@14265
   350
obua@14738
   351
lemma mult_neg_le: "[| a \<le> (0::'a::pordered_ring); b \<le> 0 |] ==> 0 \<le> a*b"
obua@14738
   352
by (drule mult_right_mono_neg[of a 0 b ], auto)
obua@14738
   353
paulson@14341
   354
lemma zero_less_mult_pos:
obua@14738
   355
     "[| 0 < a*b; 0 < a|] ==> 0 < (b::'a::ordered_semiring_strict)"
paulson@14265
   356
apply (case_tac "b\<le>0") 
paulson@14265
   357
 apply (auto simp add: order_le_less linorder_not_less)
paulson@14265
   358
apply (drule_tac mult_pos_neg [of a b]) 
paulson@14265
   359
 apply (auto dest: order_less_not_sym)
paulson@14265
   360
done
paulson@14265
   361
obua@14738
   362
lemma zero_less_mult_pos2:
obua@14738
   363
     "[| 0 < b*a; 0 < a|] ==> 0 < (b::'a::ordered_semiring_strict)"
obua@14738
   364
apply (case_tac "b\<le>0") 
obua@14738
   365
 apply (auto simp add: order_le_less linorder_not_less)
obua@14738
   366
apply (drule_tac mult_pos_neg2 [of a b]) 
obua@14738
   367
 apply (auto dest: order_less_not_sym)
obua@14738
   368
done
obua@14738
   369
paulson@14265
   370
lemma zero_less_mult_iff:
obua@14738
   371
     "((0::'a::ordered_ring_strict) < a*b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14265
   372
apply (auto simp add: order_le_less linorder_not_less mult_pos mult_neg)
paulson@14265
   373
apply (blast dest: zero_less_mult_pos) 
obua@14738
   374
apply (blast dest: zero_less_mult_pos2)
paulson@14265
   375
done
paulson@14265
   376
paulson@14341
   377
text{*A field has no "zero divisors", and this theorem holds without the
paulson@14277
   378
      assumption of an ordering.  See @{text field_mult_eq_0_iff} below.*}
obua@14738
   379
lemma mult_eq_0_iff [simp]: "(a*b = (0::'a::ordered_ring_strict)) = (a = 0 | b = 0)"
paulson@14265
   380
apply (case_tac "a < 0")
paulson@14265
   381
apply (auto simp add: linorder_not_less order_le_less linorder_neq_iff)
paulson@14265
   382
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono)+
paulson@14265
   383
done
paulson@14265
   384
paulson@14265
   385
lemma zero_le_mult_iff:
obua@14738
   386
     "((0::'a::ordered_ring_strict) \<le> a*b) = (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14265
   387
by (auto simp add: eq_commute [of 0] order_le_less linorder_not_less
paulson@14265
   388
                   zero_less_mult_iff)
paulson@14265
   389
paulson@14265
   390
lemma mult_less_0_iff:
obua@14738
   391
     "(a*b < (0::'a::ordered_ring_strict)) = (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14265
   392
apply (insert zero_less_mult_iff [of "-a" b]) 
paulson@14265
   393
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   394
done
paulson@14265
   395
paulson@14265
   396
lemma mult_le_0_iff:
obua@14738
   397
     "(a*b \<le> (0::'a::ordered_ring_strict)) = (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14265
   398
apply (insert zero_le_mult_iff [of "-a" b]) 
paulson@14265
   399
apply (force simp add: minus_mult_left[symmetric]) 
paulson@14265
   400
done
paulson@14265
   401
obua@14738
   402
lemma split_mult_pos_le: "(0 \<le> a & 0 \<le> b) | (a \<le> 0 & b \<le> 0) \<Longrightarrow> 0 \<le> a * (b::_::pordered_ring)"
obua@14738
   403
by (auto simp add: mult_pos_le mult_neg_le)
obua@14738
   404
obua@14738
   405
lemma split_mult_neg_le: "(0 \<le> a & b \<le> 0) | (a \<le> 0 & 0 \<le> b) \<Longrightarrow> a * b \<le> (0::_::pordered_cancel_semiring)" 
obua@14738
   406
by (auto simp add: mult_pos_neg_le mult_pos_neg2_le)
obua@14738
   407
obua@14738
   408
lemma zero_le_square: "(0::'a::ordered_ring_strict) \<le> a*a"
paulson@14265
   409
by (simp add: zero_le_mult_iff linorder_linear) 
paulson@14265
   410
obua@14738
   411
text{*Proving axiom @{text zero_less_one} makes all @{text ordered_semidom}
obua@14738
   412
      theorems available to members of @{term ordered_idom} *}
obua@14738
   413
obua@14738
   414
instance ordered_idom \<subseteq> ordered_semidom
paulson@14421
   415
proof
paulson@14421
   416
  have "(0::'a) \<le> 1*1" by (rule zero_le_square)
paulson@14430
   417
  thus "(0::'a) < 1" by (simp add: order_le_less) 
paulson@14421
   418
qed
paulson@14421
   419
obua@14738
   420
instance ordered_ring_strict \<subseteq> axclass_no_zero_divisors 
obua@14738
   421
by (intro_classes, simp)
obua@14738
   422
obua@14738
   423
instance ordered_idom \<subseteq> idom ..
obua@14738
   424
paulson@14387
   425
text{*All three types of comparision involving 0 and 1 are covered.*}
paulson@14387
   426
paulson@14387
   427
declare zero_neq_one [THEN not_sym, simp]
paulson@14387
   428
obua@14738
   429
lemma zero_le_one [simp]: "(0::'a::ordered_semidom) \<le> 1"
paulson@14268
   430
  by (rule zero_less_one [THEN order_less_imp_le]) 
paulson@14268
   431
obua@14738
   432
lemma not_one_le_zero [simp]: "~ (1::'a::ordered_semidom) \<le> 0"
obua@14738
   433
by (simp add: linorder_not_le) 
paulson@14387
   434
obua@14738
   435
lemma not_one_less_zero [simp]: "~ (1::'a::ordered_semidom) < 0"
obua@14738
   436
by (simp add: linorder_not_less) 
paulson@14268
   437
paulson@14268
   438
subsection{*More Monotonicity*}
paulson@14268
   439
paulson@14268
   440
text{*Strict monotonicity in both arguments*}
paulson@14268
   441
lemma mult_strict_mono:
obua@14738
   442
     "[|a<b; c<d; 0<b; 0\<le>c|] ==> a * c < b * (d::'a::ordered_semiring_strict)"
paulson@14268
   443
apply (case_tac "c=0")
paulson@14268
   444
 apply (simp add: mult_pos) 
paulson@14268
   445
apply (erule mult_strict_right_mono [THEN order_less_trans])
paulson@14268
   446
 apply (force simp add: order_le_less) 
paulson@14268
   447
apply (erule mult_strict_left_mono, assumption)
paulson@14268
   448
done
paulson@14268
   449
paulson@14268
   450
text{*This weaker variant has more natural premises*}
paulson@14268
   451
lemma mult_strict_mono':
obua@14738
   452
     "[| a<b; c<d; 0 \<le> a; 0 \<le> c|] ==> a * c < b * (d::'a::ordered_semiring_strict)"
paulson@14268
   453
apply (rule mult_strict_mono)
paulson@14268
   454
apply (blast intro: order_le_less_trans)+
paulson@14268
   455
done
paulson@14268
   456
paulson@14268
   457
lemma mult_mono:
paulson@14268
   458
     "[|a \<le> b; c \<le> d; 0 \<le> b; 0 \<le> c|] 
obua@14738
   459
      ==> a * c  \<le>  b * (d::'a::pordered_semiring)"
paulson@14268
   460
apply (erule mult_right_mono [THEN order_trans], assumption)
paulson@14268
   461
apply (erule mult_left_mono, assumption)
paulson@14268
   462
done
paulson@14268
   463
obua@14738
   464
lemma less_1_mult: "[| 1 < m; 1 < n |] ==> 1 < m*(n::'a::ordered_semidom)"
paulson@14387
   465
apply (insert mult_strict_mono [of 1 m 1 n]) 
paulson@14430
   466
apply (simp add:  order_less_trans [OF zero_less_one]) 
paulson@14387
   467
done
paulson@14387
   468
paulson@14268
   469
subsection{*Cancellation Laws for Relationships With a Common Factor*}
paulson@14268
   470
paulson@14268
   471
text{*Cancellation laws for @{term "c*a < c*b"} and @{term "a*c < b*c"},
paulson@14268
   472
   also with the relations @{text "\<le>"} and equality.*}
paulson@14268
   473
paulson@15234
   474
text{*These ``disjunction'' versions produce two cases when the comparison is
paulson@15234
   475
 an assumption, but effectively four when the comparison is a goal.*}
paulson@15234
   476
paulson@15234
   477
lemma mult_less_cancel_right_disj:
obua@14738
   478
    "(a*c < b*c) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring_strict)))"
paulson@14268
   479
apply (case_tac "c = 0")
paulson@14268
   480
apply (auto simp add: linorder_neq_iff mult_strict_right_mono 
paulson@14268
   481
                      mult_strict_right_mono_neg)
paulson@14268
   482
apply (auto simp add: linorder_not_less 
paulson@14268
   483
                      linorder_not_le [symmetric, of "a*c"]
paulson@14268
   484
                      linorder_not_le [symmetric, of a])
paulson@14268
   485
apply (erule_tac [!] notE)
paulson@14268
   486
apply (auto simp add: order_less_imp_le mult_right_mono 
paulson@14268
   487
                      mult_right_mono_neg)
paulson@14268
   488
done
paulson@14268
   489
paulson@15234
   490
lemma mult_less_cancel_left_disj:
obua@14738
   491
    "(c*a < c*b) = ((0 < c & a < b) | (c < 0 & b < (a::'a::ordered_ring_strict)))"
obua@14738
   492
apply (case_tac "c = 0")
obua@14738
   493
apply (auto simp add: linorder_neq_iff mult_strict_left_mono 
obua@14738
   494
                      mult_strict_left_mono_neg)
obua@14738
   495
apply (auto simp add: linorder_not_less 
obua@14738
   496
                      linorder_not_le [symmetric, of "c*a"]
obua@14738
   497
                      linorder_not_le [symmetric, of a])
obua@14738
   498
apply (erule_tac [!] notE)
obua@14738
   499
apply (auto simp add: order_less_imp_le mult_left_mono 
obua@14738
   500
                      mult_left_mono_neg)
obua@14738
   501
done
paulson@14268
   502
paulson@15234
   503
paulson@15234
   504
text{*The ``conjunction of implication'' lemmas produce two cases when the
paulson@15234
   505
comparison is a goal, but give four when the comparison is an assumption.*}
paulson@15234
   506
paulson@15234
   507
lemma mult_less_cancel_right:
paulson@15234
   508
  fixes c :: "'a :: ordered_ring_strict"
paulson@15234
   509
  shows      "(a*c < b*c) = ((0 \<le> c --> a < b) & (c \<le> 0 --> b < a))"
paulson@15234
   510
by (insert mult_less_cancel_right_disj [of a c b], auto)
paulson@15234
   511
paulson@15234
   512
lemma mult_less_cancel_left:
paulson@15234
   513
  fixes c :: "'a :: ordered_ring_strict"
paulson@15234
   514
  shows      "(c*a < c*b) = ((0 \<le> c --> a < b) & (c \<le> 0 --> b < a))"
paulson@15234
   515
by (insert mult_less_cancel_left_disj [of c a b], auto)
paulson@15234
   516
paulson@14268
   517
lemma mult_le_cancel_right:
obua@14738
   518
     "(a*c \<le> b*c) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring_strict)))"
paulson@15234
   519
by (simp add: linorder_not_less [symmetric] mult_less_cancel_right_disj)
paulson@14268
   520
paulson@14268
   521
lemma mult_le_cancel_left:
obua@14738
   522
     "(c*a \<le> c*b) = ((0<c --> a\<le>b) & (c<0 --> b \<le> (a::'a::ordered_ring_strict)))"
paulson@15234
   523
by (simp add: linorder_not_less [symmetric] mult_less_cancel_left_disj)
paulson@14268
   524
paulson@14268
   525
lemma mult_less_imp_less_left:
paulson@14341
   526
      assumes less: "c*a < c*b" and nonneg: "0 \<le> c"
obua@14738
   527
      shows "a < (b::'a::ordered_semiring_strict)"
paulson@14377
   528
proof (rule ccontr)
paulson@14377
   529
  assume "~ a < b"
paulson@14377
   530
  hence "b \<le> a" by (simp add: linorder_not_less)
paulson@14377
   531
  hence "c*b \<le> c*a" by (rule mult_left_mono)
paulson@14377
   532
  with this and less show False 
paulson@14377
   533
    by (simp add: linorder_not_less [symmetric])
paulson@14377
   534
qed
paulson@14268
   535
paulson@14268
   536
lemma mult_less_imp_less_right:
obua@14738
   537
  assumes less: "a*c < b*c" and nonneg: "0 <= c"
obua@14738
   538
  shows "a < (b::'a::ordered_semiring_strict)"
obua@14738
   539
proof (rule ccontr)
obua@14738
   540
  assume "~ a < b"
obua@14738
   541
  hence "b \<le> a" by (simp add: linorder_not_less)
obua@14738
   542
  hence "b*c \<le> a*c" by (rule mult_right_mono)
obua@14738
   543
  with this and less show False 
obua@14738
   544
    by (simp add: linorder_not_less [symmetric])
obua@14738
   545
qed  
paulson@14268
   546
paulson@14268
   547
text{*Cancellation of equalities with a common factor*}
paulson@14268
   548
lemma mult_cancel_right [simp]:
obua@14738
   549
     "(a*c = b*c) = (c = (0::'a::ordered_ring_strict) | a=b)"
paulson@14268
   550
apply (cut_tac linorder_less_linear [of 0 c])
paulson@14268
   551
apply (force dest: mult_strict_right_mono_neg mult_strict_right_mono
paulson@14268
   552
             simp add: linorder_neq_iff)
paulson@14268
   553
done
paulson@14268
   554
paulson@14268
   555
text{*These cancellation theorems require an ordering. Versions are proved
paulson@14268
   556
      below that work for fields without an ordering.*}
paulson@14268
   557
lemma mult_cancel_left [simp]:
obua@14738
   558
     "(c*a = c*b) = (c = (0::'a::ordered_ring_strict) | a=b)"
obua@14738
   559
apply (cut_tac linorder_less_linear [of 0 c])
obua@14738
   560
apply (force dest: mult_strict_left_mono_neg mult_strict_left_mono
obua@14738
   561
             simp add: linorder_neq_iff)
obua@14738
   562
done
paulson@14268
   563
paulson@15234
   564
paulson@15234
   565
subsubsection{*Special Cancellation Simprules for Multiplication*}
paulson@15234
   566
paulson@15234
   567
text{*These also produce two cases when the comparison is a goal.*}
paulson@15234
   568
paulson@15234
   569
lemma mult_le_cancel_right1:
paulson@15234
   570
  fixes c :: "'a :: ordered_idom"
paulson@15234
   571
  shows "(c \<le> b*c) = ((0<c --> 1\<le>b) & (c<0 --> b \<le> 1))"
paulson@15234
   572
by (insert mult_le_cancel_right [of 1 c b], simp)
paulson@15234
   573
paulson@15234
   574
lemma mult_le_cancel_right2:
paulson@15234
   575
  fixes c :: "'a :: ordered_idom"
paulson@15234
   576
  shows "(a*c \<le> c) = ((0<c --> a\<le>1) & (c<0 --> 1 \<le> a))"
paulson@15234
   577
by (insert mult_le_cancel_right [of a c 1], simp)
paulson@15234
   578
paulson@15234
   579
lemma mult_le_cancel_left1:
paulson@15234
   580
  fixes c :: "'a :: ordered_idom"
paulson@15234
   581
  shows "(c \<le> c*b) = ((0<c --> 1\<le>b) & (c<0 --> b \<le> 1))"
paulson@15234
   582
by (insert mult_le_cancel_left [of c 1 b], simp)
paulson@15234
   583
paulson@15234
   584
lemma mult_le_cancel_left2:
paulson@15234
   585
  fixes c :: "'a :: ordered_idom"
paulson@15234
   586
  shows "(c*a \<le> c) = ((0<c --> a\<le>1) & (c<0 --> 1 \<le> a))"
paulson@15234
   587
by (insert mult_le_cancel_left [of c a 1], simp)
paulson@15234
   588
paulson@15234
   589
lemma mult_less_cancel_right1:
paulson@15234
   590
  fixes c :: "'a :: ordered_idom"
paulson@15234
   591
  shows "(c < b*c) = ((0 \<le> c --> 1<b) & (c \<le> 0 --> b < 1))"
paulson@15234
   592
by (insert mult_less_cancel_right [of 1 c b], simp)
paulson@15234
   593
paulson@15234
   594
lemma mult_less_cancel_right2:
paulson@15234
   595
  fixes c :: "'a :: ordered_idom"
paulson@15234
   596
  shows "(a*c < c) = ((0 \<le> c --> a<1) & (c \<le> 0 --> 1 < a))"
paulson@15234
   597
by (insert mult_less_cancel_right [of a c 1], simp)
paulson@15234
   598
paulson@15234
   599
lemma mult_less_cancel_left1:
paulson@15234
   600
  fixes c :: "'a :: ordered_idom"
paulson@15234
   601
  shows "(c < c*b) = ((0 \<le> c --> 1<b) & (c \<le> 0 --> b < 1))"
paulson@15234
   602
by (insert mult_less_cancel_left [of c 1 b], simp)
paulson@15234
   603
paulson@15234
   604
lemma mult_less_cancel_left2:
paulson@15234
   605
  fixes c :: "'a :: ordered_idom"
paulson@15234
   606
  shows "(c*a < c) = ((0 \<le> c --> a<1) & (c \<le> 0 --> 1 < a))"
paulson@15234
   607
by (insert mult_less_cancel_left [of c a 1], simp)
paulson@15234
   608
paulson@15234
   609
lemma mult_cancel_right1 [simp]:
paulson@15234
   610
fixes c :: "'a :: ordered_idom"
paulson@15234
   611
  shows "(c = b*c) = (c = 0 | b=1)"
paulson@15234
   612
by (insert mult_cancel_right [of 1 c b], force)
paulson@15234
   613
paulson@15234
   614
lemma mult_cancel_right2 [simp]:
paulson@15234
   615
fixes c :: "'a :: ordered_idom"
paulson@15234
   616
  shows "(a*c = c) = (c = 0 | a=1)"
paulson@15234
   617
by (insert mult_cancel_right [of a c 1], simp)
paulson@15234
   618
 
paulson@15234
   619
lemma mult_cancel_left1 [simp]:
paulson@15234
   620
fixes c :: "'a :: ordered_idom"
paulson@15234
   621
  shows "(c = c*b) = (c = 0 | b=1)"
paulson@15234
   622
by (insert mult_cancel_left [of c 1 b], force)
paulson@15234
   623
paulson@15234
   624
lemma mult_cancel_left2 [simp]:
paulson@15234
   625
fixes c :: "'a :: ordered_idom"
paulson@15234
   626
  shows "(c*a = c) = (c = 0 | a=1)"
paulson@15234
   627
by (insert mult_cancel_left [of c a 1], simp)
paulson@15234
   628
paulson@15234
   629
paulson@15234
   630
text{*Simprules for comparisons where common factors can be cancelled.*}
paulson@15234
   631
lemmas mult_compare_simps =
paulson@15234
   632
    mult_le_cancel_right mult_le_cancel_left
paulson@15234
   633
    mult_le_cancel_right1 mult_le_cancel_right2
paulson@15234
   634
    mult_le_cancel_left1 mult_le_cancel_left2
paulson@15234
   635
    mult_less_cancel_right mult_less_cancel_left
paulson@15234
   636
    mult_less_cancel_right1 mult_less_cancel_right2
paulson@15234
   637
    mult_less_cancel_left1 mult_less_cancel_left2
paulson@15234
   638
    mult_cancel_right mult_cancel_left
paulson@15234
   639
    mult_cancel_right1 mult_cancel_right2
paulson@15234
   640
    mult_cancel_left1 mult_cancel_left2
paulson@15234
   641
paulson@15234
   642
obua@14738
   643
text{*This list of rewrites decides ring equalities by ordered rewriting.*}
obua@15178
   644
lemmas ring_eq_simps =  
obua@15178
   645
(*  mult_ac*)
obua@14738
   646
  left_distrib right_distrib left_diff_distrib right_diff_distrib
obua@15178
   647
  group_eq_simps
obua@15178
   648
(*  add_ac
obua@14738
   649
  add_diff_eq diff_add_eq diff_diff_eq diff_diff_eq2
obua@15178
   650
  diff_eq_eq eq_diff_eq *)
obua@14738
   651
    
paulson@14265
   652
subsection {* Fields *}
paulson@14265
   653
paulson@14288
   654
lemma right_inverse [simp]:
paulson@14288
   655
      assumes not0: "a \<noteq> 0" shows "a * inverse (a::'a::field) = 1"
paulson@14288
   656
proof -
paulson@14288
   657
  have "a * inverse a = inverse a * a" by (simp add: mult_ac)
paulson@14288
   658
  also have "... = 1" using not0 by simp
paulson@14288
   659
  finally show ?thesis .
paulson@14288
   660
qed
paulson@14288
   661
paulson@14288
   662
lemma right_inverse_eq: "b \<noteq> 0 ==> (a / b = 1) = (a = (b::'a::field))"
paulson@14288
   663
proof
paulson@14288
   664
  assume neq: "b \<noteq> 0"
paulson@14288
   665
  {
paulson@14288
   666
    hence "a = (a / b) * b" by (simp add: divide_inverse mult_ac)
paulson@14288
   667
    also assume "a / b = 1"
paulson@14288
   668
    finally show "a = b" by simp
paulson@14288
   669
  next
paulson@14288
   670
    assume "a = b"
paulson@14288
   671
    with neq show "a / b = 1" by (simp add: divide_inverse)
paulson@14288
   672
  }
paulson@14288
   673
qed
paulson@14288
   674
paulson@14288
   675
lemma nonzero_inverse_eq_divide: "a \<noteq> 0 ==> inverse (a::'a::field) = 1/a"
paulson@14288
   676
by (simp add: divide_inverse)
paulson@14288
   677
paulson@15228
   678
lemma divide_self: "a \<noteq> 0 ==> a / (a::'a::field) = 1"
paulson@14288
   679
  by (simp add: divide_inverse)
paulson@14288
   680
paulson@14430
   681
lemma divide_zero [simp]: "a / 0 = (0::'a::{field,division_by_zero})"
paulson@14430
   682
by (simp add: divide_inverse)
paulson@14277
   683
paulson@15228
   684
lemma divide_self_if [simp]:
paulson@15228
   685
     "a / (a::'a::{field,division_by_zero}) = (if a=0 then 0 else 1)"
paulson@15228
   686
  by (simp add: divide_self)
paulson@15228
   687
paulson@14430
   688
lemma divide_zero_left [simp]: "0/a = (0::'a::field)"
paulson@14430
   689
by (simp add: divide_inverse)
paulson@14277
   690
paulson@14430
   691
lemma inverse_eq_divide: "inverse (a::'a::field) = 1/a"
paulson@14430
   692
by (simp add: divide_inverse)
paulson@14277
   693
paulson@14430
   694
lemma add_divide_distrib: "(a+b)/(c::'a::field) = a/c + b/c"
paulson@14293
   695
by (simp add: divide_inverse left_distrib) 
paulson@14293
   696
paulson@14293
   697
paulson@14270
   698
text{*Compared with @{text mult_eq_0_iff}, this version removes the requirement
paulson@14270
   699
      of an ordering.*}
paulson@14348
   700
lemma field_mult_eq_0_iff [simp]: "(a*b = (0::'a::field)) = (a = 0 | b = 0)"
paulson@14377
   701
proof cases
paulson@14377
   702
  assume "a=0" thus ?thesis by simp
paulson@14377
   703
next
paulson@14377
   704
  assume anz [simp]: "a\<noteq>0"
paulson@14377
   705
  { assume "a * b = 0"
paulson@14377
   706
    hence "inverse a * (a * b) = 0" by simp
paulson@14377
   707
    hence "b = 0"  by (simp (no_asm_use) add: mult_assoc [symmetric])}
paulson@14377
   708
  thus ?thesis by force
paulson@14377
   709
qed
paulson@14270
   710
paulson@14268
   711
text{*Cancellation of equalities with a common factor*}
paulson@14268
   712
lemma field_mult_cancel_right_lemma:
paulson@14269
   713
      assumes cnz: "c \<noteq> (0::'a::field)"
paulson@14269
   714
	  and eq:  "a*c = b*c"
paulson@14269
   715
	 shows "a=b"
paulson@14377
   716
proof -
paulson@14268
   717
  have "(a * c) * inverse c = (b * c) * inverse c"
paulson@14268
   718
    by (simp add: eq)
paulson@14268
   719
  thus "a=b"
paulson@14268
   720
    by (simp add: mult_assoc cnz)
paulson@14377
   721
qed
paulson@14268
   722
paulson@14348
   723
lemma field_mult_cancel_right [simp]:
paulson@14268
   724
     "(a*c = b*c) = (c = (0::'a::field) | a=b)"
paulson@14377
   725
proof cases
paulson@14377
   726
  assume "c=0" thus ?thesis by simp
paulson@14377
   727
next
paulson@14377
   728
  assume "c\<noteq>0" 
paulson@14377
   729
  thus ?thesis by (force dest: field_mult_cancel_right_lemma)
paulson@14377
   730
qed
paulson@14268
   731
paulson@14348
   732
lemma field_mult_cancel_left [simp]:
paulson@14268
   733
     "(c*a = c*b) = (c = (0::'a::field) | a=b)"
paulson@14268
   734
  by (simp add: mult_commute [of c] field_mult_cancel_right) 
paulson@14268
   735
paulson@14268
   736
lemma nonzero_imp_inverse_nonzero: "a \<noteq> 0 ==> inverse a \<noteq> (0::'a::field)"
paulson@14377
   737
proof
paulson@14268
   738
  assume ianz: "inverse a = 0"
paulson@14268
   739
  assume "a \<noteq> 0"
paulson@14268
   740
  hence "1 = a * inverse a" by simp
paulson@14268
   741
  also have "... = 0" by (simp add: ianz)
paulson@14268
   742
  finally have "1 = (0::'a::field)" .
paulson@14268
   743
  thus False by (simp add: eq_commute)
paulson@14377
   744
qed
paulson@14268
   745
paulson@14277
   746
paulson@14277
   747
subsection{*Basic Properties of @{term inverse}*}
paulson@14277
   748
paulson@14268
   749
lemma inverse_zero_imp_zero: "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   750
apply (rule ccontr) 
paulson@14268
   751
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   752
done
paulson@14268
   753
paulson@14268
   754
lemma inverse_nonzero_imp_nonzero:
paulson@14268
   755
   "inverse a = 0 ==> a = (0::'a::field)"
paulson@14268
   756
apply (rule ccontr) 
paulson@14268
   757
apply (blast dest: nonzero_imp_inverse_nonzero) 
paulson@14268
   758
done
paulson@14268
   759
paulson@14268
   760
lemma inverse_nonzero_iff_nonzero [simp]:
paulson@14268
   761
   "(inverse a = 0) = (a = (0::'a::{field,division_by_zero}))"
paulson@14268
   762
by (force dest: inverse_nonzero_imp_nonzero) 
paulson@14268
   763
paulson@14268
   764
lemma nonzero_inverse_minus_eq:
paulson@14269
   765
      assumes [simp]: "a\<noteq>0"  shows "inverse(-a) = -inverse(a::'a::field)"
paulson@14377
   766
proof -
paulson@14377
   767
  have "-a * inverse (- a) = -a * - inverse a"
paulson@14377
   768
    by simp
paulson@14377
   769
  thus ?thesis 
paulson@14377
   770
    by (simp only: field_mult_cancel_left, simp)
paulson@14377
   771
qed
paulson@14268
   772
paulson@14268
   773
lemma inverse_minus_eq [simp]:
paulson@14377
   774
   "inverse(-a) = -inverse(a::'a::{field,division_by_zero})";
paulson@14377
   775
proof cases
paulson@14377
   776
  assume "a=0" thus ?thesis by (simp add: inverse_zero)
paulson@14377
   777
next
paulson@14377
   778
  assume "a\<noteq>0" 
paulson@14377
   779
  thus ?thesis by (simp add: nonzero_inverse_minus_eq)
paulson@14377
   780
qed
paulson@14268
   781
paulson@14268
   782
lemma nonzero_inverse_eq_imp_eq:
paulson@14269
   783
      assumes inveq: "inverse a = inverse b"
paulson@14269
   784
	  and anz:  "a \<noteq> 0"
paulson@14269
   785
	  and bnz:  "b \<noteq> 0"
paulson@14269
   786
	 shows "a = (b::'a::field)"
paulson@14377
   787
proof -
paulson@14268
   788
  have "a * inverse b = a * inverse a"
paulson@14268
   789
    by (simp add: inveq)
paulson@14268
   790
  hence "(a * inverse b) * b = (a * inverse a) * b"
paulson@14268
   791
    by simp
paulson@14268
   792
  thus "a = b"
paulson@14268
   793
    by (simp add: mult_assoc anz bnz)
paulson@14377
   794
qed
paulson@14268
   795
paulson@14268
   796
lemma inverse_eq_imp_eq:
paulson@14268
   797
     "inverse a = inverse b ==> a = (b::'a::{field,division_by_zero})"
paulson@14268
   798
apply (case_tac "a=0 | b=0") 
paulson@14268
   799
 apply (force dest!: inverse_zero_imp_zero
paulson@14268
   800
              simp add: eq_commute [of "0::'a"])
paulson@14268
   801
apply (force dest!: nonzero_inverse_eq_imp_eq) 
paulson@14268
   802
done
paulson@14268
   803
paulson@14268
   804
lemma inverse_eq_iff_eq [simp]:
paulson@14268
   805
     "(inverse a = inverse b) = (a = (b::'a::{field,division_by_zero}))"
paulson@14268
   806
by (force dest!: inverse_eq_imp_eq) 
paulson@14268
   807
paulson@14270
   808
lemma nonzero_inverse_inverse_eq:
paulson@14270
   809
      assumes [simp]: "a \<noteq> 0"  shows "inverse(inverse (a::'a::field)) = a"
paulson@14270
   810
  proof -
paulson@14270
   811
  have "(inverse (inverse a) * inverse a) * a = a" 
paulson@14270
   812
    by (simp add: nonzero_imp_inverse_nonzero)
paulson@14270
   813
  thus ?thesis
paulson@14270
   814
    by (simp add: mult_assoc)
paulson@14270
   815
  qed
paulson@14270
   816
paulson@14270
   817
lemma inverse_inverse_eq [simp]:
paulson@14270
   818
     "inverse(inverse (a::'a::{field,division_by_zero})) = a"
paulson@14270
   819
  proof cases
paulson@14270
   820
    assume "a=0" thus ?thesis by simp
paulson@14270
   821
  next
paulson@14270
   822
    assume "a\<noteq>0" 
paulson@14270
   823
    thus ?thesis by (simp add: nonzero_inverse_inverse_eq)
paulson@14270
   824
  qed
paulson@14270
   825
paulson@14270
   826
lemma inverse_1 [simp]: "inverse 1 = (1::'a::field)"
paulson@14270
   827
  proof -
paulson@14270
   828
  have "inverse 1 * 1 = (1::'a::field)" 
paulson@14270
   829
    by (rule left_inverse [OF zero_neq_one [symmetric]])
paulson@14270
   830
  thus ?thesis  by simp
paulson@14270
   831
  qed
paulson@14270
   832
paulson@15077
   833
lemma inverse_unique: 
paulson@15077
   834
  assumes ab: "a*b = 1"
paulson@15077
   835
  shows "inverse a = (b::'a::field)"
paulson@15077
   836
proof -
paulson@15077
   837
  have "a \<noteq> 0" using ab by auto
paulson@15077
   838
  moreover have "inverse a * (a * b) = inverse a" by (simp add: ab) 
paulson@15077
   839
  ultimately show ?thesis by (simp add: mult_assoc [symmetric]) 
paulson@15077
   840
qed
paulson@15077
   841
paulson@14270
   842
lemma nonzero_inverse_mult_distrib: 
paulson@14270
   843
      assumes anz: "a \<noteq> 0"
paulson@14270
   844
          and bnz: "b \<noteq> 0"
paulson@14270
   845
      shows "inverse(a*b) = inverse(b) * inverse(a::'a::field)"
paulson@14270
   846
  proof -
paulson@14270
   847
  have "inverse(a*b) * (a * b) * inverse(b) = inverse(b)" 
paulson@14270
   848
    by (simp add: field_mult_eq_0_iff anz bnz)
paulson@14270
   849
  hence "inverse(a*b) * a = inverse(b)" 
paulson@14270
   850
    by (simp add: mult_assoc bnz)
paulson@14270
   851
  hence "inverse(a*b) * a * inverse(a) = inverse(b) * inverse(a)" 
paulson@14270
   852
    by simp
paulson@14270
   853
  thus ?thesis
paulson@14270
   854
    by (simp add: mult_assoc anz)
paulson@14270
   855
  qed
paulson@14270
   856
paulson@14270
   857
text{*This version builds in division by zero while also re-orienting
paulson@14270
   858
      the right-hand side.*}
paulson@14270
   859
lemma inverse_mult_distrib [simp]:
paulson@14270
   860
     "inverse(a*b) = inverse(a) * inverse(b::'a::{field,division_by_zero})"
paulson@14270
   861
  proof cases
paulson@14270
   862
    assume "a \<noteq> 0 & b \<noteq> 0" 
paulson@14270
   863
    thus ?thesis  by (simp add: nonzero_inverse_mult_distrib mult_commute)
paulson@14270
   864
  next
paulson@14270
   865
    assume "~ (a \<noteq> 0 & b \<noteq> 0)" 
paulson@14270
   866
    thus ?thesis  by force
paulson@14270
   867
  qed
paulson@14270
   868
paulson@14270
   869
text{*There is no slick version using division by zero.*}
paulson@14270
   870
lemma inverse_add:
paulson@14270
   871
     "[|a \<noteq> 0;  b \<noteq> 0|]
paulson@14270
   872
      ==> inverse a + inverse b = (a+b) * inverse a * inverse (b::'a::field)"
paulson@14270
   873
apply (simp add: left_distrib mult_assoc)
paulson@14270
   874
apply (simp add: mult_commute [of "inverse a"]) 
paulson@14270
   875
apply (simp add: mult_assoc [symmetric] add_commute)
paulson@14270
   876
done
paulson@14270
   877
paulson@14365
   878
lemma inverse_divide [simp]:
paulson@14365
   879
      "inverse (a/b) = b / (a::'a::{field,division_by_zero})"
paulson@14430
   880
  by (simp add: divide_inverse mult_commute)
paulson@14365
   881
paulson@14277
   882
lemma nonzero_mult_divide_cancel_left:
paulson@14277
   883
  assumes [simp]: "b\<noteq>0" and [simp]: "c\<noteq>0" 
paulson@14277
   884
    shows "(c*a)/(c*b) = a/(b::'a::field)"
paulson@14277
   885
proof -
paulson@14277
   886
  have "(c*a)/(c*b) = c * a * (inverse b * inverse c)"
paulson@14277
   887
    by (simp add: field_mult_eq_0_iff divide_inverse 
paulson@14277
   888
                  nonzero_inverse_mult_distrib)
paulson@14277
   889
  also have "... =  a * inverse b * (inverse c * c)"
paulson@14277
   890
    by (simp only: mult_ac)
paulson@14277
   891
  also have "... =  a * inverse b"
paulson@14277
   892
    by simp
paulson@14277
   893
    finally show ?thesis 
paulson@14277
   894
    by (simp add: divide_inverse)
paulson@14277
   895
qed
paulson@14277
   896
paulson@14277
   897
lemma mult_divide_cancel_left:
paulson@14277
   898
     "c\<noteq>0 ==> (c*a) / (c*b) = a / (b::'a::{field,division_by_zero})"
paulson@14277
   899
apply (case_tac "b = 0")
paulson@14277
   900
apply (simp_all add: nonzero_mult_divide_cancel_left)
paulson@14277
   901
done
paulson@14277
   902
paulson@14321
   903
lemma nonzero_mult_divide_cancel_right:
paulson@14321
   904
     "[|b\<noteq>0; c\<noteq>0|] ==> (a*c) / (b*c) = a/(b::'a::field)"
paulson@14321
   905
by (simp add: mult_commute [of _ c] nonzero_mult_divide_cancel_left) 
paulson@14321
   906
paulson@14321
   907
lemma mult_divide_cancel_right:
paulson@14321
   908
     "c\<noteq>0 ==> (a*c) / (b*c) = a / (b::'a::{field,division_by_zero})"
paulson@14321
   909
apply (case_tac "b = 0")
paulson@14321
   910
apply (simp_all add: nonzero_mult_divide_cancel_right)
paulson@14321
   911
done
paulson@14321
   912
paulson@14277
   913
(*For ExtractCommonTerm*)
paulson@14277
   914
lemma mult_divide_cancel_eq_if:
paulson@14277
   915
     "(c*a) / (c*b) = 
paulson@14277
   916
      (if c=0 then 0 else a / (b::'a::{field,division_by_zero}))"
paulson@14277
   917
  by (simp add: mult_divide_cancel_left)
paulson@14277
   918
paulson@14284
   919
lemma divide_1 [simp]: "a/1 = (a::'a::field)"
paulson@14430
   920
  by (simp add: divide_inverse)
paulson@14284
   921
paulson@15234
   922
lemma times_divide_eq_right: "a * (b/c) = (a*b) / (c::'a::field)"
paulson@14430
   923
by (simp add: divide_inverse mult_assoc)
paulson@14288
   924
paulson@14430
   925
lemma times_divide_eq_left: "(b/c) * a = (b*a) / (c::'a::field)"
paulson@14430
   926
by (simp add: divide_inverse mult_ac)
paulson@14288
   927
paulson@14288
   928
lemma divide_divide_eq_right [simp]:
paulson@14288
   929
     "a / (b/c) = (a*c) / (b::'a::{field,division_by_zero})"
paulson@14430
   930
by (simp add: divide_inverse mult_ac)
paulson@14288
   931
paulson@14288
   932
lemma divide_divide_eq_left [simp]:
paulson@14288
   933
     "(a / b) / (c::'a::{field,division_by_zero}) = a / (b*c)"
paulson@14430
   934
by (simp add: divide_inverse mult_assoc)
paulson@14288
   935
paulson@14268
   936
paulson@15234
   937
subsubsection{*Special Cancellation Simprules for Division*}
paulson@15234
   938
paulson@15234
   939
lemma mult_divide_cancel_left_if [simp]:
paulson@15234
   940
  fixes c :: "'a :: {field,division_by_zero}"
paulson@15234
   941
  shows "(c*a) / (c*b) = (if c=0 then 0 else a/b)"
paulson@15234
   942
by (simp add: mult_divide_cancel_left)
paulson@15234
   943
paulson@15234
   944
lemma mult_divide_cancel_right_if [simp]:
paulson@15234
   945
  fixes c :: "'a :: {field,division_by_zero}"
paulson@15234
   946
  shows "(a*c) / (b*c) = (if c=0 then 0 else a/b)"
paulson@15234
   947
by (simp add: mult_divide_cancel_right)
paulson@15234
   948
paulson@15234
   949
lemma mult_divide_cancel_left_if1 [simp]:
paulson@15234
   950
  fixes c :: "'a :: {field,division_by_zero}"
paulson@15234
   951
  shows "c / (c*b) = (if c=0 then 0 else 1/b)"
paulson@15234
   952
apply (insert mult_divide_cancel_left_if [of c 1 b]) 
paulson@15234
   953
apply (simp del: mult_divide_cancel_left_if)
paulson@15234
   954
done
paulson@15234
   955
paulson@15234
   956
lemma mult_divide_cancel_left_if2 [simp]:
paulson@15234
   957
  fixes c :: "'a :: {field,division_by_zero}"
paulson@15234
   958
  shows "(c*a) / c = (if c=0 then 0 else a)" 
paulson@15234
   959
apply (insert mult_divide_cancel_left_if [of c a 1]) 
paulson@15234
   960
apply (simp del: mult_divide_cancel_left_if)
paulson@15234
   961
done
paulson@15234
   962
paulson@15234
   963
lemma mult_divide_cancel_right_if1 [simp]:
paulson@15234
   964
  fixes c :: "'a :: {field,division_by_zero}"
paulson@15234
   965
  shows "c / (b*c) = (if c=0 then 0 else 1/b)"
paulson@15234
   966
apply (insert mult_divide_cancel_right_if [of 1 c b]) 
paulson@15234
   967
apply (simp del: mult_divide_cancel_right_if)
paulson@15234
   968
done
paulson@15234
   969
paulson@15234
   970
lemma mult_divide_cancel_right_if2 [simp]:
paulson@15234
   971
  fixes c :: "'a :: {field,division_by_zero}"
paulson@15234
   972
  shows "(a*c) / c = (if c=0 then 0 else a)" 
paulson@15234
   973
apply (insert mult_divide_cancel_right_if [of a c 1]) 
paulson@15234
   974
apply (simp del: mult_divide_cancel_right_if)
paulson@15234
   975
done
paulson@15234
   976
paulson@15234
   977
text{*Two lemmas for cancelling the denominator*}
paulson@15234
   978
paulson@15234
   979
lemma times_divide_self_right [simp]: 
paulson@15234
   980
  fixes a :: "'a :: {field,division_by_zero}"
paulson@15234
   981
  shows "a * (b/a) = (if a=0 then 0 else b)"
paulson@15234
   982
by (simp add: times_divide_eq_right)
paulson@15234
   983
paulson@15234
   984
lemma times_divide_self_left [simp]: 
paulson@15234
   985
  fixes a :: "'a :: {field,division_by_zero}"
paulson@15234
   986
  shows "(b/a) * a = (if a=0 then 0 else b)"
paulson@15234
   987
by (simp add: times_divide_eq_left)
paulson@15234
   988
paulson@15234
   989
paulson@14293
   990
subsection {* Division and Unary Minus *}
paulson@14293
   991
paulson@14293
   992
lemma nonzero_minus_divide_left: "b \<noteq> 0 ==> - (a/b) = (-a) / (b::'a::field)"
paulson@14293
   993
by (simp add: divide_inverse minus_mult_left)
paulson@14293
   994
paulson@14293
   995
lemma nonzero_minus_divide_right: "b \<noteq> 0 ==> - (a/b) = a / -(b::'a::field)"
paulson@14293
   996
by (simp add: divide_inverse nonzero_inverse_minus_eq minus_mult_right)
paulson@14293
   997
paulson@14293
   998
lemma nonzero_minus_divide_divide: "b \<noteq> 0 ==> (-a)/(-b) = a / (b::'a::field)"
paulson@14293
   999
by (simp add: divide_inverse nonzero_inverse_minus_eq)
paulson@14293
  1000
paulson@14430
  1001
lemma minus_divide_left: "- (a/b) = (-a) / (b::'a::field)"
paulson@14430
  1002
by (simp add: divide_inverse minus_mult_left [symmetric])
paulson@14293
  1003
paulson@14293
  1004
lemma minus_divide_right: "- (a/b) = a / -(b::'a::{field,division_by_zero})"
paulson@14430
  1005
by (simp add: divide_inverse minus_mult_right [symmetric])
paulson@14430
  1006
paulson@14293
  1007
paulson@14293
  1008
text{*The effect is to extract signs from divisions*}
paulson@14293
  1009
declare minus_divide_left  [symmetric, simp]
paulson@14293
  1010
declare minus_divide_right [symmetric, simp]
paulson@14293
  1011
paulson@14387
  1012
text{*Also, extract signs from products*}
paulson@14387
  1013
declare minus_mult_left [symmetric, simp]
paulson@14387
  1014
declare minus_mult_right [symmetric, simp]
paulson@14387
  1015
paulson@14293
  1016
lemma minus_divide_divide [simp]:
paulson@14293
  1017
     "(-a)/(-b) = a / (b::'a::{field,division_by_zero})"
paulson@14293
  1018
apply (case_tac "b=0", simp) 
paulson@14293
  1019
apply (simp add: nonzero_minus_divide_divide) 
paulson@14293
  1020
done
paulson@14293
  1021
paulson@14430
  1022
lemma diff_divide_distrib: "(a-b)/(c::'a::field) = a/c - b/c"
paulson@14387
  1023
by (simp add: diff_minus add_divide_distrib) 
paulson@14387
  1024
paulson@14293
  1025
paulson@14268
  1026
subsection {* Ordered Fields *}
paulson@14268
  1027
paulson@14277
  1028
lemma positive_imp_inverse_positive: 
paulson@14269
  1029
      assumes a_gt_0: "0 < a"  shows "0 < inverse (a::'a::ordered_field)"
paulson@14268
  1030
  proof -
paulson@14268
  1031
  have "0 < a * inverse a" 
paulson@14268
  1032
    by (simp add: a_gt_0 [THEN order_less_imp_not_eq2] zero_less_one)
paulson@14268
  1033
  thus "0 < inverse a" 
paulson@14268
  1034
    by (simp add: a_gt_0 [THEN order_less_not_sym] zero_less_mult_iff)
paulson@14268
  1035
  qed
paulson@14268
  1036
paulson@14277
  1037
lemma negative_imp_inverse_negative:
paulson@14268
  1038
     "a < 0 ==> inverse a < (0::'a::ordered_field)"
paulson@14277
  1039
  by (insert positive_imp_inverse_positive [of "-a"], 
paulson@14268
  1040
      simp add: nonzero_inverse_minus_eq order_less_imp_not_eq) 
paulson@14268
  1041
paulson@14268
  1042
lemma inverse_le_imp_le:
paulson@14269
  1043
      assumes invle: "inverse a \<le> inverse b"
paulson@14269
  1044
	  and apos:  "0 < a"
paulson@14269
  1045
	 shows "b \<le> (a::'a::ordered_field)"
paulson@14268
  1046
  proof (rule classical)
paulson@14268
  1047
  assume "~ b \<le> a"
paulson@14268
  1048
  hence "a < b"
paulson@14268
  1049
    by (simp add: linorder_not_le)
paulson@14268
  1050
  hence bpos: "0 < b"
paulson@14268
  1051
    by (blast intro: apos order_less_trans)
paulson@14268
  1052
  hence "a * inverse a \<le> a * inverse b"
paulson@14268
  1053
    by (simp add: apos invle order_less_imp_le mult_left_mono)
paulson@14268
  1054
  hence "(a * inverse a) * b \<le> (a * inverse b) * b"
paulson@14268
  1055
    by (simp add: bpos order_less_imp_le mult_right_mono)
paulson@14268
  1056
  thus "b \<le> a"
paulson@14268
  1057
    by (simp add: mult_assoc apos bpos order_less_imp_not_eq2)
paulson@14268
  1058
  qed
paulson@14268
  1059
paulson@14277
  1060
lemma inverse_positive_imp_positive:
paulson@14277
  1061
      assumes inv_gt_0: "0 < inverse a"
paulson@14277
  1062
          and [simp]:   "a \<noteq> 0"
paulson@14277
  1063
        shows "0 < (a::'a::ordered_field)"
paulson@14277
  1064
  proof -
paulson@14277
  1065
  have "0 < inverse (inverse a)"
paulson@14277
  1066
    by (rule positive_imp_inverse_positive)
paulson@14277
  1067
  thus "0 < a"
paulson@14277
  1068
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
  1069
  qed
paulson@14277
  1070
paulson@14277
  1071
lemma inverse_positive_iff_positive [simp]:
paulson@14277
  1072
      "(0 < inverse a) = (0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1073
apply (case_tac "a = 0", simp)
paulson@14277
  1074
apply (blast intro: inverse_positive_imp_positive positive_imp_inverse_positive)
paulson@14277
  1075
done
paulson@14277
  1076
paulson@14277
  1077
lemma inverse_negative_imp_negative:
paulson@14277
  1078
      assumes inv_less_0: "inverse a < 0"
paulson@14277
  1079
          and [simp]:   "a \<noteq> 0"
paulson@14277
  1080
        shows "a < (0::'a::ordered_field)"
paulson@14277
  1081
  proof -
paulson@14277
  1082
  have "inverse (inverse a) < 0"
paulson@14277
  1083
    by (rule negative_imp_inverse_negative)
paulson@14277
  1084
  thus "a < 0"
paulson@14277
  1085
    by (simp add: nonzero_inverse_inverse_eq)
paulson@14277
  1086
  qed
paulson@14277
  1087
paulson@14277
  1088
lemma inverse_negative_iff_negative [simp]:
paulson@14277
  1089
      "(inverse a < 0) = (a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1090
apply (case_tac "a = 0", simp)
paulson@14277
  1091
apply (blast intro: inverse_negative_imp_negative negative_imp_inverse_negative)
paulson@14277
  1092
done
paulson@14277
  1093
paulson@14277
  1094
lemma inverse_nonnegative_iff_nonnegative [simp]:
paulson@14277
  1095
      "(0 \<le> inverse a) = (0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1096
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1097
paulson@14277
  1098
lemma inverse_nonpositive_iff_nonpositive [simp]:
paulson@14277
  1099
      "(inverse a \<le> 0) = (a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14277
  1100
by (simp add: linorder_not_less [symmetric])
paulson@14277
  1101
paulson@14277
  1102
paulson@14277
  1103
subsection{*Anti-Monotonicity of @{term inverse}*}
paulson@14277
  1104
paulson@14268
  1105
lemma less_imp_inverse_less:
paulson@14269
  1106
      assumes less: "a < b"
paulson@14269
  1107
	  and apos:  "0 < a"
paulson@14269
  1108
	shows "inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1109
  proof (rule ccontr)
paulson@14268
  1110
  assume "~ inverse b < inverse a"
paulson@14268
  1111
  hence "inverse a \<le> inverse b"
paulson@14268
  1112
    by (simp add: linorder_not_less)
paulson@14268
  1113
  hence "~ (a < b)"
paulson@14268
  1114
    by (simp add: linorder_not_less inverse_le_imp_le [OF _ apos])
paulson@14268
  1115
  thus False
paulson@14268
  1116
    by (rule notE [OF _ less])
paulson@14268
  1117
  qed
paulson@14268
  1118
paulson@14268
  1119
lemma inverse_less_imp_less:
paulson@14268
  1120
   "[|inverse a < inverse b; 0 < a|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1121
apply (simp add: order_less_le [of "inverse a"] order_less_le [of "b"])
paulson@14268
  1122
apply (force dest!: inverse_le_imp_le nonzero_inverse_eq_imp_eq) 
paulson@14268
  1123
done
paulson@14268
  1124
paulson@14268
  1125
text{*Both premises are essential. Consider -1 and 1.*}
paulson@14268
  1126
lemma inverse_less_iff_less [simp]:
paulson@14268
  1127
     "[|0 < a; 0 < b|] 
paulson@14268
  1128
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1129
by (blast intro: less_imp_inverse_less dest: inverse_less_imp_less) 
paulson@14268
  1130
paulson@14268
  1131
lemma le_imp_inverse_le:
paulson@14268
  1132
   "[|a \<le> b; 0 < a|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1133
  by (force simp add: order_le_less less_imp_inverse_less)
paulson@14268
  1134
paulson@14268
  1135
lemma inverse_le_iff_le [simp]:
paulson@14268
  1136
     "[|0 < a; 0 < b|] 
paulson@14268
  1137
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1138
by (blast intro: le_imp_inverse_le dest: inverse_le_imp_le) 
paulson@14268
  1139
paulson@14268
  1140
paulson@14268
  1141
text{*These results refer to both operands being negative.  The opposite-sign
paulson@14268
  1142
case is trivial, since inverse preserves signs.*}
paulson@14268
  1143
lemma inverse_le_imp_le_neg:
paulson@14268
  1144
   "[|inverse a \<le> inverse b; b < 0|] ==> b \<le> (a::'a::ordered_field)"
paulson@14268
  1145
  apply (rule classical) 
paulson@14268
  1146
  apply (subgoal_tac "a < 0") 
paulson@14268
  1147
   prefer 2 apply (force simp add: linorder_not_le intro: order_less_trans) 
paulson@14268
  1148
  apply (insert inverse_le_imp_le [of "-b" "-a"])
paulson@14268
  1149
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1150
  done
paulson@14268
  1151
paulson@14268
  1152
lemma less_imp_inverse_less_neg:
paulson@14268
  1153
   "[|a < b; b < 0|] ==> inverse b < inverse (a::'a::ordered_field)"
paulson@14268
  1154
  apply (subgoal_tac "a < 0") 
paulson@14268
  1155
   prefer 2 apply (blast intro: order_less_trans) 
paulson@14268
  1156
  apply (insert less_imp_inverse_less [of "-b" "-a"])
paulson@14268
  1157
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1158
  done
paulson@14268
  1159
paulson@14268
  1160
lemma inverse_less_imp_less_neg:
paulson@14268
  1161
   "[|inverse a < inverse b; b < 0|] ==> b < (a::'a::ordered_field)"
paulson@14268
  1162
  apply (rule classical) 
paulson@14268
  1163
  apply (subgoal_tac "a < 0") 
paulson@14268
  1164
   prefer 2
paulson@14268
  1165
   apply (force simp add: linorder_not_less intro: order_le_less_trans) 
paulson@14268
  1166
  apply (insert inverse_less_imp_less [of "-b" "-a"])
paulson@14268
  1167
  apply (simp add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1168
  done
paulson@14268
  1169
paulson@14268
  1170
lemma inverse_less_iff_less_neg [simp]:
paulson@14268
  1171
     "[|a < 0; b < 0|] 
paulson@14268
  1172
      ==> (inverse a < inverse b) = (b < (a::'a::ordered_field))"
paulson@14268
  1173
  apply (insert inverse_less_iff_less [of "-b" "-a"])
paulson@14268
  1174
  apply (simp del: inverse_less_iff_less 
paulson@14268
  1175
	      add: order_less_imp_not_eq nonzero_inverse_minus_eq) 
paulson@14268
  1176
  done
paulson@14268
  1177
paulson@14268
  1178
lemma le_imp_inverse_le_neg:
paulson@14268
  1179
   "[|a \<le> b; b < 0|] ==> inverse b \<le> inverse (a::'a::ordered_field)"
paulson@14268
  1180
  by (force simp add: order_le_less less_imp_inverse_less_neg)
paulson@14268
  1181
paulson@14268
  1182
lemma inverse_le_iff_le_neg [simp]:
paulson@14268
  1183
     "[|a < 0; b < 0|] 
paulson@14268
  1184
      ==> (inverse a \<le> inverse b) = (b \<le> (a::'a::ordered_field))"
paulson@14268
  1185
by (blast intro: le_imp_inverse_le_neg dest: inverse_le_imp_le_neg) 
paulson@14265
  1186
paulson@14277
  1187
paulson@14365
  1188
subsection{*Inverses and the Number One*}
paulson@14365
  1189
paulson@14365
  1190
lemma one_less_inverse_iff:
paulson@14365
  1191
    "(1 < inverse x) = (0 < x & x < (1::'a::{ordered_field,division_by_zero}))"proof cases
paulson@14365
  1192
  assume "0 < x"
paulson@14365
  1193
    with inverse_less_iff_less [OF zero_less_one, of x]
paulson@14365
  1194
    show ?thesis by simp
paulson@14365
  1195
next
paulson@14365
  1196
  assume notless: "~ (0 < x)"
paulson@14365
  1197
  have "~ (1 < inverse x)"
paulson@14365
  1198
  proof
paulson@14365
  1199
    assume "1 < inverse x"
paulson@14365
  1200
    also with notless have "... \<le> 0" by (simp add: linorder_not_less)
paulson@14365
  1201
    also have "... < 1" by (rule zero_less_one) 
paulson@14365
  1202
    finally show False by auto
paulson@14365
  1203
  qed
paulson@14365
  1204
  with notless show ?thesis by simp
paulson@14365
  1205
qed
paulson@14365
  1206
paulson@14365
  1207
lemma inverse_eq_1_iff [simp]:
paulson@14365
  1208
    "(inverse x = 1) = (x = (1::'a::{field,division_by_zero}))"
paulson@14365
  1209
by (insert inverse_eq_iff_eq [of x 1], simp) 
paulson@14365
  1210
paulson@14365
  1211
lemma one_le_inverse_iff:
paulson@14365
  1212
   "(1 \<le> inverse x) = (0 < x & x \<le> (1::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1213
by (force simp add: order_le_less one_less_inverse_iff zero_less_one 
paulson@14365
  1214
                    eq_commute [of 1]) 
paulson@14365
  1215
paulson@14365
  1216
lemma inverse_less_1_iff:
paulson@14365
  1217
   "(inverse x < 1) = (x \<le> 0 | 1 < (x::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1218
by (simp add: linorder_not_le [symmetric] one_le_inverse_iff) 
paulson@14365
  1219
paulson@14365
  1220
lemma inverse_le_1_iff:
paulson@14365
  1221
   "(inverse x \<le> 1) = (x \<le> 0 | 1 \<le> (x::'a::{ordered_field,division_by_zero}))"
paulson@14365
  1222
by (simp add: linorder_not_less [symmetric] one_less_inverse_iff) 
paulson@14365
  1223
paulson@14365
  1224
paulson@14277
  1225
subsection{*Division and Signs*}
paulson@14277
  1226
paulson@14277
  1227
lemma zero_less_divide_iff:
paulson@14277
  1228
     "((0::'a::{ordered_field,division_by_zero}) < a/b) = (0 < a & 0 < b | a < 0 & b < 0)"
paulson@14430
  1229
by (simp add: divide_inverse zero_less_mult_iff)
paulson@14277
  1230
paulson@14277
  1231
lemma divide_less_0_iff:
paulson@14277
  1232
     "(a/b < (0::'a::{ordered_field,division_by_zero})) = 
paulson@14277
  1233
      (0 < a & b < 0 | a < 0 & 0 < b)"
paulson@14430
  1234
by (simp add: divide_inverse mult_less_0_iff)
paulson@14277
  1235
paulson@14277
  1236
lemma zero_le_divide_iff:
paulson@14277
  1237
     "((0::'a::{ordered_field,division_by_zero}) \<le> a/b) =
paulson@14277
  1238
      (0 \<le> a & 0 \<le> b | a \<le> 0 & b \<le> 0)"
paulson@14430
  1239
by (simp add: divide_inverse zero_le_mult_iff)
paulson@14277
  1240
paulson@14277
  1241
lemma divide_le_0_iff:
paulson@14288
  1242
     "(a/b \<le> (0::'a::{ordered_field,division_by_zero})) =
paulson@14288
  1243
      (0 \<le> a & b \<le> 0 | a \<le> 0 & 0 \<le> b)"
paulson@14430
  1244
by (simp add: divide_inverse mult_le_0_iff)
paulson@14277
  1245
paulson@14277
  1246
lemma divide_eq_0_iff [simp]:
paulson@14277
  1247
     "(a/b = 0) = (a=0 | b=(0::'a::{field,division_by_zero}))"
paulson@14430
  1248
by (simp add: divide_inverse field_mult_eq_0_iff)
paulson@14277
  1249
paulson@14288
  1250
paulson@14288
  1251
subsection{*Simplification of Inequalities Involving Literal Divisors*}
paulson@14288
  1252
paulson@14288
  1253
lemma pos_le_divide_eq: "0 < (c::'a::ordered_field) ==> (a \<le> b/c) = (a*c \<le> b)"
paulson@14288
  1254
proof -
paulson@14288
  1255
  assume less: "0<c"
paulson@14288
  1256
  hence "(a \<le> b/c) = (a*c \<le> (b/c)*c)"
paulson@14288
  1257
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1258
  also have "... = (a*c \<le> b)"
paulson@14288
  1259
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1260
  finally show ?thesis .
paulson@14288
  1261
qed
paulson@14288
  1262
paulson@14288
  1263
paulson@14288
  1264
lemma neg_le_divide_eq: "c < (0::'a::ordered_field) ==> (a \<le> b/c) = (b \<le> a*c)"
paulson@14288
  1265
proof -
paulson@14288
  1266
  assume less: "c<0"
paulson@14288
  1267
  hence "(a \<le> b/c) = ((b/c)*c \<le> a*c)"
paulson@14288
  1268
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1269
  also have "... = (b \<le> a*c)"
paulson@14288
  1270
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1271
  finally show ?thesis .
paulson@14288
  1272
qed
paulson@14288
  1273
paulson@14288
  1274
lemma le_divide_eq:
paulson@14288
  1275
  "(a \<le> b/c) = 
paulson@14288
  1276
   (if 0 < c then a*c \<le> b
paulson@14288
  1277
             else if c < 0 then b \<le> a*c
paulson@14288
  1278
             else  a \<le> (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1279
apply (case_tac "c=0", simp) 
paulson@14288
  1280
apply (force simp add: pos_le_divide_eq neg_le_divide_eq linorder_neq_iff) 
paulson@14288
  1281
done
paulson@14288
  1282
paulson@14288
  1283
lemma pos_divide_le_eq: "0 < (c::'a::ordered_field) ==> (b/c \<le> a) = (b \<le> a*c)"
paulson@14288
  1284
proof -
paulson@14288
  1285
  assume less: "0<c"
paulson@14288
  1286
  hence "(b/c \<le> a) = ((b/c)*c \<le> a*c)"
paulson@14288
  1287
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1288
  also have "... = (b \<le> a*c)"
paulson@14288
  1289
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1290
  finally show ?thesis .
paulson@14288
  1291
qed
paulson@14288
  1292
paulson@14288
  1293
lemma neg_divide_le_eq: "c < (0::'a::ordered_field) ==> (b/c \<le> a) = (a*c \<le> b)"
paulson@14288
  1294
proof -
paulson@14288
  1295
  assume less: "c<0"
paulson@14288
  1296
  hence "(b/c \<le> a) = (a*c \<le> (b/c)*c)"
paulson@14288
  1297
    by (simp add: mult_le_cancel_right order_less_not_sym [OF less])
paulson@14288
  1298
  also have "... = (a*c \<le> b)"
paulson@14288
  1299
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1300
  finally show ?thesis .
paulson@14288
  1301
qed
paulson@14288
  1302
paulson@14288
  1303
lemma divide_le_eq:
paulson@14288
  1304
  "(b/c \<le> a) = 
paulson@14288
  1305
   (if 0 < c then b \<le> a*c
paulson@14288
  1306
             else if c < 0 then a*c \<le> b
paulson@14288
  1307
             else 0 \<le> (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1308
apply (case_tac "c=0", simp) 
paulson@14288
  1309
apply (force simp add: pos_divide_le_eq neg_divide_le_eq linorder_neq_iff) 
paulson@14288
  1310
done
paulson@14288
  1311
paulson@14288
  1312
paulson@14288
  1313
lemma pos_less_divide_eq:
paulson@14288
  1314
     "0 < (c::'a::ordered_field) ==> (a < b/c) = (a*c < b)"
paulson@14288
  1315
proof -
paulson@14288
  1316
  assume less: "0<c"
paulson@14288
  1317
  hence "(a < b/c) = (a*c < (b/c)*c)"
paulson@15234
  1318
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1319
  also have "... = (a*c < b)"
paulson@14288
  1320
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1321
  finally show ?thesis .
paulson@14288
  1322
qed
paulson@14288
  1323
paulson@14288
  1324
lemma neg_less_divide_eq:
paulson@14288
  1325
 "c < (0::'a::ordered_field) ==> (a < b/c) = (b < a*c)"
paulson@14288
  1326
proof -
paulson@14288
  1327
  assume less: "c<0"
paulson@14288
  1328
  hence "(a < b/c) = ((b/c)*c < a*c)"
paulson@15234
  1329
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1330
  also have "... = (b < a*c)"
paulson@14288
  1331
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1332
  finally show ?thesis .
paulson@14288
  1333
qed
paulson@14288
  1334
paulson@14288
  1335
lemma less_divide_eq:
paulson@14288
  1336
  "(a < b/c) = 
paulson@14288
  1337
   (if 0 < c then a*c < b
paulson@14288
  1338
             else if c < 0 then b < a*c
paulson@14288
  1339
             else  a < (0::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1340
apply (case_tac "c=0", simp) 
paulson@14288
  1341
apply (force simp add: pos_less_divide_eq neg_less_divide_eq linorder_neq_iff) 
paulson@14288
  1342
done
paulson@14288
  1343
paulson@14288
  1344
lemma pos_divide_less_eq:
paulson@14288
  1345
     "0 < (c::'a::ordered_field) ==> (b/c < a) = (b < a*c)"
paulson@14288
  1346
proof -
paulson@14288
  1347
  assume less: "0<c"
paulson@14288
  1348
  hence "(b/c < a) = ((b/c)*c < a*c)"
paulson@15234
  1349
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1350
  also have "... = (b < a*c)"
paulson@14288
  1351
    by (simp add: order_less_imp_not_eq2 [OF less] divide_inverse mult_assoc) 
paulson@14288
  1352
  finally show ?thesis .
paulson@14288
  1353
qed
paulson@14288
  1354
paulson@14288
  1355
lemma neg_divide_less_eq:
paulson@14288
  1356
 "c < (0::'a::ordered_field) ==> (b/c < a) = (a*c < b)"
paulson@14288
  1357
proof -
paulson@14288
  1358
  assume less: "c<0"
paulson@14288
  1359
  hence "(b/c < a) = (a*c < (b/c)*c)"
paulson@15234
  1360
    by (simp add: mult_less_cancel_right_disj order_less_not_sym [OF less])
paulson@14288
  1361
  also have "... = (a*c < b)"
paulson@14288
  1362
    by (simp add: order_less_imp_not_eq [OF less] divide_inverse mult_assoc) 
paulson@14288
  1363
  finally show ?thesis .
paulson@14288
  1364
qed
paulson@14288
  1365
paulson@14288
  1366
lemma divide_less_eq:
paulson@14288
  1367
  "(b/c < a) = 
paulson@14288
  1368
   (if 0 < c then b < a*c
paulson@14288
  1369
             else if c < 0 then a*c < b
paulson@14288
  1370
             else 0 < (a::'a::{ordered_field,division_by_zero}))"
paulson@14288
  1371
apply (case_tac "c=0", simp) 
paulson@14288
  1372
apply (force simp add: pos_divide_less_eq neg_divide_less_eq linorder_neq_iff) 
paulson@14288
  1373
done
paulson@14288
  1374
paulson@14288
  1375
lemma nonzero_eq_divide_eq: "c\<noteq>0 ==> ((a::'a::field) = b/c) = (a*c = b)"
paulson@14288
  1376
proof -
paulson@14288
  1377
  assume [simp]: "c\<noteq>0"
paulson@14288
  1378
  have "(a = b/c) = (a*c = (b/c)*c)"
paulson@14288
  1379
    by (simp add: field_mult_cancel_right)
paulson@14288
  1380
  also have "... = (a*c = b)"
paulson@14288
  1381
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1382
  finally show ?thesis .
paulson@14288
  1383
qed
paulson@14288
  1384
paulson@14288
  1385
lemma eq_divide_eq:
paulson@14288
  1386
  "((a::'a::{field,division_by_zero}) = b/c) = (if c\<noteq>0 then a*c = b else a=0)"
paulson@14288
  1387
by (simp add: nonzero_eq_divide_eq) 
paulson@14288
  1388
paulson@14288
  1389
lemma nonzero_divide_eq_eq: "c\<noteq>0 ==> (b/c = (a::'a::field)) = (b = a*c)"
paulson@14288
  1390
proof -
paulson@14288
  1391
  assume [simp]: "c\<noteq>0"
paulson@14288
  1392
  have "(b/c = a) = ((b/c)*c = a*c)"
paulson@14288
  1393
    by (simp add: field_mult_cancel_right)
paulson@14288
  1394
  also have "... = (b = a*c)"
paulson@14288
  1395
    by (simp add: divide_inverse mult_assoc) 
paulson@14288
  1396
  finally show ?thesis .
paulson@14288
  1397
qed
paulson@14288
  1398
paulson@14288
  1399
lemma divide_eq_eq:
paulson@14288
  1400
  "(b/c = (a::'a::{field,division_by_zero})) = (if c\<noteq>0 then b = a*c else a=0)"
paulson@14288
  1401
by (force simp add: nonzero_divide_eq_eq) 
paulson@14288
  1402
paulson@15234
  1403
paulson@14288
  1404
subsection{*Cancellation Laws for Division*}
paulson@14288
  1405
paulson@14288
  1406
lemma divide_cancel_right [simp]:
paulson@14288
  1407
     "(a/c = b/c) = (c = 0 | a = (b::'a::{field,division_by_zero}))"
paulson@14288
  1408
apply (case_tac "c=0", simp) 
paulson@14430
  1409
apply (simp add: divide_inverse field_mult_cancel_right) 
paulson@14288
  1410
done
paulson@14288
  1411
paulson@14288
  1412
lemma divide_cancel_left [simp]:
paulson@14288
  1413
     "(c/a = c/b) = (c = 0 | a = (b::'a::{field,division_by_zero}))" 
paulson@14288
  1414
apply (case_tac "c=0", simp) 
paulson@14430
  1415
apply (simp add: divide_inverse field_mult_cancel_left) 
paulson@14288
  1416
done
paulson@14288
  1417
paulson@14353
  1418
subsection {* Division and the Number One *}
paulson@14353
  1419
paulson@14353
  1420
text{*Simplify expressions equated with 1*}
paulson@14353
  1421
lemma divide_eq_1_iff [simp]:
paulson@14353
  1422
     "(a/b = 1) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
paulson@14353
  1423
apply (case_tac "b=0", simp) 
paulson@14353
  1424
apply (simp add: right_inverse_eq) 
paulson@14353
  1425
done
paulson@14353
  1426
paulson@14353
  1427
paulson@14353
  1428
lemma one_eq_divide_iff [simp]:
paulson@14353
  1429
     "(1 = a/b) = (b \<noteq> 0 & a = (b::'a::{field,division_by_zero}))"
paulson@14353
  1430
by (simp add: eq_commute [of 1])  
paulson@14353
  1431
paulson@14353
  1432
lemma zero_eq_1_divide_iff [simp]:
paulson@14353
  1433
     "((0::'a::{ordered_field,division_by_zero}) = 1/a) = (a = 0)"
paulson@14353
  1434
apply (case_tac "a=0", simp) 
paulson@14353
  1435
apply (auto simp add: nonzero_eq_divide_eq) 
paulson@14353
  1436
done
paulson@14353
  1437
paulson@14353
  1438
lemma one_divide_eq_0_iff [simp]:
paulson@14353
  1439
     "(1/a = (0::'a::{ordered_field,division_by_zero})) = (a = 0)"
paulson@14353
  1440
apply (case_tac "a=0", simp) 
paulson@14353
  1441
apply (insert zero_neq_one [THEN not_sym]) 
paulson@14353
  1442
apply (auto simp add: nonzero_divide_eq_eq) 
paulson@14353
  1443
done
paulson@14353
  1444
paulson@14353
  1445
text{*Simplify expressions such as @{text "0 < 1/x"} to @{text "0 < x"}*}
paulson@14353
  1446
declare zero_less_divide_iff [of "1", simp]
paulson@14353
  1447
declare divide_less_0_iff [of "1", simp]
paulson@14353
  1448
declare zero_le_divide_iff [of "1", simp]
paulson@14353
  1449
declare divide_le_0_iff [of "1", simp]
paulson@14353
  1450
paulson@14288
  1451
paulson@14293
  1452
subsection {* Ordering Rules for Division *}
paulson@14293
  1453
paulson@14293
  1454
lemma divide_strict_right_mono:
paulson@14293
  1455
     "[|a < b; 0 < c|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1456
by (simp add: order_less_imp_not_eq2 divide_inverse mult_strict_right_mono 
paulson@14293
  1457
              positive_imp_inverse_positive) 
paulson@14293
  1458
paulson@14293
  1459
lemma divide_right_mono:
paulson@14293
  1460
     "[|a \<le> b; 0 \<le> c|] ==> a/c \<le> b/(c::'a::{ordered_field,division_by_zero})"
paulson@14293
  1461
  by (force simp add: divide_strict_right_mono order_le_less) 
paulson@14293
  1462
paulson@14293
  1463
paulson@14293
  1464
text{*The last premise ensures that @{term a} and @{term b} 
paulson@14293
  1465
      have the same sign*}
paulson@14293
  1466
lemma divide_strict_left_mono:
paulson@14293
  1467
       "[|b < a; 0 < c; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
paulson@14293
  1468
by (force simp add: zero_less_mult_iff divide_inverse mult_strict_left_mono 
paulson@14293
  1469
      order_less_imp_not_eq order_less_imp_not_eq2  
paulson@14293
  1470
      less_imp_inverse_less less_imp_inverse_less_neg) 
paulson@14293
  1471
paulson@14293
  1472
lemma divide_left_mono:
paulson@14293
  1473
     "[|b \<le> a; 0 \<le> c; 0 < a*b|] ==> c / a \<le> c / (b::'a::ordered_field)"
paulson@14293
  1474
  apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
paulson@14293
  1475
   prefer 2 
paulson@14293
  1476
   apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
paulson@14293
  1477
  apply (case_tac "c=0", simp add: divide_inverse)
paulson@14293
  1478
  apply (force simp add: divide_strict_left_mono order_le_less) 
paulson@14293
  1479
  done
paulson@14293
  1480
paulson@14293
  1481
lemma divide_strict_left_mono_neg:
paulson@14293
  1482
     "[|a < b; c < 0; 0 < a*b|] ==> c / a < c / (b::'a::ordered_field)"
paulson@14293
  1483
  apply (subgoal_tac "a \<noteq> 0 & b \<noteq> 0") 
paulson@14293
  1484
   prefer 2 
paulson@14293
  1485
   apply (force simp add: zero_less_mult_iff order_less_imp_not_eq) 
paulson@14293
  1486
  apply (drule divide_strict_left_mono [of _ _ "-c"]) 
paulson@14293
  1487
   apply (simp_all add: mult_commute nonzero_minus_divide_left [symmetric]) 
paulson@14293
  1488
  done
paulson@14293
  1489
paulson@14293
  1490
lemma divide_strict_right_mono_neg:
paulson@14293
  1491
     "[|b < a; c < 0|] ==> a / c < b / (c::'a::ordered_field)"
paulson@14293
  1492
apply (drule divide_strict_right_mono [of _ _ "-c"], simp) 
paulson@14293
  1493
apply (simp add: order_less_imp_not_eq nonzero_minus_divide_right [symmetric]) 
paulson@14293
  1494
done
paulson@14293
  1495
paulson@14293
  1496
paulson@14293
  1497
subsection {* Ordered Fields are Dense *}
paulson@14293
  1498
obua@14738
  1499
lemma less_add_one: "a < (a+1::'a::ordered_semidom)"
paulson@14293
  1500
proof -
obua@14738
  1501
  have "a+0 < (a+1::'a::ordered_semidom)"
paulson@14365
  1502
    by (blast intro: zero_less_one add_strict_left_mono) 
paulson@14293
  1503
  thus ?thesis by simp
paulson@14293
  1504
qed
paulson@14293
  1505
obua@14738
  1506
lemma zero_less_two: "0 < (1+1::'a::ordered_semidom)"
paulson@14365
  1507
  by (blast intro: order_less_trans zero_less_one less_add_one) 
paulson@14365
  1508
paulson@14293
  1509
lemma less_half_sum: "a < b ==> a < (a+b) / (1+1::'a::ordered_field)"
paulson@14293
  1510
by (simp add: zero_less_two pos_less_divide_eq right_distrib) 
paulson@14293
  1511
paulson@14293
  1512
lemma gt_half_sum: "a < b ==> (a+b)/(1+1::'a::ordered_field) < b"
paulson@14293
  1513
by (simp add: zero_less_two pos_divide_less_eq right_distrib) 
paulson@14293
  1514
paulson@14293
  1515
lemma dense: "a < b ==> \<exists>r::'a::ordered_field. a < r & r < b"
paulson@14293
  1516
by (blast intro!: less_half_sum gt_half_sum)
paulson@14293
  1517
paulson@15234
  1518
paulson@15234
  1519
lemmas times_divide_eq = times_divide_eq_right times_divide_eq_left
paulson@15234
  1520
paulson@15234
  1521
text{*It's not obvious whether these should be simprules or not. 
paulson@15234
  1522
  Their effect is to gather terms into one big fraction, like
paulson@15234
  1523
  a*b*c / x*y*z. The rationale for that is unclear, but many proofs 
paulson@15234
  1524
  seem to need them.*}
paulson@15234
  1525
paulson@15234
  1526
declare times_divide_eq [simp]
paulson@15234
  1527
paulson@15234
  1528
paulson@14293
  1529
subsection {* Absolute Value *}
paulson@14293
  1530
obua@14738
  1531
lemma abs_one [simp]: "abs 1 = (1::'a::ordered_idom)"
paulson@14294
  1532
  by (simp add: abs_if zero_less_one [THEN order_less_not_sym]) 
paulson@14294
  1533
obua@14738
  1534
lemma abs_le_mult: "abs (a * b) \<le> (abs a) * (abs (b::'a::lordered_ring))" 
obua@14738
  1535
proof -
obua@14738
  1536
  let ?x = "pprt a * pprt b - pprt a * nprt b - nprt a * pprt b + nprt a * nprt b"
obua@14738
  1537
  let ?y = "pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
obua@14738
  1538
  have a: "(abs a) * (abs b) = ?x"
obua@14738
  1539
    by (simp only: abs_prts[of a] abs_prts[of b] ring_eq_simps)
obua@14738
  1540
  {
obua@14738
  1541
    fix u v :: 'a
paulson@15481
  1542
    have bh: "\<lbrakk>u = a; v = b\<rbrakk> \<Longrightarrow> 
paulson@15481
  1543
              u * v = pprt a * pprt b + pprt a * nprt b + 
paulson@15481
  1544
                      nprt a * pprt b + nprt a * nprt b"
obua@14738
  1545
      apply (subst prts[of u], subst prts[of v])
obua@14738
  1546
      apply (simp add: left_distrib right_distrib add_ac) 
obua@14738
  1547
      done
obua@14738
  1548
  }
obua@14738
  1549
  note b = this[OF refl[of a] refl[of b]]
obua@14738
  1550
  note addm = add_mono[of "0::'a" _ "0::'a", simplified]
obua@14738
  1551
  note addm2 = add_mono[of _ "0::'a" _ "0::'a", simplified]
obua@14738
  1552
  have xy: "- ?x <= ?y"
obua@14754
  1553
    apply (simp)
obua@14754
  1554
    apply (rule_tac y="0::'a" in order_trans)
obua@14754
  1555
    apply (rule addm2)+
obua@14754
  1556
    apply (simp_all add: mult_pos_le mult_neg_le)
obua@14754
  1557
    apply (rule addm)+
obua@14754
  1558
    apply (simp_all add: mult_pos_le mult_neg_le)
obua@14754
  1559
    done
obua@14738
  1560
  have yx: "?y <= ?x"
obua@14738
  1561
    apply (simp add: add_ac)
obua@14754
  1562
    apply (rule_tac y=0 in order_trans)
obua@14754
  1563
    apply (rule addm2, (simp add: mult_pos_neg_le mult_pos_neg2_le)+)
obua@14754
  1564
    apply (rule addm, (simp add: mult_pos_neg_le mult_pos_neg2_le)+)
obua@14738
  1565
    done
obua@14738
  1566
  have i1: "a*b <= abs a * abs b" by (simp only: a b yx)
obua@14738
  1567
  have i2: "- (abs a * abs b) <= a*b" by (simp only: a b xy)
obua@14738
  1568
  show ?thesis
obua@14738
  1569
    apply (rule abs_leI)
obua@14738
  1570
    apply (simp add: i1)
obua@14738
  1571
    apply (simp add: i2[simplified minus_le_iff])
obua@14738
  1572
    done
obua@14738
  1573
qed
paulson@14294
  1574
obua@14738
  1575
lemma abs_eq_mult: 
obua@14738
  1576
  assumes "(0 \<le> a \<or> a \<le> 0) \<and> (0 \<le> b \<or> b \<le> 0)"
obua@14738
  1577
  shows "abs (a*b) = abs a * abs (b::'a::lordered_ring)"
obua@14738
  1578
proof -
obua@14738
  1579
  have s: "(0 <= a*b) | (a*b <= 0)"
obua@14738
  1580
    apply (auto)    
obua@14738
  1581
    apply (rule_tac split_mult_pos_le)
obua@14738
  1582
    apply (rule_tac contrapos_np[of "a*b <= 0"])
obua@14738
  1583
    apply (simp)
obua@14738
  1584
    apply (rule_tac split_mult_neg_le)
obua@14738
  1585
    apply (insert prems)
obua@14738
  1586
    apply (blast)
obua@14738
  1587
    done
obua@14738
  1588
  have mulprts: "a * b = (pprt a + nprt a) * (pprt b + nprt b)"
obua@14738
  1589
    by (simp add: prts[symmetric])
obua@14738
  1590
  show ?thesis
obua@14738
  1591
  proof cases
obua@14738
  1592
    assume "0 <= a * b"
obua@14738
  1593
    then show ?thesis
obua@14738
  1594
      apply (simp_all add: mulprts abs_prts)
obua@14738
  1595
      apply (insert prems)
obua@14754
  1596
      apply (auto simp add: 
obua@14754
  1597
	ring_eq_simps 
obua@14754
  1598
	iff2imp[OF zero_le_iff_zero_nprt] iff2imp[OF le_zero_iff_zero_pprt]
nipkow@15197
  1599
	iff2imp[OF le_zero_iff_pprt_id] iff2imp[OF zero_le_iff_nprt_id])
nipkow@15197
  1600
	apply(drule (1) mult_pos_neg_le[of a b], simp)
nipkow@15197
  1601
	apply(drule (1) mult_pos_neg2_le[of b a], simp)
obua@14738
  1602
      done
obua@14738
  1603
  next
obua@14738
  1604
    assume "~(0 <= a*b)"
obua@14738
  1605
    with s have "a*b <= 0" by simp
obua@14738
  1606
    then show ?thesis
obua@14738
  1607
      apply (simp_all add: mulprts abs_prts)
obua@14738
  1608
      apply (insert prems)
obua@15580
  1609
      apply (auto simp add: ring_eq_simps)
nipkow@15197
  1610
      apply(drule (1) mult_pos_le[of a b],simp)
nipkow@15197
  1611
      apply(drule (1) mult_neg_le[of a b],simp)
obua@14738
  1612
      done
obua@14738
  1613
  qed
obua@14738
  1614
qed
paulson@14294
  1615
obua@14738
  1616
lemma abs_mult: "abs (a * b) = abs a * abs (b::'a::ordered_idom)" 
obua@14738
  1617
by (simp add: abs_eq_mult linorder_linear)
paulson@14293
  1618
obua@14738
  1619
lemma abs_mult_self: "abs a * abs a = a * (a::'a::ordered_idom)"
obua@14738
  1620
by (simp add: abs_if) 
paulson@14294
  1621
paulson@14294
  1622
lemma nonzero_abs_inverse:
paulson@14294
  1623
     "a \<noteq> 0 ==> abs (inverse (a::'a::ordered_field)) = inverse (abs a)"
paulson@14294
  1624
apply (auto simp add: linorder_neq_iff abs_if nonzero_inverse_minus_eq 
paulson@14294
  1625
                      negative_imp_inverse_negative)
paulson@14294
  1626
apply (blast intro: positive_imp_inverse_positive elim: order_less_asym) 
paulson@14294
  1627
done
paulson@14294
  1628
paulson@14294
  1629
lemma abs_inverse [simp]:
paulson@14294
  1630
     "abs (inverse (a::'a::{ordered_field,division_by_zero})) = 
paulson@14294
  1631
      inverse (abs a)"
paulson@14294
  1632
apply (case_tac "a=0", simp) 
paulson@14294
  1633
apply (simp add: nonzero_abs_inverse) 
paulson@14294
  1634
done
paulson@14294
  1635
paulson@14294
  1636
lemma nonzero_abs_divide:
paulson@14294
  1637
     "b \<noteq> 0 ==> abs (a / (b::'a::ordered_field)) = abs a / abs b"
paulson@14294
  1638
by (simp add: divide_inverse abs_mult nonzero_abs_inverse) 
paulson@14294
  1639
paulson@15234
  1640
lemma abs_divide [simp]:
paulson@14294
  1641
     "abs (a / (b::'a::{ordered_field,division_by_zero})) = abs a / abs b"
paulson@14294
  1642
apply (case_tac "b=0", simp) 
paulson@14294
  1643
apply (simp add: nonzero_abs_divide) 
paulson@14294
  1644
done
paulson@14294
  1645
paulson@14294
  1646
lemma abs_mult_less:
obua@14738
  1647
     "[| abs a < c; abs b < d |] ==> abs a * abs b < c*(d::'a::ordered_idom)"
paulson@14294
  1648
proof -
paulson@14294
  1649
  assume ac: "abs a < c"
paulson@14294
  1650
  hence cpos: "0<c" by (blast intro: order_le_less_trans abs_ge_zero)
paulson@14294
  1651
  assume "abs b < d"
paulson@14294
  1652
  thus ?thesis by (simp add: ac cpos mult_strict_mono) 
paulson@14294
  1653
qed
paulson@14293
  1654
obua@14738
  1655
lemma eq_minus_self_iff: "(a = -a) = (a = (0::'a::ordered_idom))"
obua@14738
  1656
by (force simp add: order_eq_iff le_minus_self_iff minus_le_self_iff)
obua@14738
  1657
obua@14738
  1658
lemma less_minus_self_iff: "(a < -a) = (a < (0::'a::ordered_idom))"
obua@14738
  1659
by (simp add: order_less_le le_minus_self_iff eq_minus_self_iff)
obua@14738
  1660
obua@14738
  1661
lemma abs_less_iff: "(abs a < b) = (a < b & -a < (b::'a::ordered_idom))" 
obua@14738
  1662
apply (simp add: order_less_le abs_le_iff)  
obua@14738
  1663
apply (auto simp add: abs_if minus_le_self_iff eq_minus_self_iff)
obua@14738
  1664
apply (simp add: le_minus_self_iff linorder_neq_iff) 
obua@14738
  1665
done
obua@14738
  1666
obua@15178
  1667
lemma linprog_dual_estimate:
obua@15178
  1668
  assumes
obua@15178
  1669
  "A * x \<le> (b::'a::lordered_ring)"
obua@15178
  1670
  "0 \<le> y"
obua@15178
  1671
  "abs (A - A') \<le> \<delta>A"
obua@15178
  1672
  "b \<le> b'"
obua@15178
  1673
  "abs (c - c') \<le> \<delta>c"
obua@15178
  1674
  "abs x \<le> r"
obua@15178
  1675
  shows
obua@15178
  1676
  "c * x \<le> y * b' + (y * \<delta>A + abs (y * A' - c') + \<delta>c) * r"
obua@15178
  1677
proof -
obua@15178
  1678
  from prems have 1: "y * b <= y * b'" by (simp add: mult_left_mono)
obua@15178
  1679
  from prems have 2: "y * (A * x) <= y * b" by (simp add: mult_left_mono) 
obua@15178
  1680
  have 3: "y * (A * x) = c * x + (y * (A - A') + (y * A' - c') + (c'-c)) * x" by (simp add: ring_eq_simps)  
obua@15178
  1681
  from 1 2 3 have 4: "c * x + (y * (A - A') + (y * A' - c') + (c'-c)) * x <= y * b'" by simp
obua@15178
  1682
  have 5: "c * x <= y * b' + abs((y * (A - A') + (y * A' - c') + (c'-c)) * x)"
obua@15178
  1683
    by (simp only: 4 estimate_by_abs)  
obua@15178
  1684
  have 6: "abs((y * (A - A') + (y * A' - c') + (c'-c)) * x) <= abs (y * (A - A') + (y * A' - c') + (c'-c)) * abs x"
obua@15178
  1685
    by (simp add: abs_le_mult)
obua@15178
  1686
  have 7: "(abs (y * (A - A') + (y * A' - c') + (c'-c))) * abs x <= (abs (y * (A-A') + (y*A'-c')) + abs(c'-c)) * abs x"
obua@15178
  1687
    by (simp add: abs_triangle_ineq mult_right_mono)
obua@15178
  1688
  have 8: " (abs (y * (A-A') + (y*A'-c')) + abs(c'-c)) * abs x <=  (abs (y * (A-A')) + abs (y*A'-c') + abs(c'-c)) * abs x"
obua@15178
  1689
    by (simp add: abs_triangle_ineq mult_right_mono)    
obua@15178
  1690
  have 9: "(abs (y * (A-A')) + abs (y*A'-c') + abs(c'-c)) * abs x <= (abs y * abs (A-A') + abs (y*A'-c') + abs (c'-c)) * abs x"
obua@15178
  1691
    by (simp add: abs_le_mult mult_right_mono)  
obua@15178
  1692
  have 10: "c'-c = -(c-c')" by (simp add: ring_eq_simps)
obua@15178
  1693
  have 11: "abs (c'-c) = abs (c-c')" 
obua@15178
  1694
    by (subst 10, subst abs_minus_cancel, simp)
obua@15178
  1695
  have 12: "(abs y * abs (A-A') + abs (y*A'-c') + abs (c'-c)) * abs x <= (abs y * abs (A-A') + abs (y*A'-c') + \<delta>c) * abs x"
obua@15178
  1696
    by (simp add: 11 prems mult_right_mono)
obua@15178
  1697
  have 13: "(abs y * abs (A-A') + abs (y*A'-c') + \<delta>c) * abs x <= (abs y * \<delta>A + abs (y*A'-c') + \<delta>c) * abs x"
obua@15178
  1698
    by (simp add: prems mult_right_mono mult_left_mono)  
obua@15178
  1699
  have r: "(abs y * \<delta>A + abs (y*A'-c') + \<delta>c) * abs x <=  (abs y * \<delta>A + abs (y*A'-c') + \<delta>c) * r"
obua@15178
  1700
    apply (rule mult_left_mono)
obua@15178
  1701
    apply (simp add: prems)
obua@15178
  1702
    apply (rule_tac add_mono[of "0::'a" _ "0", simplified])+
obua@15178
  1703
    apply (rule mult_left_mono[of "0" "\<delta>A", simplified])
obua@15178
  1704
    apply (simp_all)
obua@15178
  1705
    apply (rule order_trans[where y="abs (A-A')"], simp_all add: prems)
obua@15178
  1706
    apply (rule order_trans[where y="abs (c-c')"], simp_all add: prems)
obua@15178
  1707
    done    
obua@15178
  1708
  from 6 7 8 9 12 13 r have 14:" abs((y * (A - A') + (y * A' - c') + (c'-c)) * x) <=(abs y * \<delta>A + abs (y*A'-c') + \<delta>c) * r"     
obua@15178
  1709
    by (simp)
obua@15178
  1710
  show ?thesis 
obua@15178
  1711
    apply (rule_tac le_add_right_mono[of _ _ "abs((y * (A - A') + (y * A' - c') + (c'-c)) * x)"])
obua@15178
  1712
    apply (simp_all add: 5 14[simplified abs_of_ge_0[of y, simplified prems]])
obua@15178
  1713
    done
obua@15178
  1714
qed
obua@15178
  1715
obua@15178
  1716
lemma le_ge_imp_abs_diff_1:
obua@15178
  1717
  assumes
obua@15178
  1718
  "A1 <= (A::'a::lordered_ring)"
obua@15178
  1719
  "A <= A2" 
obua@15178
  1720
  shows "abs (A-A1) <= A2-A1"
obua@15178
  1721
proof -
obua@15178
  1722
  have "0 <= A - A1"    
obua@15178
  1723
  proof -
obua@15178
  1724
    have 1: "A - A1 = A + (- A1)" by simp
obua@15178
  1725
    show ?thesis by (simp only: 1 add_right_mono[of A1 A "-A1", simplified, simplified prems])
obua@15178
  1726
  qed
obua@15178
  1727
  then have "abs (A-A1) = A-A1" by (rule abs_of_ge_0)
obua@15178
  1728
  with prems show "abs (A-A1) <= (A2-A1)" by simp
obua@15178
  1729
qed
obua@15178
  1730
obua@15580
  1731
lemma mult_le_prts:
obua@15580
  1732
  assumes
obua@15580
  1733
  "a1 <= (a::'a::lordered_ring)"
obua@15580
  1734
  "a <= a2"
obua@15580
  1735
  "b1 <= b"
obua@15580
  1736
  "b <= b2"
obua@15580
  1737
  shows
obua@15580
  1738
  "a * b <= pprt a2 * pprt b2 + pprt a1 * nprt b2 + nprt a2 * pprt b1 + nprt a1 * nprt b1"
obua@15580
  1739
proof - 
obua@15580
  1740
  have "a * b = (pprt a + nprt a) * (pprt b + nprt b)" 
obua@15580
  1741
    apply (subst prts[symmetric])+
obua@15580
  1742
    apply simp
obua@15580
  1743
    done
obua@15580
  1744
  then have "a * b = pprt a * pprt b + pprt a * nprt b + nprt a * pprt b + nprt a * nprt b"
obua@15580
  1745
    by (simp add: ring_eq_simps)
obua@15580
  1746
  moreover have "pprt a * pprt b <= pprt a2 * pprt b2"
obua@15580
  1747
    by (simp_all add: prems mult_mono)
obua@15580
  1748
  moreover have "pprt a * nprt b <= pprt a1 * nprt b2"
obua@15580
  1749
  proof -
obua@15580
  1750
    have "pprt a * nprt b <= pprt a * nprt b2"
obua@15580
  1751
      by (simp add: mult_left_mono prems)
obua@15580
  1752
    moreover have "pprt a * nprt b2 <= pprt a1 * nprt b2"
obua@15580
  1753
      by (simp add: mult_right_mono_neg prems)
obua@15580
  1754
    ultimately show ?thesis
obua@15580
  1755
      by simp
obua@15580
  1756
  qed
obua@15580
  1757
  moreover have "nprt a * pprt b <= nprt a2 * pprt b1"
obua@15580
  1758
  proof - 
obua@15580
  1759
    have "nprt a * pprt b <= nprt a2 * pprt b"
obua@15580
  1760
      by (simp add: mult_right_mono prems)
obua@15580
  1761
    moreover have "nprt a2 * pprt b <= nprt a2 * pprt b1"
obua@15580
  1762
      by (simp add: mult_left_mono_neg prems)
obua@15580
  1763
    ultimately show ?thesis
obua@15580
  1764
      by simp
obua@15580
  1765
  qed
obua@15580
  1766
  moreover have "nprt a * nprt b <= nprt a1 * nprt b1"
obua@15580
  1767
  proof -
obua@15580
  1768
    have "nprt a * nprt b <= nprt a * nprt b1"
obua@15580
  1769
      by (simp add: mult_left_mono_neg prems)
obua@15580
  1770
    moreover have "nprt a * nprt b1 <= nprt a1 * nprt b1"
obua@15580
  1771
      by (simp add: mult_right_mono_neg prems)
obua@15580
  1772
    ultimately show ?thesis
obua@15580
  1773
      by simp
obua@15580
  1774
  qed
obua@15580
  1775
  ultimately show ?thesis
obua@15580
  1776
    by - (rule add_mono | simp)+
obua@15580
  1777
qed
obua@15580
  1778
    
obua@15580
  1779
lemma mult_le_dual_prts: 
obua@15178
  1780
  assumes
obua@15178
  1781
  "A * x \<le> (b::'a::lordered_ring)"
obua@15178
  1782
  "0 \<le> y"
obua@15580
  1783
  "A1 \<le> A"
obua@15580
  1784
  "A \<le> A2"
obua@15580
  1785
  "c1 \<le> c"
obua@15580
  1786
  "c \<le> c2"
obua@15580
  1787
  "r1 \<le> x"
obua@15580
  1788
  "x \<le> r2"
obua@15178
  1789
  shows
obua@15580
  1790
  "c * x \<le> y * b + (let s1 = c1 - y * A2; s2 = c2 - y * A1 in pprt s2 * pprt r2 + pprt s1 * nprt r2 + nprt s2 * pprt r1 + nprt s1 * nprt r1)"
obua@15580
  1791
  (is "_ <= _ + ?C")
obua@15178
  1792
proof -
obua@15580
  1793
  from prems have "y * (A * x) <= y * b" by (simp add: mult_left_mono) 
obua@15580
  1794
  moreover have "y * (A * x) = c * x + (y * A - c) * x" by (simp add: ring_eq_simps)  
obua@15580
  1795
  ultimately have "c * x + (y * A - c) * x <= y * b" by simp
obua@15580
  1796
  then have "c * x <= y * b - (y * A - c) * x" by (simp add: le_diff_eq)
obua@15580
  1797
  then have cx: "c * x <= y * b + (c - y * A) * x" by (simp add: ring_eq_simps)
obua@15580
  1798
  have s2: "c - y * A <= c2 - y * A1"
obua@15580
  1799
    by (simp add: diff_def prems add_mono mult_left_mono)
obua@15580
  1800
  have s1: "c1 - y * A2 <= c - y * A"
obua@15580
  1801
    by (simp add: diff_def prems add_mono mult_left_mono)
obua@15580
  1802
  have prts: "(c - y * A) * x <= ?C"
obua@15580
  1803
    apply (simp add: Let_def)
obua@15580
  1804
    apply (rule mult_le_prts)
obua@15580
  1805
    apply (simp_all add: prems s1 s2)
obua@15178
  1806
    done
obua@15580
  1807
  then have "y * b + (c - y * A) * x <= y * b + ?C"
obua@15580
  1808
    by simp
obua@15580
  1809
  with cx show ?thesis
obua@15580
  1810
    by(simp only:)
obua@15178
  1811
qed
obua@15178
  1812
obua@14738
  1813
ML {*
paulson@14334
  1814
val left_distrib = thm "left_distrib";
obua@14738
  1815
val right_distrib = thm "right_distrib";
obua@14738
  1816
val mult_commute = thm "mult_commute";
obua@14738
  1817
val distrib = thm "distrib";
obua@14738
  1818
val zero_neq_one = thm "zero_neq_one";
obua@14738
  1819
val no_zero_divisors = thm "no_zero_divisors";
paulson@14331
  1820
val left_inverse = thm "left_inverse";
obua@14738
  1821
val divide_inverse = thm "divide_inverse";
obua@14738
  1822
val mult_zero_left = thm "mult_zero_left";
obua@14738
  1823
val mult_zero_right = thm "mult_zero_right";
obua@14738
  1824
val field_mult_eq_0_iff = thm "field_mult_eq_0_iff";
obua@14738
  1825
val inverse_zero = thm "inverse_zero";
obua@14738
  1826
val ring_distrib = thms "ring_distrib";
obua@14738
  1827
val combine_common_factor = thm "combine_common_factor";
obua@14738
  1828
val minus_mult_left = thm "minus_mult_left";
obua@14738
  1829
val minus_mult_right = thm "minus_mult_right";
obua@14738
  1830
val minus_mult_minus = thm "minus_mult_minus";
obua@14738
  1831
val minus_mult_commute = thm "minus_mult_commute";
obua@14738
  1832
val right_diff_distrib = thm "right_diff_distrib";
obua@14738
  1833
val left_diff_distrib = thm "left_diff_distrib";
obua@14738
  1834
val mult_left_mono = thm "mult_left_mono";
obua@14738
  1835
val mult_right_mono = thm "mult_right_mono";
obua@14738
  1836
val mult_strict_left_mono = thm "mult_strict_left_mono";
obua@14738
  1837
val mult_strict_right_mono = thm "mult_strict_right_mono";
obua@14738
  1838
val mult_mono = thm "mult_mono";
obua@14738
  1839
val mult_strict_mono = thm "mult_strict_mono";
obua@14738
  1840
val abs_if = thm "abs_if";
obua@14738
  1841
val zero_less_one = thm "zero_less_one";
obua@14738
  1842
val eq_add_iff1 = thm "eq_add_iff1";
obua@14738
  1843
val eq_add_iff2 = thm "eq_add_iff2";
obua@14738
  1844
val less_add_iff1 = thm "less_add_iff1";
obua@14738
  1845
val less_add_iff2 = thm "less_add_iff2";
obua@14738
  1846
val le_add_iff1 = thm "le_add_iff1";
obua@14738
  1847
val le_add_iff2 = thm "le_add_iff2";
obua@14738
  1848
val mult_left_le_imp_le = thm "mult_left_le_imp_le";
obua@14738
  1849
val mult_right_le_imp_le = thm "mult_right_le_imp_le";
obua@14738
  1850
val mult_left_less_imp_less = thm "mult_left_less_imp_less";
obua@14738
  1851
val mult_right_less_imp_less = thm "mult_right_less_imp_less";
obua@14738
  1852
val mult_strict_left_mono_neg = thm "mult_strict_left_mono_neg";
obua@14738
  1853
val mult_left_mono_neg = thm "mult_left_mono_neg";
obua@14738
  1854
val mult_strict_right_mono_neg = thm "mult_strict_right_mono_neg";
obua@14738
  1855
val mult_right_mono_neg = thm "mult_right_mono_neg";
obua@14738
  1856
val mult_pos = thm "mult_pos";
obua@14738
  1857
val mult_pos_le = thm "mult_pos_le";
obua@14738
  1858
val mult_pos_neg = thm "mult_pos_neg";
obua@14738
  1859
val mult_pos_neg_le = thm "mult_pos_neg_le";
obua@14738
  1860
val mult_pos_neg2 = thm "mult_pos_neg2";
obua@14738
  1861
val mult_pos_neg2_le = thm "mult_pos_neg2_le";
obua@14738
  1862
val mult_neg = thm "mult_neg";
obua@14738
  1863
val mult_neg_le = thm "mult_neg_le";
obua@14738
  1864
val zero_less_mult_pos = thm "zero_less_mult_pos";
obua@14738
  1865
val zero_less_mult_pos2 = thm "zero_less_mult_pos2";
obua@14738
  1866
val zero_less_mult_iff = thm "zero_less_mult_iff";
obua@14738
  1867
val mult_eq_0_iff = thm "mult_eq_0_iff";
obua@14738
  1868
val zero_le_mult_iff = thm "zero_le_mult_iff";
obua@14738
  1869
val mult_less_0_iff = thm "mult_less_0_iff";
obua@14738
  1870
val mult_le_0_iff = thm "mult_le_0_iff";
obua@14738
  1871
val split_mult_pos_le = thm "split_mult_pos_le";
obua@14738
  1872
val split_mult_neg_le = thm "split_mult_neg_le";
obua@14738
  1873
val zero_le_square = thm "zero_le_square";
obua@14738
  1874
val zero_le_one = thm "zero_le_one";
obua@14738
  1875
val not_one_le_zero = thm "not_one_le_zero";
obua@14738
  1876
val not_one_less_zero = thm "not_one_less_zero";
obua@14738
  1877
val mult_left_mono_neg = thm "mult_left_mono_neg";
obua@14738
  1878
val mult_right_mono_neg = thm "mult_right_mono_neg";
obua@14738
  1879
val mult_strict_mono = thm "mult_strict_mono";
obua@14738
  1880
val mult_strict_mono' = thm "mult_strict_mono'";
obua@14738
  1881
val mult_mono = thm "mult_mono";
obua@14738
  1882
val less_1_mult = thm "less_1_mult";
paulson@15234
  1883
val mult_less_cancel_right_disj = thm "mult_less_cancel_right_disj";
paulson@15234
  1884
val mult_less_cancel_left_disj = thm "mult_less_cancel_left_disj";
obua@14738
  1885
val mult_less_cancel_right = thm "mult_less_cancel_right";
obua@14738
  1886
val mult_less_cancel_left = thm "mult_less_cancel_left";
obua@14738
  1887
val mult_le_cancel_right = thm "mult_le_cancel_right";
obua@14738
  1888
val mult_le_cancel_left = thm "mult_le_cancel_left";
obua@14738
  1889
val mult_less_imp_less_left = thm "mult_less_imp_less_left";
obua@14738
  1890
val mult_less_imp_less_right = thm "mult_less_imp_less_right";
obua@14738
  1891
val mult_cancel_right = thm "mult_cancel_right";
obua@14738
  1892
val mult_cancel_left = thm "mult_cancel_left";
obua@14738
  1893
val ring_eq_simps = thms "ring_eq_simps";
obua@14738
  1894
val right_inverse = thm "right_inverse";
obua@14738
  1895
val right_inverse_eq = thm "right_inverse_eq";
obua@14738
  1896
val nonzero_inverse_eq_divide = thm "nonzero_inverse_eq_divide";
obua@14738
  1897
val divide_self = thm "divide_self";
obua@14738
  1898
val divide_zero = thm "divide_zero";
obua@14738
  1899
val divide_zero_left = thm "divide_zero_left";
obua@14738
  1900
val inverse_eq_divide = thm "inverse_eq_divide";
obua@14738
  1901
val add_divide_distrib = thm "add_divide_distrib";
obua@14738
  1902
val field_mult_eq_0_iff = thm "field_mult_eq_0_iff";
obua@14738
  1903
val field_mult_cancel_right_lemma = thm "field_mult_cancel_right_lemma";
obua@14738
  1904
val field_mult_cancel_right = thm "field_mult_cancel_right";
obua@14738
  1905
val field_mult_cancel_left = thm "field_mult_cancel_left";
obua@14738
  1906
val nonzero_imp_inverse_nonzero = thm "nonzero_imp_inverse_nonzero";
obua@14738
  1907
val inverse_zero_imp_zero = thm "inverse_zero_imp_zero";
obua@14738
  1908
val inverse_nonzero_imp_nonzero = thm "inverse_nonzero_imp_nonzero";
obua@14738
  1909
val inverse_nonzero_iff_nonzero = thm "inverse_nonzero_iff_nonzero";
obua@14738
  1910
val nonzero_inverse_minus_eq = thm "nonzero_inverse_minus_eq";
obua@14738
  1911
val inverse_minus_eq = thm "inverse_minus_eq";
obua@14738
  1912
val nonzero_inverse_eq_imp_eq = thm "nonzero_inverse_eq_imp_eq";
obua@14738
  1913
val inverse_eq_imp_eq = thm "inverse_eq_imp_eq";
obua@14738
  1914
val inverse_eq_iff_eq = thm "inverse_eq_iff_eq";
obua@14738
  1915
val nonzero_inverse_inverse_eq = thm "nonzero_inverse_inverse_eq";
obua@14738
  1916
val inverse_inverse_eq = thm "inverse_inverse_eq";
obua@14738
  1917
val inverse_1 = thm "inverse_1";
obua@14738
  1918
val nonzero_inverse_mult_distrib = thm "nonzero_inverse_mult_distrib";
obua@14738
  1919
val inverse_mult_distrib = thm "inverse_mult_distrib";
obua@14738
  1920
val inverse_add = thm "inverse_add";
obua@14738
  1921
val inverse_divide = thm "inverse_divide";
obua@14738
  1922
val nonzero_mult_divide_cancel_left = thm "nonzero_mult_divide_cancel_left";
obua@14738
  1923
val mult_divide_cancel_left = thm "mult_divide_cancel_left";
obua@14738
  1924
val nonzero_mult_divide_cancel_right = thm "nonzero_mult_divide_cancel_right";
obua@14738
  1925
val mult_divide_cancel_right = thm "mult_divide_cancel_right";
obua@14738
  1926
val mult_divide_cancel_eq_if = thm "mult_divide_cancel_eq_if";
obua@14738
  1927
val divide_1 = thm "divide_1";
obua@14738
  1928
val times_divide_eq_right = thm "times_divide_eq_right";
obua@14738
  1929
val times_divide_eq_left = thm "times_divide_eq_left";
obua@14738
  1930
val divide_divide_eq_right = thm "divide_divide_eq_right";
obua@14738
  1931
val divide_divide_eq_left = thm "divide_divide_eq_left";
obua@14738
  1932
val nonzero_minus_divide_left = thm "nonzero_minus_divide_left";
obua@14738
  1933
val nonzero_minus_divide_right = thm "nonzero_minus_divide_right";
obua@14738
  1934
val nonzero_minus_divide_divide = thm "nonzero_minus_divide_divide";
obua@14738
  1935
val minus_divide_left = thm "minus_divide_left";
obua@14738
  1936
val minus_divide_right = thm "minus_divide_right";
obua@14738
  1937
val minus_divide_divide = thm "minus_divide_divide";
obua@14738
  1938
val diff_divide_distrib = thm "diff_divide_distrib";
obua@14738
  1939
val positive_imp_inverse_positive = thm "positive_imp_inverse_positive";
obua@14738
  1940
val negative_imp_inverse_negative = thm "negative_imp_inverse_negative";
obua@14738
  1941
val inverse_le_imp_le = thm "inverse_le_imp_le";
obua@14738
  1942
val inverse_positive_imp_positive = thm "inverse_positive_imp_positive";
obua@14738
  1943
val inverse_positive_iff_positive = thm "inverse_positive_iff_positive";
obua@14738
  1944
val inverse_negative_imp_negative = thm "inverse_negative_imp_negative";
obua@14738
  1945
val inverse_negative_iff_negative = thm "inverse_negative_iff_negative";
obua@14738
  1946
val inverse_nonnegative_iff_nonnegative = thm "inverse_nonnegative_iff_nonnegative";
obua@14738
  1947
val inverse_nonpositive_iff_nonpositive = thm "inverse_nonpositive_iff_nonpositive";
obua@14738
  1948
val less_imp_inverse_less = thm "less_imp_inverse_less";
obua@14738
  1949
val inverse_less_imp_less = thm "inverse_less_imp_less";
obua@14738
  1950
val inverse_less_iff_less = thm "inverse_less_iff_less";
obua@14738
  1951
val le_imp_inverse_le = thm "le_imp_inverse_le";
obua@14738
  1952
val inverse_le_iff_le = thm "inverse_le_iff_le";
obua@14738
  1953
val inverse_le_imp_le_neg = thm "inverse_le_imp_le_neg";
obua@14738
  1954
val less_imp_inverse_less_neg = thm "less_imp_inverse_less_neg";
obua@14738
  1955
val inverse_less_imp_less_neg = thm "inverse_less_imp_less_neg";
obua@14738
  1956
val inverse_less_iff_less_neg = thm "inverse_less_iff_less_neg";
obua@14738
  1957
val le_imp_inverse_le_neg = thm "le_imp_inverse_le_neg";
obua@14738
  1958
val inverse_le_iff_le_neg = thm "inverse_le_iff_le_neg";
obua@14738
  1959
val one_less_inverse_iff = thm "one_less_inverse_iff";
obua@14738
  1960
val inverse_eq_1_iff = thm "inverse_eq_1_iff";
obua@14738
  1961
val one_le_inverse_iff = thm "one_le_inverse_iff";
obua@14738
  1962
val inverse_less_1_iff = thm "inverse_less_1_iff";
obua@14738
  1963
val inverse_le_1_iff = thm "inverse_le_1_iff";
obua@14738
  1964
val zero_less_divide_iff = thm "zero_less_divide_iff";
obua@14738
  1965
val divide_less_0_iff = thm "divide_less_0_iff";
obua@14738
  1966
val zero_le_divide_iff = thm "zero_le_divide_iff";
obua@14738
  1967
val divide_le_0_iff = thm "divide_le_0_iff";
obua@14738
  1968
val divide_eq_0_iff = thm "divide_eq_0_iff";
obua@14738
  1969
val pos_le_divide_eq = thm "pos_le_divide_eq";
obua@14738
  1970
val neg_le_divide_eq = thm "neg_le_divide_eq";
obua@14738
  1971
val le_divide_eq = thm "le_divide_eq";
obua@14738
  1972
val pos_divide_le_eq = thm "pos_divide_le_eq";
obua@14738
  1973
val neg_divide_le_eq = thm "neg_divide_le_eq";
obua@14738
  1974
val divide_le_eq = thm "divide_le_eq";
obua@14738
  1975
val pos_less_divide_eq = thm "pos_less_divide_eq";
obua@14738
  1976
val neg_less_divide_eq = thm "neg_less_divide_eq";
obua@14738
  1977
val less_divide_eq = thm "less_divide_eq";
obua@14738
  1978
val pos_divide_less_eq = thm "pos_divide_less_eq";
obua@14738
  1979
val neg_divide_less_eq = thm "neg_divide_less_eq";
obua@14738
  1980
val divide_less_eq = thm "divide_less_eq";
obua@14738
  1981
val nonzero_eq_divide_eq = thm "nonzero_eq_divide_eq";
obua@14738
  1982
val eq_divide_eq = thm "eq_divide_eq";
obua@14738
  1983
val nonzero_divide_eq_eq = thm "nonzero_divide_eq_eq";
obua@14738
  1984
val divide_eq_eq = thm "divide_eq_eq";
obua@14738
  1985
val divide_cancel_right = thm "divide_cancel_right";
obua@14738
  1986
val divide_cancel_left = thm "divide_cancel_left";
obua@14738
  1987
val divide_eq_1_iff = thm "divide_eq_1_iff";
obua@14738
  1988
val one_eq_divide_iff = thm "one_eq_divide_iff";
obua@14738
  1989
val zero_eq_1_divide_iff = thm "zero_eq_1_divide_iff";
obua@14738
  1990
val one_divide_eq_0_iff = thm "one_divide_eq_0_iff";
obua@14738
  1991
val divide_strict_right_mono = thm "divide_strict_right_mono";
obua@14738
  1992
val divide_right_mono = thm "divide_right_mono";
obua@14738
  1993
val divide_strict_left_mono = thm "divide_strict_left_mono";
obua@14738
  1994
val divide_left_mono = thm "divide_left_mono";
obua@14738
  1995
val divide_strict_left_mono_neg = thm "divide_strict_left_mono_neg";
obua@14738
  1996
val divide_strict_right_mono_neg = thm "divide_strict_right_mono_neg";
obua@14738
  1997
val less_add_one = thm "less_add_one";
obua@14738
  1998
val zero_less_two = thm "zero_less_two";
obua@14738
  1999
val less_half_sum = thm "less_half_sum";
obua@14738
  2000
val gt_half_sum = thm "gt_half_sum";
obua@14738
  2001
val dense = thm "dense";
obua@14738
  2002
val abs_one = thm "abs_one";
obua@14738
  2003
val abs_le_mult = thm "abs_le_mult";
obua@14738
  2004
val abs_eq_mult = thm "abs_eq_mult";
obua@14738
  2005
val abs_mult = thm "abs_mult";
obua@14738
  2006
val abs_mult_self = thm "abs_mult_self";
obua@14738
  2007
val nonzero_abs_inverse = thm "nonzero_abs_inverse";
obua@14738
  2008
val abs_inverse = thm "abs_inverse";
obua@14738
  2009
val nonzero_abs_divide = thm "nonzero_abs_divide";
obua@14738
  2010
val abs_divide = thm "abs_divide";
obua@14738
  2011
val abs_mult_less = thm "abs_mult_less";
obua@14738
  2012
val eq_minus_self_iff = thm "eq_minus_self_iff";
obua@14738
  2013
val less_minus_self_iff = thm "less_minus_self_iff";
obua@14738
  2014
val abs_less_iff = thm "abs_less_iff";
paulson@14331
  2015
*}
paulson@14331
  2016
paulson@14265
  2017
end