src/HOL/Word/Word_Miscellaneous.thy
author haftmann
Fri Oct 20 07:46:10 2017 +0200 (21 months ago)
changeset 66886 960509bfd47e
parent 66808 1907167b6038
child 67120 491fd7f0b5df
permissions -rw-r--r--
added lemmas and tuned proofs
wenzelm@65363
     1
(*  Title:      HOL/Word/Word_Miscellaneous.thy  *)
haftmann@53062
     2
wenzelm@61799
     3
section \<open>Miscellaneous lemmas, of at least doubtful value\<close>
haftmann@53062
     4
haftmann@53062
     5
theory Word_Miscellaneous
wenzelm@66453
     6
  imports "HOL-Library.Bit" Misc_Numeric
haftmann@53062
     7
begin
haftmann@53062
     8
wenzelm@65363
     9
lemma power_minus_simp: "0 < n \<Longrightarrow> a ^ n = a * a ^ (n - 1)"
haftmann@53062
    10
  by (auto dest: gr0_implies_Suc)
haftmann@53062
    11
wenzelm@65363
    12
lemma funpow_minus_simp: "0 < n \<Longrightarrow> f ^^ n = f \<circ> f ^^ (n - 1)"
haftmann@53062
    13
  by (auto dest: gr0_implies_Suc)
haftmann@53062
    14
wenzelm@65363
    15
lemma power_numeral: "a ^ numeral k = a * a ^ (pred_numeral k)"
haftmann@53062
    16
  by (simp add: numeral_eq_Suc)
haftmann@53062
    17
wenzelm@65363
    18
lemma funpow_numeral [simp]: "f ^^ numeral k = f \<circ> f ^^ (pred_numeral k)"
haftmann@53062
    19
  by (simp add: numeral_eq_Suc)
haftmann@53062
    20
wenzelm@65363
    21
lemma replicate_numeral [simp]: "replicate (numeral k) x = x # replicate (pred_numeral k) x"
haftmann@53062
    22
  by (simp add: numeral_eq_Suc)
haftmann@53062
    23
wenzelm@65363
    24
lemma rco_alt: "(f \<circ> g) ^^ n \<circ> f = f \<circ> (g \<circ> f) ^^ n"
haftmann@53062
    25
  apply (rule ext)
haftmann@53062
    26
  apply (induct n)
haftmann@53062
    27
   apply (simp_all add: o_def)
haftmann@53062
    28
  done
haftmann@53062
    29
haftmann@53062
    30
lemma list_exhaust_size_gt0:
haftmann@53062
    31
  assumes y: "\<And>a list. y = a # list \<Longrightarrow> P"
haftmann@53062
    32
  shows "0 < length y \<Longrightarrow> P"
wenzelm@65363
    33
  apply (cases y)
wenzelm@65363
    34
   apply simp
haftmann@53062
    35
  apply (rule y)
haftmann@53062
    36
  apply fastforce
haftmann@53062
    37
  done
haftmann@53062
    38
haftmann@53062
    39
lemma list_exhaust_size_eq0:
haftmann@53062
    40
  assumes y: "y = [] \<Longrightarrow> P"
haftmann@53062
    41
  shows "length y = 0 \<Longrightarrow> P"
haftmann@53062
    42
  apply (cases y)
wenzelm@65363
    43
   apply (rule y)
wenzelm@65363
    44
   apply simp
haftmann@53062
    45
  apply simp
haftmann@53062
    46
  done
haftmann@53062
    47
wenzelm@65363
    48
lemma size_Cons_lem_eq: "y = xa # list \<Longrightarrow> size y = Suc k \<Longrightarrow> size list = k"
haftmann@53062
    49
  by auto
haftmann@53062
    50
nipkow@62390
    51
lemmas ls_splits = prod.split prod.split_asm if_split_asm
haftmann@53062
    52
wenzelm@65363
    53
lemma not_B1_is_B0: "y \<noteq> 1 \<Longrightarrow> y = 0"
wenzelm@65363
    54
  for y :: bit
haftmann@53062
    55
  by (cases y) auto
haftmann@53062
    56
wenzelm@65363
    57
lemma B1_ass_B0:
wenzelm@65363
    58
  fixes y :: bit
wenzelm@65363
    59
  assumes y: "y = 0 \<Longrightarrow> y = 1"
wenzelm@65363
    60
  shows "y = 1"
