src/HOL/Word/Num_Lemmas.thy
author huffman
Tue, 28 Aug 2007 20:13:47 +0200
changeset 24465 70f0214b3ecc
parent 24414 87ef9b486068
child 25349 0d46bea01741
permissions -rw-r--r--
revert to Word library version from 2007/08/20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     1
(* 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     2
  ID:      $Id$
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     3
  Author:  Jeremy Dawson, NICTA
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     4
*) 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     5
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     6
header {* Useful Numerical Lemmas *}
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     7
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     8
theory Num_Lemmas imports Parity begin
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     9
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    10
lemma contentsI: "y = {x} ==> contents y = x" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    11
  unfolding contents_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    12
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    13
lemma prod_case_split: "prod_case = split"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    14
  by (rule ext)+ auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    15
 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    16
lemmas split_split = prod.split [unfolded prod_case_split] 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    17
lemmas split_split_asm = prod.split_asm [unfolded prod_case_split]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    18
lemmas "split.splits" = split_split split_split_asm 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    19
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    20
lemmas funpow_0 = funpow.simps(1)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    21
lemmas funpow_Suc = funpow.simps(2)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    22
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    23
lemma nonemptyE: "S ~= {} ==> (!!x. x : S ==> R) ==> R"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    24
  apply (erule contrapos_np)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    25
  apply (rule equals0I)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    26
  apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    27
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    28
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    29
lemma gt_or_eq_0: "0 < y \<or> 0 = (y::nat)" by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    30
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    31
constdefs
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    32
  mod_alt :: "'a => 'a => 'a :: Divides.div"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    33
  "mod_alt n m == n mod m" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    34
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    35
  -- "alternative way of defining @{text bin_last}, @{text bin_rest}"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    36
  bin_rl :: "int => int * bit" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    37
  "bin_rl w == SOME (r, l). w = r BIT l"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    38
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    39
declare iszero_0 [iff]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    40
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    41
lemmas xtr1 = xtrans(1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    42
lemmas xtr2 = xtrans(2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    43
lemmas xtr3 = xtrans(3)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    44
lemmas xtr4 = xtrans(4)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    45
lemmas xtr5 = xtrans(5)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    46
lemmas xtr6 = xtrans(6)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    47
lemmas xtr7 = xtrans(7)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    48
lemmas xtr8 = xtrans(8)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    49
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    50
lemma Min_ne_Pls [iff]:  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    51
  "Numeral.Min ~= Numeral.Pls"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    52
  unfolding Min_def Pls_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    53
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    54
lemmas Pls_ne_Min [iff] = Min_ne_Pls [symmetric]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    55
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    56
lemmas PlsMin_defs [intro!] = 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    57
  Pls_def Min_def Pls_def [symmetric] Min_def [symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    58
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    59
lemmas PlsMin_simps [simp] = PlsMin_defs [THEN Eq_TrueI]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    60
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    61
lemma number_of_False_cong: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    62
  "False ==> number_of x = number_of y" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    63
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    64
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    65
lemmas nat_simps = diff_add_inverse2 diff_add_inverse
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    66
lemmas nat_iffs = le_add1 le_add2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    67
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    68
lemma sum_imp_diff: "j = k + i ==> j - i = (k :: nat)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    69
  by (clarsimp simp add: nat_simps)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    70
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    71
lemma nobm1:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    72
  "0 < (number_of w :: nat) ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    73
   number_of w - (1 :: nat) = number_of (Numeral.pred w)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    74
  apply (unfold nat_number_of_def One_nat_def nat_1 [symmetric] pred_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    75
  apply (simp add: number_of_eq nat_diff_distrib [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    76
  done
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    77
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    78
lemma of_int_power:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    79
  "of_int (a ^ n) = (of_int a ^ n :: 'a :: {recpower, comm_ring_1})" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    80
  by (induct n) (auto simp add: power_Suc)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    81
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    82
lemma zless2: "0 < (2 :: int)" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    83
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    84
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    85
lemmas zless2p [simp] = zless2 [THEN zero_less_power]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    86
lemmas zle2p [simp] = zless2p [THEN order_less_imp_le]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    87
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    88
lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    89
lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    90
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    91
-- "the inverse(s) of @{text number_of}"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    92
lemma nmod2: "n mod (2::int) = 0 | n mod 2 = 1"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    93
  using pos_mod_sign2 [of n] pos_mod_bound2 [of n]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    94
  unfolding mod_alt_def [symmetric] by auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    95
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    96
lemma emep1:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    97
  "even n ==> even d ==> 0 <= d ==> (n + 1) mod (d :: int) = (n mod d) + 1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    98
  apply (simp add: add_commute)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    99
  apply (safe dest!: even_equiv_def [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   100
  apply (subst pos_zmod_mult_2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   101
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   102
  apply (simp add: zmod_zmult_zmult1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   103
 done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   104
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   105
lemmas eme1p = emep1 [simplified add_commute]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   106
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   107
lemma le_diff_eq': "(a \<le> c - b) = (b + a \<le> (c::int))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   108
  by (simp add: le_diff_eq add_commute)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   109
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   110
lemma less_diff_eq': "(a < c - b) = (b + a < (c::int))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   111
  by (simp add: less_diff_eq add_commute)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   112
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   113
lemma diff_le_eq': "(a - b \<le> c) = (a \<le> b + (c::int))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   114
  by (simp add: diff_le_eq add_commute)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   115
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   116
lemma diff_less_eq': "(a - b < c) = (a < b + (c::int))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   117
  by (simp add: diff_less_eq add_commute)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   118
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   119
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   120
lemmas m1mod2k = zless2p [THEN zmod_minus1]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   121
lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   122
lemmas p1mod22k' = zless2p [THEN order_less_imp_le, THEN pos_zmod_mult_2]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   123
lemmas z1pmod2' = zero_le_one [THEN pos_zmod_mult_2, simplified]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   124
lemmas z1pdiv2' = zero_le_one [THEN pos_zdiv_mult_2, simplified]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   125
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   126
lemma p1mod22k:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   127
  "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + (1::int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   128
  by (simp add: p1mod22k' add_commute)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   129
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   130
lemma z1pmod2:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   131
  "(2 * b + 1) mod 2 = (1::int)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   132
  by (simp add: z1pmod2' add_commute)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   133
  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   134
lemma z1pdiv2:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   135
  "(2 * b + 1) div 2 = (b::int)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   136
  by (simp add: z1pdiv2' add_commute)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   137
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   138
lemmas zdiv_le_dividend = xtr3 [OF zdiv_1 [symmetric] zdiv_mono2,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   139
  simplified int_one_le_iff_zero_less, simplified, standard]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   140
  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   141
(** ways in which type Bin resembles a datatype **)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   142
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   143
lemma BIT_eq: "u BIT b = v BIT c ==> u = v & b = c"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   144
  apply (unfold Bit_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   145
  apply (simp (no_asm_use) split: bit.split_asm)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   146
     apply simp_all
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   147
   apply (drule_tac f=even in arg_cong, clarsimp)+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   148
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   149
     
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   150
lemmas BIT_eqE [elim!] = BIT_eq [THEN conjE, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   151
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   152
lemma BIT_eq_iff [simp]: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   153
  "(u BIT b = v BIT c) = (u = v \<and> b = c)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   154
  by (rule iffI) auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   155
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   156
lemmas BIT_eqI [intro!] = conjI [THEN BIT_eq_iff [THEN iffD2]]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   157
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   158
lemma less_Bits: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   159
  "(v BIT b < w BIT c) = (v < w | v <= w & b = bit.B0 & c = bit.B1)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   160
  unfolding Bit_def by (auto split: bit.split)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   161
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   162
lemma le_Bits: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   163
  "(v BIT b <= w BIT c) = (v < w | v <= w & (b ~= bit.B1 | c ~= bit.B0))" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   164
  unfolding Bit_def by (auto split: bit.split)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   165
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   166
lemma neB1E [elim!]:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   167
  assumes ne: "y \<noteq> bit.B1"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   168
  assumes y: "y = bit.B0 \<Longrightarrow> P"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   169
  shows "P"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   170
  apply (rule y)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   171
  apply (cases y rule: bit.exhaust, simp)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   172
  apply (simp add: ne)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   173
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   174
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   175
lemma bin_ex_rl: "EX w b. w BIT b = bin"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   176
  apply (unfold Bit_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   177
  apply (cases "even bin")
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   178
   apply (clarsimp simp: even_equiv_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   179
   apply (auto simp: odd_equiv_def split: bit.split)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   180
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   181
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   182
lemma bin_exhaust:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   183
  assumes Q: "\<And>x b. bin = x BIT b \<Longrightarrow> Q"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   184
  shows "Q"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   185
  apply (insert bin_ex_rl [of bin])  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   186
  apply (erule exE)+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   187
  apply (rule Q)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   188
  apply force
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   189
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   190
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   191
lemma bin_rl_char: "(bin_rl w = (r, l)) = (r BIT l = w)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   192
  apply (unfold bin_rl_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   193
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   194
   apply (cases w rule: bin_exhaust)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   195
   apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   196
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   197
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   198
lemmas bin_rl_simps [THEN bin_rl_char [THEN iffD2], standard, simp] =
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   199
  Pls_0_eq Min_1_eq refl 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   200
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   201
lemma bin_abs_lem:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   202
  "bin = (w BIT b) ==> ~ bin = Numeral.Min --> ~ bin = Numeral.Pls -->
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   203
    nat (abs w) < nat (abs bin)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   204
  apply (clarsimp simp add: bin_rl_char)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   205
  apply (unfold Pls_def Min_def Bit_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   206
  apply (cases b)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   207
   apply (clarsimp, arith)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   208
  apply (clarsimp, arith)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   209
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   210
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   211
lemma bin_induct:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   212
  assumes PPls: "P Numeral.Pls"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   213
    and PMin: "P Numeral.Min"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   214
    and PBit: "!!bin bit. P bin ==> P (bin BIT bit)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   215
  shows "P bin"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   216
  apply (rule_tac P=P and a=bin and f1="nat o abs" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   217
                  in wf_measure [THEN wf_induct])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   218
  apply (simp add: measure_def inv_image_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   219
  apply (case_tac x rule: bin_exhaust)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   220
  apply (frule bin_abs_lem)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   221
  apply (auto simp add : PPls PMin PBit)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   222
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   223
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   224
lemma no_no [simp]: "number_of (number_of i) = i"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   225
  unfolding number_of_eq by simp
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   226
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   227
lemma Bit_B0:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   228
  "k BIT bit.B0 = k + k"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   229
   by (unfold Bit_def) simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   230
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   231
lemma Bit_B1:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   232
  "k BIT bit.B1 = k + k + 1"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   233
   by (unfold Bit_def) simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   234
  
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   235
lemma Bit_B0_2t: "k BIT bit.B0 = 2 * k"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
  by (rule trans, rule Bit_B0) simp
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   237
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   238
lemma Bit_B1_2t: "k BIT bit.B1 = 2 * k + 1"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   239
  by (rule trans, rule Bit_B1) simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   240
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   241
lemma B_mod_2': 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   242
  "X = 2 ==> (w BIT bit.B1) mod X = 1 & (w BIT bit.B0) mod X = 0"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   243
  apply (simp (no_asm) only: Bit_B0 Bit_B1)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   244
  apply (simp add: z1pmod2)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   245
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   246
    
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   247
lemmas B1_mod_2 [simp] = B_mod_2' [OF refl, THEN conjunct1, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   248
lemmas B0_mod_2 [simp] = B_mod_2' [OF refl, THEN conjunct2, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   249
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   250
lemma axxbyy:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   251
  "a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==>  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   252
   a = b & m = (n :: int)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   253
  apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   254
   apply (drule_tac f="%n. n mod 2" in arg_cong)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   255
   apply (clarsimp simp: z1pmod2)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   256
  apply (drule_tac f="%n. n mod 2" in arg_cong)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   257
  apply (clarsimp simp: z1pmod2)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   258
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   259
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   260
lemma axxmod2:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   261
  "(1 + x + x) mod 2 = (1 :: int) & (0 + x + x) mod 2 = (0 :: int)" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   262
  by simp (rule z1pmod2)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   263
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   264
lemma axxdiv2:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   265
  "(1 + x + x) div 2 = (x :: int) & (0 + x + x) div 2 = (x :: int)" 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   266
  by simp (rule z1pdiv2)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   267
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   268
lemmas iszero_minus = trans [THEN trans,
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   269
  OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric], standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   270
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   271
lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add_commute,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   272
  standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   273
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   274
lemmas add_diff_cancel2 = add_commute [THEN diff_eq_eq [THEN iffD2], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   275
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   276
lemma zmod_uminus: "- ((a :: int) mod b) mod b = -a mod b"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   277
  by (simp add : zmod_zminus1_eq_if)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   278
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   279
lemma zmod_zsub_distrib: "((a::int) - b) mod c = (a mod c - b mod c) mod c"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   280
  apply (unfold diff_int_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   281
  apply (rule trans [OF _ zmod_zadd1_eq [symmetric]])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   282
  apply (simp add: zmod_uminus zmod_zadd1_eq [symmetric])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   283
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   284
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   285
lemma zmod_zsub_right_eq: "((a::int) - b) mod c = (a - b mod c) mod c"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   286
  apply (unfold diff_int_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   287
  apply (rule trans [OF _ zmod_zadd_right_eq [symmetric]])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   288
  apply (simp add : zmod_uminus zmod_zadd_right_eq [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   289
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   290
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   291
lemmas zmod_zsub_left_eq = 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   292
  zmod_zadd_left_eq [where b = "- ?b", simplified diff_int_def [symmetric]]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   293
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   294
lemma zmod_zsub_self [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   295
  "((b :: int) - a) mod a = b mod a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   296
  by (simp add: zmod_zsub_right_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   297
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   298
lemma zmod_zmult1_eq_rev:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   299
  "b * a mod c = b mod c * a mod (c::int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   300
  apply (simp add: mult_commute)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   301
  apply (subst zmod_zmult1_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   302
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   303
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   304
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   305
lemmas rdmods [symmetric] = zmod_uminus [symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   306
  zmod_zsub_left_eq zmod_zsub_right_eq zmod_zadd_left_eq
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   307
  zmod_zadd_right_eq zmod_zmult1_eq zmod_zmult1_eq_rev
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   308
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   309
lemma mod_plus_right:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   310
  "((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   311
  apply (induct x)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   312
   apply (simp_all add: mod_Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   313
  apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   314
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   315
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   316
lemma nat_minus_mod: "(n - n mod m) mod m = (0 :: nat)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   317
  by (induct n) (simp_all add : mod_Suc)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   318
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   319
lemmas nat_minus_mod_plus_right = trans [OF nat_minus_mod mod_0 [symmetric],
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   320
  THEN mod_plus_right [THEN iffD2], standard, simplified]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   321
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   322
lemmas push_mods' = zmod_zadd1_eq [standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   323
  zmod_zmult_distrib [standard] zmod_zsub_distrib [standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   324
  zmod_uminus [symmetric, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   325
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   326
lemmas push_mods = push_mods' [THEN eq_reflection, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   327
lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   328
lemmas mod_simps = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   329
  zmod_zmult_self1 [THEN eq_reflection] zmod_zmult_self2 [THEN eq_reflection]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   330
  mod_mod_trivial [THEN eq_reflection]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   331
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   332
lemma nat_mod_eq:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   333
  "!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   334
  by (induct a) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   335
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   336
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   337
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   338
lemma nat_mod_lem: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   339
  "(0 :: nat) < n ==> b < n = (b mod n = b)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   340
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   341
   apply (erule nat_mod_eq')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   342
  apply (erule subst)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   343
  apply (erule mod_less_divisor)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   344
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   345
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   346
lemma mod_nat_add: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   347
  "(x :: nat) < z ==> y < z ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
  apply (rule nat_mod_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   350
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   351
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   352
   apply (rule le_mod_geq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   353
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   354
  apply (rule nat_mod_eq')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   355
  apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   356
  done
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   357
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   358
lemma mod_nat_sub: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   359
  "(x :: nat) < z ==> (x - y) mod z = x - y"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   360
  by (rule nat_mod_eq') arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
lemma int_mod_lem: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
  "(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   364
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   365
    apply (erule (1) mod_pos_pos_trivial)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   366
   apply (erule_tac [!] subst)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   367
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   368
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   370
lemma int_mod_eq:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
  "(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   372
  by clarsimp (rule mod_pos_pos_trivial)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   373
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
lemmas int_mod_eq' = refl [THEN [3] int_mod_eq]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
  apply (cases "a < n")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   378
   apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   380
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   381
lemmas int_mod_le' = int_mod_le [where a = "?b - ?n", simplified]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   382
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   383
lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   384
  apply (cases "0 <= a")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   385
   apply (drule (1) mod_pos_pos_trivial)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   386
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   387
  apply (rule order_trans [OF _ pos_mod_sign])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   388
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   389
  apply assumption
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   390
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   391
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   392
lemmas int_mod_ge' = int_mod_ge [where a = "?b + ?n", simplified]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   393
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   394
lemma mod_add_if_z:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   395
  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   396
   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   397
  by (auto intro: int_mod_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   398
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   399
lemma mod_sub_if_z:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   400
  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   401
   (x - y) mod z = (if y <= x then x - y else x - y + z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   402
  by (auto intro: int_mod_eq)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   403
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   404
lemmas zmde = zmod_zdiv_equality [THEN diff_eq_eq [THEN iffD2], symmetric]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   405
lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   406
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   407
(* already have this for naturals, div_mult_self1/2, but not for ints *)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   408
lemma zdiv_mult_self: "m ~= (0 :: int) ==> (a + m * n) div m = a div m + n"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   409
  apply (rule mcl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   410
   prefer 2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   411
   apply (erule asm_rl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   412
  apply (simp add: zmde ring_distribs)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   413
  apply (simp add: push_mods)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   414
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   415
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   416
(** Rep_Integ **)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   417
lemma eqne: "equiv A r ==> X : A // r ==> X ~= {}"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   418
  unfolding equiv_def refl_def quotient_def Image_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   419
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   420
lemmas Rep_Integ_ne = Integ.Rep_Integ 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   421
  [THEN equiv_intrel [THEN eqne, simplified Integ_def [symmetric]], standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   422
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   423
lemmas riq = Integ.Rep_Integ [simplified Integ_def]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   424
lemmas intrel_refl = refl [THEN equiv_intrel_iff [THEN iffD1], standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   425
lemmas Rep_Integ_equiv = quotient_eq_iff
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   426
  [OF equiv_intrel riq riq, simplified Integ.Rep_Integ_inject, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   427
lemmas Rep_Integ_same = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   428
  Rep_Integ_equiv [THEN intrel_refl [THEN rev_iffD2], standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   429
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   430
lemma RI_int: "(a, 0) : Rep_Integ (int a)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   431
  unfolding int_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   432
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   433
lemmas RI_intrel [simp] = UNIV_I [THEN quotientI,
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   434
  THEN Integ.Abs_Integ_inverse [simplified Integ_def], standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   435
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   436
lemma RI_minus: "(a, b) : Rep_Integ x ==> (b, a) : Rep_Integ (- x)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   437
  apply (rule_tac z=x in eq_Abs_Integ)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   438
  apply (clarsimp simp: minus)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   439
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   440
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   441
lemma RI_add: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   442
  "(a, b) : Rep_Integ x ==> (c, d) : Rep_Integ y ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   443
   (a + c, b + d) : Rep_Integ (x + y)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   444
  apply (rule_tac z=x in eq_Abs_Integ)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   445
  apply (rule_tac z=y in eq_Abs_Integ) 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   446
  apply (clarsimp simp: add)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   447
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   448
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   449
lemma mem_same: "a : S ==> a = b ==> b : S"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   450
  by fast
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   451
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   452
(* two alternative proofs of this *)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   453
lemma RI_eq_diff': "(a, b) : Rep_Integ (int a - int b)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   454
  apply (unfold diff_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   455
  apply (rule mem_same)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   456
   apply (rule RI_minus RI_add RI_int)+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   457
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   458
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   459
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   460
lemma RI_eq_diff: "((a, b) : Rep_Integ x) = (int a - int b = x)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   461
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   462
   apply (rule Rep_Integ_same)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   463
    prefer 2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   464
    apply (erule asm_rl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   465
   apply (rule RI_eq_diff')+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   466
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   467
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   468
lemma mod_power_lem:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   469
  "a > 1 ==> a ^ n mod a ^ m = (if m <= n then 0 else (a :: int) ^ n)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   470
  apply clarsimp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   471
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   472
   apply (simp add: zdvd_iff_zmod_eq_0 [symmetric])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   473
   apply (drule le_iff_add [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   474
   apply (force simp: zpower_zadd_distrib)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   475
  apply (rule mod_pos_pos_trivial)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   476
   apply (simp add: zero_le_power)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   477
  apply (rule power_strict_increasing)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   478
   apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   479
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   480
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   481
lemma min_pm [simp]: "min a b + (a - b) = (a :: nat)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   482
  by arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   483
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   484
lemmas min_pm1 [simp] = trans [OF add_commute min_pm]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   485
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   486
lemma rev_min_pm [simp]: "min b a + (a - b) = (a::nat)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   487
  by simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   488
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   489
lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   490
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   491
lemma pl_pl_rels: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   492
  "a + b = c + d ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   493
   a >= c & b <= d | a <= c & b >= (d :: nat)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   494
  apply (cut_tac n=a and m=c in nat_le_linear)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   495
  apply (safe dest!: le_iff_add [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   496
         apply arith+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   497
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   498
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   499
lemmas pl_pl_rels' = add_commute [THEN [2] trans, THEN pl_pl_rels]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   500
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   501
lemma minus_eq: "(m - k = m) = (k = 0 | m = (0 :: nat))"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   502
  by arith
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   503
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   504
lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a - c = d - b"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   505
  by arith
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   506
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   507
lemmas pl_pl_mm' = add_commute [THEN [2] trans, THEN pl_pl_mm]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   508
 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   509
lemma min_minus [simp] : "min m (m - k) = (m - k :: nat)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   510
  by arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   511
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   512
lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   513
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   514
lemma nat_no_eq_iff: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   515
  "(number_of b :: int) >= 0 ==> (number_of c :: int) >= 0 ==> 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   516
   (number_of b = (number_of c :: nat)) = (b = c)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   517
  apply (unfold nat_number_of_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   518
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   519
  apply (drule (2) eq_nat_nat_iff [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   520
  apply (simp add: number_of_eq)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   521
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   522
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   523
lemmas dme = box_equals [OF div_mod_equality add_0_right add_0_right]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   524
lemmas dtle = xtr3 [OF dme [symmetric] le_add1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   525
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   526
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   527
lemma td_gal: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   528
  "0 < c ==> (a >= b * c) = (a div c >= (b :: nat))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   529
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   530
   apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   531
  apply (erule th2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   532
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   533
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   534
lemmas td_gal_lt = td_gal [simplified le_def, simplified]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   535
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   536
lemma div_mult_le: "(a :: nat) div b * b <= a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   537
  apply (cases b)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   538
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   539
   apply (rule order_refl [THEN th2])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   540
  apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   541
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   542
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   543
lemmas sdl = split_div_lemma [THEN iffD1, symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   544
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   545
lemma given_quot: "f > (0 :: nat) ==> (f * l + (f - 1)) div f = l"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   546
  by (rule sdl, assumption) (simp (no_asm))
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   547
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   548
lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f - Suc 0) div f = l"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   549
  apply (frule given_quot)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   550
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   551
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   552
   apply (erule asm_rl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   553
  apply (rule_tac f="%n. n div f" in arg_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   554
  apply (simp add : mult_ac)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   555
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   556
    
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   557
lemma diff_mod_le: "(a::nat) < d ==> b dvd d ==> a - a mod b <= d - b"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   558
  apply (unfold dvd_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   559
  apply clarify
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   560
  apply (case_tac k)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   561
   apply clarsimp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   562
  apply clarify
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   563
  apply (cases "b > 0")
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   564
   apply (drule mult_commute [THEN xtr1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   565
   apply (frule (1) td_gal_lt [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   566
   apply (clarsimp simp: le_simps)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   567
   apply (rule mult_div_cancel [THEN [2] xtr4])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   568
   apply (rule mult_mono)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   569
      apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   570
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   571
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   572
lemma less_le_mult':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   573
  "w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   574
  apply (rule mult_right_mono)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   575
   apply (rule zless_imp_add1_zle)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   576
   apply (erule (1) mult_right_less_imp_less)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   577
  apply assumption
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   578
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   579
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   580
lemmas less_le_mult = less_le_mult' [simplified left_distrib, simplified]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   581
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   582
lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult, 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   583
  simplified left_diff_distrib, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   584
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   585
lemma lrlem':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   586
  assumes d: "(i::nat) \<le> j \<or> m < j'"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   587
  assumes R1: "i * k \<le> j * k \<Longrightarrow> R"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   588
  assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   589
  shows "R" using d
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   590
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   591
   apply (rule R1, erule mult_le_mono1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   592
  apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   593
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   594
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   595
lemma lrlem: "(0::nat) < sc ==>
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   596
    (sc - n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   597
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   598
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   599
  apply (case_tac "sc >= n")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   600
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   601
  apply (insert linorder_le_less_linear [of m lb])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   602
  apply (erule_tac k=n and k'=n in lrlem')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   603
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   604
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   605
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   606
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   607
lemma gen_minus: "0 < n ==> f n = f (Suc (n - 1))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   608
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   609
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   610
lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i - j + k < i"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   611
  apply (induct i, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   612
  apply (cases j, clarsimp)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   613
  apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   614
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   615
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   616
lemma nonneg_mod_div:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   617
  "0 <= a ==> 0 <= b ==> 0 <= (a mod b :: int) & 0 <= a div b"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   618
  apply (cases "b = 0", clarsimp)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   619
  apply (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   620
  done
24399
371f8c6b2101 move if_simps from BinBoolList to Num_Lemmas
huffman
parents: 24394
diff changeset
   621
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   622
end