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