haftmann@53062
    61
  apply (rule classical)
haftmann@53062
    62
  apply (drule not_B1_is_B0)
haftmann@53062
    63
  apply (erule y)
haftmann@53062
    64
  done
haftmann@53062
    65
wenzelm@61799
    66
\<comment> "simplifications for specific word lengths"
haftmann@53062
    67
lemmas n2s_ths [THEN eq_reflection] = add_2_eq_Suc add_2_eq_Suc'
haftmann@53062
    68
haftmann@53062
    69
lemmas s2n_ths = n2s_ths [symmetric]
haftmann@53062
    70
wenzelm@65363
    71
lemma and_len: "xs = ys \<Longrightarrow> xs = ys \<and> length xs = length ys"
haftmann@53062
    72
  by auto
haftmann@53062
    73
haftmann@53062
    74
lemma size_if: "size (if p then xs else ys) = (if p then size xs else size ys)"
haftmann@53062
    75
  by auto
haftmann@53062
    76
haftmann@53062
    77
lemma tl_if: "tl (if p then xs else ys) = (if p then tl xs else tl ys)"
haftmann@53062
    78
  by auto
haftmann@53062
    79
haftmann@53062
    80
lemma hd_if: "hd (if p then xs else ys) = (if p then hd xs else hd ys)"
haftmann@53062
    81
  by auto
haftmann@53062
    82
wenzelm@65363
    83
lemma if_Not_x: "(if p then \<not> x else x) = (p = (\<not> x))"
haftmann@53062
    84
  by auto
haftmann@53062
    85
wenzelm@65363
    86
lemma if_x_Not: "(if p then x else \<not> x) = (p = x)"
haftmann@53062
    87
  by auto
haftmann@53062
    88
wenzelm@65363
    89
lemma if_same_and: "(If p x y \<and> If p u v) = (if p then x \<and> u else y \<and> v)"
haftmann@53062
    90
  by auto
haftmann@53062
    91
wenzelm@65363
    92
lemma if_same_eq: "(If p x y  = (If p u v)) = (if p then x = u else y = v)"
haftmann@53062
    93
  by auto
haftmann@53062
    94
wenzelm@65363
    95
lemma if_same_eq_not: "(If p x y = (\<not> If p u v)) = (if p then x = (\<not> u) else y = (\<not> v))"
haftmann@53062
    96
  by auto
haftmann@53062
    97
haftmann@53062
    98
(* note - if_Cons can cause blowup in the size, if p is complex,
haftmann@53062
    99
  so make a simproc *)
haftmann@53062
   100
lemma if_Cons: "(if p then x # xs else y # ys) = If p x y # If p xs ys"
haftmann@53062
   101
  by auto
haftmann@53062
   102
wenzelm@65363
   103
lemma if_single: "(if xc then [xab] else [an]) = [if xc then xab else an]"
haftmann@53062
   104
  by auto
haftmann@53062
   105
haftmann@53062
   106
lemma if_bool_simps:
wenzelm@65363
   107
  "If p True y = (p \<or> y) \<and> If p False y = (\<not> p \<and> y) \<and>
wenzelm@65363
   108
    If p y True = (p \<longrightarrow> y) \<and> If p y False = (p \<and> y)"
haftmann@53062
   109
  by auto
haftmann@53062
   110
wenzelm@65363
   111
lemmas if_simps =
wenzelm@65363
   112
  if_x_Not if_Not_x if_cancel if_True if_False if_bool_simps
haftmann@53062
   113
haftmann@53062
   114
lemmas seqr = eq_reflection [where x = "size w"] for w (* FIXME: delete *)
haftmann@53062
   115
wenzelm@65363
   116
lemma the_elemI: "y = {x} \<Longrightarrow> the_elem y = x"
haftmann@53062
   117
  by simp
haftmann@53062
   118
wenzelm@65363
   119
lemma nonemptyE: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> R) \<Longrightarrow> R"
wenzelm@65363
   120
  by auto
haftmann@53062
   121
wenzelm@65363
   122
lemma gt_or_eq_0: "0 < y \<or> 0 = y"
wenzelm@65363
   123
  for y :: nat
wenzelm@65363
   124
  by arith
haftmann@53062
   125
haftmann@53062
   126
lemmas xtr1 = xtrans(1)
haftmann@53062
   127
lemmas xtr2 = xtrans(2)
haftmann@53062
   128
