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