lemmas xtr3 = xtrans(3)
haftmann@53062
   129
lemmas xtr4 = xtrans(4)
haftmann@53062
   130
lemmas xtr5 = xtrans(5)
haftmann@53062
   131
lemmas xtr6 = xtrans(6)
haftmann@53062
   132
lemmas xtr7 = xtrans(7)
haftmann@53062
   133
lemmas xtr8 = xtrans(8)
haftmann@53062
   134
haftmann@53062
   135
lemmas nat_simps = diff_add_inverse2 diff_add_inverse
haftmann@53062
   136
lemmas nat_iffs = le_add1 le_add2
haftmann@53062
   137
wenzelm@65363
   138
lemma sum_imp_diff: "j = k + i \<Longrightarrow> j - i = k"
wenzelm@65363
   139
  for k :: nat
wenzelm@65363
   140
  by arith
haftmann@53062
   141
haftmann@53062
   142
lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]]
haftmann@53062
   143
lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]]
haftmann@53062
   144
wenzelm@65363
   145
lemma nmod2: "n mod 2 = 0 \<or> n mod 2 = 1"
wenzelm@65363
   146
  for n :: int
haftmann@58681
   147
  by arith
haftmann@53062
   148
haftmann@57512
   149
lemmas eme1p = emep1 [simplified add.commute]
haftmann@53062
   150
wenzelm@65363
   151
lemma le_diff_eq': "a \<le> c - b \<longleftrightarrow> b + a \<le> c"
wenzelm@65363
   152
  for a b c :: int
wenzelm@65363
   153
  by arith
haftmann@53062
   154
wenzelm@65363
   155
lemma less_diff_eq': "a < c - b \<longleftrightarrow> b + a < c"
wenzelm@65363
   156
  for a b c :: int
wenzelm@65363
   157
  by arith
haftmann@53062
   158
wenzelm@65363
   159
lemma diff_less_eq': "a - b < c \<longleftrightarrow> a < b + c"
wenzelm@65363
   160
  for a b c :: int
wenzelm@65363
   161
  by arith
haftmann@53062
   162
haftmann@53062
   163
lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]
haftmann@53062
   164
wenzelm@65363
   165
lemma z1pdiv2: "(2 * b + 1) div 2 = b"
wenzelm@65363
   166
  for b :: int
wenzelm@65363
   167
  by arith
haftmann@53062
   168
haftmann@53062
   169
lemmas zdiv_le_dividend = xtr3 [OF div_by_1 [symmetric] zdiv_mono2,
haftmann@53062
   170
  simplified int_one_le_iff_zero_less, simplified]
haftmann@53062
   171
wenzelm@65363
   172
lemma axxbyy: "a + m + m = b + n + n \<Longrightarrow> a = 0 \<or> a = 1 \<Longrightarrow> b = 0 \<or> b = 1 \<Longrightarrow> a = b \<and> m = n"
wenzelm@65363
   173
  for a b m n :: int
wenzelm@65363
   174
  by arith
wenzelm@65363
   175
wenzelm@65363
   176
lemma axxmod2: "(1 + x + x) mod 2 = 1 \<and> (0 + x + x) mod 2 = 0"
wenzelm@65363
   177
  for x :: int
wenzelm@65363
   178
  by arith
haftmann@53062
   179
wenzelm@65363
   180
lemma axxdiv2: "(1 + x + x) div 2 = x \<and> (0 + x + x) div 2 = x"
wenzelm@65363
   181
  for x :: int
wenzelm@65363
   182
  by arith
haftmann@53062
   183
wenzelm@65363
   184
lemmas iszero_minus =
wenzelm@65363
   185
  trans [THEN trans, OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric]]
haftmann@53062
   186
wenzelm@65363
   187
lemmas zadd_diff_inverse =
wenzelm@65363
   188
  trans [OF diff_add_cancel [symmetric] add.commute]
haftmann@53062
   189
wenzelm@65363
   190
lemmas add_diff_cancel2 =
wenzelm@65363
   191
  add.commute [THEN diff_eq_eq [THEN iffD2]]
haftmann@53062
   192
haftmann@53062
   193
lemmas rdmods [symmetric] = mod_minus_eq
haftmann@53062
   194
  mod_diff_left_eq mod_diff_right_eq mod_add_left_eq
haftmann@53062
   195
  mod_add_right_eq mod_mult_right_eq mod_mult_left_eq
haftmann@53062
   196
wenzelm@65363
   197
lemma mod_plus_right: "(a + x) mod m = (b + x) mod m \<longleftrightarrow> a mod m = b mod m"
wenzelm@65363
   198
  for a b m x :: nat
wenzelm@65363
   199
  by (induct x) (simp_all add: mod_Suc, arith)
haftmann@53062
   200
wenzelm@65363
   201
lemma nat_minus_mod: "(n - n mod m) mod m = 0"
wenzelm@65363
   202
  for m n :: nat
wenzelm@65363
   203
  by (induct n) (simp_all add: mod_Suc)
haftmann@53062
   204
wenzelm@65363
   205
lemmas nat_minus_mod_plus_right =
wenzelm@65363
   206
  trans [OF nat_minus_mod mod_0 [symmetric],
wenzelm@65363
   207
    THEN mod_plus_right [THEN iffD2], simplified]
haftmann@53062
   208
haftmann@53062
   209
lemmas push_mods' = mod_add_eq
haftmann@53062
   210
  mod_mult_eq mod_diff_eq
haftmann@53062
   211
  mod_minus_eq
haftmann@53062
   212
haftmann@53062
   213
lemmas push_mods = push_mods' [THEN eq_reflection]
haftmann@53062
   214
lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection]
haftmann@53062
   215
wenzelm@65363
   216
lemma nat_mod_eq: "b < n \<Longrightarrow> a mod n = b mod n \<Longrightarrow> a mod n = b"
wenzelm@65363
   217
  for a b n :: nat
haftmann@53062
   218
  by (induct a) auto
haftmann@53062
   219
haftmann@53062
   220
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]
haftmann@53062
   221
wenzelm@65363
   222
lemma nat_mod_lem: "0 < n \<Longrightarrow> b < n \<longleftrightarrow> b mod n = b"
wenzelm@65363
   223
  for b n :: nat
haftmann@53062
   224
  apply safe
haftmann@53062
   225
   apply (erule nat_mod_eq')
haftmann@53062
   226
  apply (erule subst)
haftmann@53062
   227
  apply (erule mod_less_divisor)
haftmann@53062
   228
  done
haftmann@53062
   229
wenzelm@65363
   230
lemma mod_nat_add: "x < z \<Longrightarrow> y < z \<Longrightarrow> (x + y) mod z = (if x + y < z then x + y else x + y - z)"
wenzelm@65363
   231
  for x y z :: nat
haftmann@53062
   232
  apply (rule nat_mod_eq)
haftmann@53062
   233
   apply auto
haftmann@53062
   234
  apply (rule trans)
haftmann@53062
   235
   apply (rule le_mod_geq)
haftmann@53062
   236
   apply simp
haftmann@53062
   237
  apply (rule nat_mod_eq')
haftmann@53062
   238
  apply arith
haftmann@53062
   239
  done
haftmann@53062
   240
wenzelm@65363
   241
lemma mod_nat_sub: "x < z \<Longrightarrow> (x - y) mod z = x - y"
wenzelm@65363
   242
  for x y :: nat
haftmann@53062
   243
  by (rule nat_mod_eq') arith
haftmann@53062
   244
wenzelm@65363
   245
lemma int_mod_eq: "0 \<le> b \<Longrightarrow> b < n \<Longrightarrow> a mod n = b mod n \<Longrightarrow> a mod n = b"
wenzelm@65363
   246
  for a b n :: int
haftmann@55816
   247
  by (metis mod_pos_pos_trivial)
haftmann@53062
   248
haftmann@55816
   249
lemmas int_mod_eq' = mod_pos_pos_trivial (* FIXME delete *)
haftmann@53062
   250
haftmann@66801
   251
lemmas int_mod_le = zmod_le_nonneg_dividend (* FIXME: delete *)
haftmann@53062
   252
haftmann@53062
   253
lemma mod_add_if_z:
wenzelm@65363
   254
  "x < z \<Longrightarrow> y < z \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> z \<Longrightarrow>
wenzelm@65363
   255
    (x + y) mod z = (if x + y < z then x + y else x + y - z)"
wenzelm@65363
   256
  for x y z :: int
haftmann@53062
   257
  by (auto intro: int_mod_eq)
haftmann@53062
   258
haftmann@53062
   259
lemma mod_sub_if_z:
wenzelm@65363
   260
  "x < z \<Longrightarrow> y < z \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> z \<Longrightarrow>
wenzelm@65363
   261
    (x - y) mod z = (if y \<le> x then x - y else x - y + z)"
wenzelm@65363
   262
  for x y z :: int
haftmann@53062
   263
  by (auto intro: int_mod_eq)
haftmann@53062
   264
haftmann@64246
   265
lemmas zmde = mult_div_mod_eq [symmetric, THEN diff_eq_eq [THEN iffD2], symmetric]
haftmann@53062
   266
lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]
haftmann@53062
   267
haftmann@53062
   268
(* already have this for naturals, div_mult_self1/2, but not for ints *)
wenzelm@65363
   269
lemma zdiv_mult_self: "m \<noteq> 0 \<Longrightarrow> (a + m * n) div m = a div m + n"
wenzelm@65363
   270
  for a m n :: int
haftmann@53062
   271
  apply (rule mcl)
haftmann@53062
   272
   prefer 2
haftmann@53062
   273
   apply (erule asm_rl)
haftmann@53062
   274
  apply (simp add: zmde ring_distribs)
haftmann@53062
   275
  done
haftmann@53062
   276
wenzelm@65363
   277
lemma mod_power_lem: "a > 1 \<Longrightarrow> a ^ n mod a ^ m = (if m \<le> n then 0 else a ^ n)"
wenzelm@65363
   278
  for a :: int
haftmann@66886
   279
  by (simp add: mod_eq_0_iff le_imp_power_dvd)
haftmann@53062
   280
wenzelm@65363
   281
lemma pl_pl_rels: "a + b = c + d \<Longrightarrow> a \<ge> c \<and> b \<le> d \<or> a \<le> c \<and> b \<ge> d"
wenzelm@65363
   282
  for a b c d :: nat
wenzelm@65363
   283
  by arith
haftmann@53062
   284
haftmann@57512
   285
lemmas pl_pl_rels' = add.commute [THEN [2] trans, THEN pl_pl_rels]
haftmann@53062
   286
wenzelm@65363
   287
lemma minus_eq: "m - k = m \<longleftrightarrow> k = 0 \<or> m = 0"
wenzelm@65363
   288
  for k m :: nat
wenzelm@65363
   289
  by arith
haftmann@53062
   290
wenzelm@65363
   291
lemma pl_pl_mm: "a + b = c + d \<Longrightarrow> a - c = d - b"
wenzelm@65363
   292
  for a b c d :: nat
wenzelm@65363
   293
  by arith
haftmann@53062
   294
haftmann@57512
   295
lemmas pl_pl_mm' = add.commute [THEN [2] trans, THEN pl_pl_mm]
haftmann@53062
   296
haftmann@64245
   297
lemmas dme = div_mult_mod_eq
haftmann@66808
   298
lemmas dtle = div_times_less_eq_dividend
haftmann@66808
   299
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] div_times_less_eq_dividend]
haftmann@53062
   300
wenzelm@65363
   301
lemma td_gal: "0 < c \<Longrightarrow> a \<ge> b * c \<longleftrightarrow> a div c \<ge> b"
wenzelm@65363
   302
  for a b c :: nat
haftmann@53062
   303
  apply safe
haftmann@53062
   304
   apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])
haftmann@53062
   305
  apply (erule th2)
haftmann@53062
   306
  done
wenzelm@65363
   307
haftmann@53062
   308
lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified]
haftmann@53062
   309
haftmann@66808
   310
lemmas div_mult_le = div_times_less_eq_dividend 
haftmann@53062
   311
haftmann@66808
   312
lemmas sdl = div_nat_eqI
haftmann@53062
   313
wenzelm@65363
   314
lemma given_quot: "f > 0 \<Longrightarrow> (f * l + (f - 1)) div f = l"
wenzelm@65363
   315
  for f l :: nat
haftmann@66808
   316
  by (rule div_nat_eqI) (simp_all)
haftmann@53062
   317
wenzelm@65363
   318
lemma given_quot_alt: "f > 0 \<Longrightarrow> (l * f + f - Suc 0) div f = l"
wenzelm@65363
   319
  for f l :: nat
haftmann@53062
   320
  apply (frule given_quot)
haftmann@53062
   321
  apply (rule trans)
haftmann@53062
   322
   prefer 2
haftmann@53062
   323
   apply (erule asm_rl)
wenzelm@65363
   324
  apply (rule_tac f="\<lambda>n. n div f" in arg_cong)
haftmann@57514
   325
  apply (simp add : ac_simps)
haftmann@53062
   326
  done
wenzelm@65363
   327
wenzelm@65363
   328
lemma diff_mod_le: "a < d \<Longrightarrow> b dvd d \<Longrightarrow> a - a mod b \<le> d - b"
wenzelm@65363
   329
  for a b d :: nat
haftmann@53062
   330
  apply (unfold dvd_def)
haftmann@53062
   331
  apply clarify
haftmann@53062
   332
  apply (case_tac k)
haftmann@53062
   333
   apply clarsimp
haftmann@53062
   334
  apply clarify
haftmann@53062
   335
  apply (cases "b > 0")
haftmann@57512
   336
   apply (drule mult.commute [THEN xtr1])
haftmann@53062
   337
   apply (frule (1) td_gal_lt [THEN iffD1])
haftmann@53062
   338
   apply (clarsimp simp: le_simps)
haftmann@64246
   339
   apply (rule minus_mod_eq_mult_div [symmetric, THEN [2] xtr4])
haftmann@53062
   340
   apply (rule mult_mono)
haftmann@53062
   341
      apply auto
haftmann@53062
   342
  done
haftmann@53062
   343
wenzelm@65363
   344
lemma less_le_mult': "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> (w + 1) * c \<le> b * c"
wenzelm@65363
   345
  for b c w :: int
haftmann@53062
   346
  apply (rule mult_right_mono)
haftmann@53062
   347
   apply (rule zless_imp_add1_zle)
haftmann@53062
   348
   apply (erule (1) mult_right_less_imp_less)
haftmann@53062
   349
  apply assumption
haftmann@53062
   350
  done
haftmann@53062
   351
wenzelm@65363
   352
lemma less_le_mult: "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> w * c + c \<le> b * c"
wenzelm@65363
   353
  for b c w :: int
haftmann@55816
   354
  using less_le_mult' [of w c b] by (simp add: algebra_simps)
haftmann@53062
   355
wenzelm@65363
   356
lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult,
haftmann@53062
   357
  simplified left_diff_distrib]
haftmann@53062
   358
wenzelm@65363
   359
lemma gen_minus: "0 < n \<Longrightarrow> f n = f (Suc (n - 1))"
haftmann@53062
   360
  by auto
haftmann@53062
   361
wenzelm@65363
   362
lemma mpl_lem: "j \<le> i \<Longrightarrow> k < j \<Longrightarrow> i - j + k < i"
wenzelm@65363
   363
  for i j k :: nat
wenzelm@65363
   364
  by arith
haftmann@53062
   365
wenzelm@65363
   366
lemma nonneg_mod_div: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> (a mod b) \<and> 0 \<le> a div b"
wenzelm@65363
   367
  for a b :: int
wenzelm@65363
   368
  by (cases "b = 0") (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])
haftmann@53062
   369
haftmann@54872
   370
declare iszero_0 [intro]
haftmann@54872
   371
wenzelm@65363
   372
lemma min_pm [simp]: "min a b + (a - b) = a"
wenzelm@65363
   373
  for a b :: nat
haftmann@54872
   374
  by arith
wenzelm@65363
   375
wenzelm@65363
   376
lemma min_pm1 [simp]: "a - b + min a b = a"
wenzelm@65363
   377
  for a b :: nat
haftmann@54872
   378
  by arith
haftmann@54872
   379
wenzelm@65363
   380
lemma rev_min_pm [simp]: "min b a + (a - b) = a"
wenzelm@65363
   381
  for a b :: nat
haftmann@54872
   382
  by arith
haftmann@54872
   383
wenzelm@65363
   384
lemma rev_min_pm1 [simp]: "a - b + min b a = a"
wenzelm@65363
   385
  for a b :: nat
haftmann@54872
   386
  by arith
haftmann@54872
   387
wenzelm@65363
   388
lemma min_minus [simp]: "min m (m - k) = m - k"
wenzelm@65363
   389
  for m k :: nat
haftmann@54872
   390
  by arith
wenzelm@65363
   391
wenzelm@65363
   392
lemma min_minus' [simp]: "min (m - k) m = m - k"
wenzelm@65363
   393
  for m k :: nat
haftmann@54872
   394
  by arith
haftmann@54872
   395
haftmann@53062
   396
end