src/HOL/Word/Num_Lemmas.thy
author wenzelm
Wed, 11 Mar 2009 19:27:04 +0100
changeset 30445 757ba2bb2b39
parent 30242 aea5d7fa7ef5
child 30943 eb3dbbe971f6
permissions -rw-r--r--
renamed (unused?) "split.splits" to split_splits -- it was only accepted by accident;
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
  Author:  Jeremy Dawson, NICTA
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     3
*) 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     4
24350
4d74f37c6367 headers for document generation
huffman
parents: 24333
diff changeset
     5
header {* Useful Numerical Lemmas *}
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
     6
25592
e8ddaf6bf5df explicit import of theory Main
haftmann
parents: 25349
diff changeset
     7
theory Num_Lemmas
e8ddaf6bf5df explicit import of theory Main
haftmann
parents: 25349
diff changeset
     8
imports Main Parity
e8ddaf6bf5df explicit import of theory Main
haftmann
parents: 25349
diff changeset
     9
begin
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    10
26560
haftmann
parents: 26514
diff changeset
    11
lemma contentsI: "y = {x} ==> contents y = x" 
haftmann
parents: 26514
diff changeset
    12
  unfolding contents_def by auto -- {* FIXME move *}
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 26072
diff changeset
    13
30445
757ba2bb2b39 renamed (unused?) "split.splits" to split_splits -- it was only accepted by accident;
wenzelm
parents: 30242
diff changeset
    14
lemmas split_split = prod.split [unfolded prod_case_split]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    15
lemmas split_split_asm = prod.split_asm [unfolded prod_case_split]
30445
757ba2bb2b39 renamed (unused?) "split.splits" to split_splits -- it was only accepted by accident;
wenzelm
parents: 30242
diff changeset
    16
lemmas split_splits = split_split split_split_asm
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    17
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    18
lemmas funpow_0 = funpow.simps(1)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    19
lemmas funpow_Suc = funpow.simps(2)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    20
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    21
lemma nonemptyE: "S ~= {} ==> (!!x. x : S ==> R) ==> R" by auto
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    22
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    23
lemma gt_or_eq_0: "0 < y \<or> 0 = (y::nat)" by arith 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    24
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    25
declare iszero_0 [iff]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    26
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    27
lemmas xtr1 = xtrans(1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    28
lemmas xtr2 = xtrans(2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    29
lemmas xtr3 = xtrans(3)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    30
lemmas xtr4 = xtrans(4)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    31
lemmas xtr5 = xtrans(5)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    32
lemmas xtr6 = xtrans(6)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    33
lemmas xtr7 = xtrans(7)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    34
lemmas xtr8 = xtrans(8)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    35
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    36
lemmas nat_simps = diff_add_inverse2 diff_add_inverse
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    37
lemmas nat_iffs = le_add1 le_add2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    38
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    39
lemma sum_imp_diff: "j = k + i ==> j - i = (k :: nat)" by arith
24465
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
lemma nobm1:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    42
  "0 < (number_of w :: nat) ==> 
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    43
   number_of w - (1 :: nat) = number_of (Int.pred w)" 
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    44
  apply (unfold nat_number_of_def One_nat_def nat_1 [symmetric] pred_def)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    45
  apply (simp add: number_of_eq nat_diff_distrib [symmetric])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    46
  done
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    47
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    48
lemma of_int_power:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    49
  "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
    50
  by (induct n) (auto simp add: power_Suc)
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    51
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    52
lemma zless2: "0 < (2 :: int)" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    53
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    54
lemmas zless2p [simp] = zless2 [THEN zero_less_power]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    55
lemmas zle2p [simp] = zless2p [THEN order_less_imp_le]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    56
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    57
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
    58
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
    59
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    60
-- "the inverse(s) of @{text number_of}"
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    61
lemma nmod2: "n mod (2::int) = 0 | n mod 2 = 1" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    62
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    63
lemma emep1:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    64
  "even n ==> even d ==> 0 <= d ==> (n + 1) mod (d :: int) = (n mod d) + 1"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    65
  apply (simp add: add_commute)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    66
  apply (safe dest!: even_equiv_def [THEN iffD1])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    67
  apply (subst pos_zmod_mult_2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    68
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    69
  apply (simp add: zmod_zmult_zmult1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    70
 done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    71
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    72
lemmas eme1p = emep1 [simplified add_commute]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    73
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    74
lemma le_diff_eq': "(a \<le> c - b) = (b + a \<le> (c::int))" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    75
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    76
lemma less_diff_eq': "(a < c - b) = (b + a < (c::int))" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    77
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    78
lemma diff_le_eq': "(a - b \<le> c) = (a \<le> b + (c::int))" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    79
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    80
lemma diff_less_eq': "(a - b < c) = (a < b + (c::int))" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    81
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    82
lemmas m1mod2k = zless2p [THEN zmod_minus1]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    83
lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    84
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
    85
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
    86
lemmas z1pdiv2' = zero_le_one [THEN pos_zdiv_mult_2, simplified]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    87
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    88
lemma p1mod22k:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    89
  "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + (1::int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    90
  by (simp add: p1mod22k' add_commute)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    91
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    92
lemma z1pmod2:
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    93
  "(2 * b + 1) mod 2 = (1::int)" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    94
  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
    95
lemma z1pdiv2:
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
    96
  "(2 * b + 1) div 2 = (b::int)" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    97
30031
bd786c37af84 Removed redundant lemmas
nipkow
parents: 29948
diff changeset
    98
lemmas zdiv_le_dividend = xtr3 [OF div_by_1 [symmetric] zdiv_mono2,
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
    99
  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
   100
  
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   101
lemma axxbyy:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   102
  "a + m + m = b + n + n ==> (a = 0 | a = 1) ==> (b = 0 | b = 1) ==>  
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   103
   a = b & m = (n :: int)" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   104
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   105
lemma axxmod2:
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   106
  "(1 + x + x) mod 2 = (1 :: int) & (0 + x + x) mod 2 = (0 :: int)" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   107
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   108
lemma axxdiv2:
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   109
  "(1 + x + x) div 2 = (x :: int) & (0 + x + x) div 2 = (x :: int)"  by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   110
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   111
lemmas iszero_minus = trans [THEN trans,
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   112
  OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric], standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   113
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   114
lemmas zadd_diff_inverse = trans [OF diff_add_cancel [symmetric] add_commute,
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   115
  standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   116
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   117
lemmas add_diff_cancel2 = add_commute [THEN diff_eq_eq [THEN iffD2], standard]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   118
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   119
lemma zmod_uminus: "- ((a :: int) mod b) mod b = -a mod b"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   120
  by (simp add : zmod_zminus1_eq_if)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   121
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   122
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
   123
  apply (unfold diff_int_def)
29948
cdf12a1cb963 Cleaned up IntDiv and removed subsumed lemmas.
nipkow
parents: 28952
diff changeset
   124
  apply (rule trans [OF _ mod_add_eq [symmetric]])
cdf12a1cb963 Cleaned up IntDiv and removed subsumed lemmas.
nipkow
parents: 28952
diff changeset
   125
  apply (simp add: zmod_uminus mod_add_eq [symmetric])
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   126
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   127
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   128
lemma zmod_zsub_right_eq: "((a::int) - b) mod c = (a - b mod c) mod c"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   129
  apply (unfold diff_int_def)
30034
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   130
  apply (rule trans [OF _ mod_add_right_eq [symmetric]])
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   131
  apply (simp add : zmod_uminus mod_add_right_eq [symmetric])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   132
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   133
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 24465
diff changeset
   134
lemma zmod_zsub_left_eq: "((a::int) - b) mod c = (a mod c - b) mod c"
30034
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   135
  by (rule mod_add_left_eq [where b = "- b", simplified diff_int_def [symmetric]])
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 24465
diff changeset
   136
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   137
lemma zmod_zsub_self [simp]: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   138
  "((b :: int) - a) mod a = b mod a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   139
  by (simp add: zmod_zsub_right_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   140
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   141
lemma zmod_zmult1_eq_rev:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   142
  "b * a mod c = b mod c * a mod (c::int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   143
  apply (simp add: mult_commute)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   144
  apply (subst zmod_zmult1_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   145
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   146
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   147
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   148
lemmas rdmods [symmetric] = zmod_uminus [symmetric]
30034
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   149
  zmod_zsub_left_eq zmod_zsub_right_eq mod_add_left_eq
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   150
  mod_add_right_eq zmod_zmult1_eq zmod_zmult1_eq_rev
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   151
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   152
lemma mod_plus_right:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   153
  "((a + x) mod m = (b + x) mod m) = (a mod m = b mod (m :: nat))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   154
  apply (induct x)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   155
   apply (simp_all add: mod_Suc)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   156
  apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   157
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   158
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   159
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
   160
  by (induct n) (simp_all add : mod_Suc)
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
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
   163
  THEN mod_plus_right [THEN iffD2], standard, simplified]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   164
29948
cdf12a1cb963 Cleaned up IntDiv and removed subsumed lemmas.
nipkow
parents: 28952
diff changeset
   165
lemmas push_mods' = mod_add_eq [standard]
cdf12a1cb963 Cleaned up IntDiv and removed subsumed lemmas.
nipkow
parents: 28952
diff changeset
   166
  mod_mult_eq [standard] zmod_zsub_distrib [standard]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   167
  zmod_uminus [symmetric, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   168
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   169
lemmas push_mods = push_mods' [THEN eq_reflection, standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   170
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
   171
lemmas mod_simps = 
30034
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   172
  mod_mult_self2_is_0 [THEN eq_reflection]
60f64f112174 removed redundant thms
nipkow
parents: 30031
diff changeset
   173
  mod_mult_self1_is_0 [THEN eq_reflection]
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   174
  mod_mod_trivial [THEN eq_reflection]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   175
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   176
lemma nat_mod_eq:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   177
  "!!b. b < n ==> a mod n = b mod n ==> a mod n = (b :: nat)" 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   178
  by (induct a) auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   179
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   180
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   181
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   182
lemma nat_mod_lem: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   183
  "(0 :: nat) < n ==> b < n = (b mod n = b)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   184
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   185
   apply (erule nat_mod_eq')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   186
  apply (erule subst)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   187
  apply (erule mod_less_divisor)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   188
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   189
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   190
lemma mod_nat_add: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   191
  "(x :: nat) < z ==> y < z ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   192
   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   193
  apply (rule nat_mod_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   194
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   195
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   196
   apply (rule le_mod_geq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   197
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   198
  apply (rule nat_mod_eq')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   199
  apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   200
  done
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   201
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   202
lemma mod_nat_sub: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   203
  "(x :: nat) < z ==> (x - y) mod z = x - y"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   204
  by (rule nat_mod_eq') arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   205
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   206
lemma int_mod_lem: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   207
  "(0 :: int) < n ==> (0 <= b & b < n) = (b mod n = b)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   208
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   209
    apply (erule (1) mod_pos_pos_trivial)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   210
   apply (erule_tac [!] subst)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   211
   apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   212
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   213
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   214
lemma int_mod_eq:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   215
  "(0 :: int) <= b ==> b < n ==> a mod n = b mod n ==> a mod n = b"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   216
  by clarsimp (rule mod_pos_pos_trivial)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   217
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   218
lemmas int_mod_eq' = refl [THEN [3] int_mod_eq]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   219
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   220
lemma int_mod_le: "0 <= a ==> 0 < (n :: int) ==> a mod n <= a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   221
  apply (cases "a < n")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   222
   apply (auto dest: mod_pos_pos_trivial pos_mod_bound [where a=a])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   223
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   224
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 24465
diff changeset
   225
lemma int_mod_le': "0 <= b - n ==> 0 < (n :: int) ==> b mod n <= b - n"
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 24465
diff changeset
   226
  by (rule int_mod_le [where a = "b - n" and n = n, simplified])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   227
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   228
lemma int_mod_ge: "a < n ==> 0 < (n :: int) ==> a <= a mod n"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   229
  apply (cases "0 <= a")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   230
   apply (drule (1) mod_pos_pos_trivial)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   231
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   232
  apply (rule order_trans [OF _ pos_mod_sign])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   233
   apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   234
  apply assumption
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   235
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   236
25349
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 24465
diff changeset
   237
lemma int_mod_ge': "b < 0 ==> 0 < (n :: int) ==> b + n <= b mod n"
0d46bea01741 eliminated illegal schematic variables in where/of;
wenzelm
parents: 24465
diff changeset
   238
  by (rule int_mod_ge [where a = "b + n" and n = n, simplified])
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   239
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   240
lemma mod_add_if_z:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   241
  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   242
   (x + y) mod z = (if x + y < z then x + y else x + y - z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   243
  by (auto intro: int_mod_eq)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   244
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   245
lemma mod_sub_if_z:
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   246
  "(x :: int) < z ==> y < z ==> 0 <= y ==> 0 <= x ==> 0 <= z ==> 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   247
   (x - y) mod z = (if y <= x then x - y else x - y + z)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   248
  by (auto intro: int_mod_eq)
24465
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
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
   251
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
   252
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   253
(* 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
   254
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
   255
  apply (rule mcl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   256
   prefer 2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   257
   apply (erule asm_rl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   258
  apply (simp add: zmde ring_distribs)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   259
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   260
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   261
(** Rep_Integ **)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   262
lemma eqne: "equiv A r ==> X : A // r ==> X ~= {}"
30198
922f944f03b2 name changes
nipkow
parents: 30042
diff changeset
   263
  unfolding equiv_def refl_on_def quotient_def Image_def by auto
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   264
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   265
lemmas Rep_Integ_ne = Integ.Rep_Integ 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   266
  [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
   267
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   268
lemmas riq = Integ.Rep_Integ [simplified Integ_def]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   269
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
   270
lemmas Rep_Integ_equiv = quotient_eq_iff
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   271
  [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
   272
lemmas Rep_Integ_same = 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   273
  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
   274
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   275
lemma RI_int: "(a, 0) : Rep_Integ (int a)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   276
  unfolding int_def by auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   277
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   278
lemmas RI_intrel [simp] = UNIV_I [THEN quotientI,
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   279
  THEN Integ.Abs_Integ_inverse [simplified Integ_def], standard]
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   280
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   281
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
   282
  apply (rule_tac z=x in eq_Abs_Integ)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   283
  apply (clarsimp simp: minus)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   284
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   285
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   286
lemma RI_add: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   287
  "(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
   288
   (a + c, b + d) : Rep_Integ (x + y)"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   289
  apply (rule_tac z=x in eq_Abs_Integ)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   290
  apply (rule_tac z=y in eq_Abs_Integ) 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   291
  apply (clarsimp simp: add)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   292
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   293
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   294
lemma mem_same: "a : S ==> a = b ==> b : S"
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   295
  by fast
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   296
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   297
(* two alternative proofs of this *)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   298
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
   299
  apply (unfold diff_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   300
  apply (rule mem_same)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   301
   apply (rule RI_minus RI_add RI_int)+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   302
  apply simp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   303
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   304
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   305
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
   306
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   307
   apply (rule Rep_Integ_same)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   308
    prefer 2
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   309
    apply (erule asm_rl)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   310
   apply (rule RI_eq_diff')+
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   311
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   312
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   313
lemma mod_power_lem:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   314
  "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
   315
  apply clarsimp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   316
  apply safe
30042
31039ee583fa Removed subsumed lemmas
nipkow
parents: 30034
diff changeset
   317
   apply (simp add: dvd_eq_mod_eq_0 [symmetric])
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   318
   apply (drule le_iff_add [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   319
   apply (force simp: zpower_zadd_distrib)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   320
  apply (rule mod_pos_pos_trivial)
25875
536dfdc25e0a added simp attributes/ proofs fixed
nipkow
parents: 25592
diff changeset
   321
   apply (simp)
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   322
  apply (rule power_strict_increasing)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   323
   apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   324
  done
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   325
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   326
lemma min_pm [simp]: "min a b + (a - b) = (a :: nat)" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   327
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   328
lemmas min_pm1 [simp] = trans [OF add_commute min_pm]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   329
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   330
lemma rev_min_pm [simp]: "min b a + (a - b) = (a::nat)" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   331
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   332
lemmas rev_min_pm1 [simp] = trans [OF add_commute rev_min_pm]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   333
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   334
lemma pl_pl_rels: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   335
  "a + b = c + d ==> 
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   336
   a >= c & b <= d | a <= c & b >= (d :: nat)" by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   337
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   338
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
   339
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   340
lemma minus_eq: "(m - k = m) = (k = 0 | m = (0 :: nat))"  by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   341
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   342
lemma pl_pl_mm: "(a :: nat) + b = c + d ==> a - c = d - b"  by arith
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   343
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   344
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
   345
 
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   346
lemma min_minus [simp] : "min m (m - k) = (m - k :: nat)" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   347
  
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   348
lemmas min_minus' [simp] = trans [OF min_max.inf_commute min_minus]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   349
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   350
lemma nat_no_eq_iff: 
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   351
  "(number_of b :: int) >= 0 ==> (number_of c :: int) >= 0 ==> 
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   352
   (number_of b = (number_of c :: nat)) = (b = c)" 
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   353
  apply (unfold nat_number_of_def) 
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   354
  apply safe
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   355
  apply (drule (2) eq_nat_nat_iff [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   356
  apply (simp add: number_of_eq)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   357
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   358
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   359
lemmas dme = box_equals [OF div_mod_equality add_0_right add_0_right]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   360
lemmas dtle = xtr3 [OF dme [symmetric] le_add1]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   361
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] dtle]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   362
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   363
lemma td_gal: 
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   364
  "0 < c ==> (a >= b * c) = (a div c >= (b :: nat))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   365
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   366
   apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   367
  apply (erule th2)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   368
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   369
  
26072
f65a7fa2da6c <= and < on nat no longer depend on wellfounded relations
haftmann
parents: 25937
diff changeset
   370
lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   371
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   372
lemma div_mult_le: "(a :: nat) div b * b <= a"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   373
  apply (cases b)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   374
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   375
   apply (rule order_refl [THEN th2])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   376
  apply auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   377
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   378
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   379
lemmas sdl = split_div_lemma [THEN iffD1, symmetric]
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   380
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   381
lemma given_quot: "f > (0 :: nat) ==> (f * l + (f - 1)) div f = l"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   382
  by (rule sdl, assumption) (simp (no_asm))
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   383
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   384
lemma given_quot_alt: "f > (0 :: nat) ==> (l * f + f - Suc 0) div f = l"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   385
  apply (frule given_quot)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   386
  apply (rule trans)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   387
   prefer 2
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   388
   apply (erule asm_rl)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   389
  apply (rule_tac f="%n. n div f" in arg_cong)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   390
  apply (simp add : mult_ac)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   391
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   392
    
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   393
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
   394
  apply (unfold dvd_def)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   395
  apply clarify
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   396
  apply (case_tac k)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   397
   apply clarsimp
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   398
  apply clarify
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   399
  apply (cases "b > 0")
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   400
   apply (drule mult_commute [THEN xtr1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   401
   apply (frule (1) td_gal_lt [THEN iffD1])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   402
   apply (clarsimp simp: le_simps)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   403
   apply (rule mult_div_cancel [THEN [2] xtr4])
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   404
   apply (rule mult_mono)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   405
      apply auto
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   406
  done
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   407
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   408
lemma less_le_mult':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   409
  "w * c < b * c ==> 0 \<le> c ==> (w + 1) * c \<le> b * (c::int)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   410
  apply (rule mult_right_mono)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   411
   apply (rule zless_imp_add1_zle)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   412
   apply (erule (1) mult_right_less_imp_less)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   413
  apply assumption
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   414
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   415
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   416
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
   417
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   418
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
   419
  simplified left_diff_distrib, standard]
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   420
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   421
lemma lrlem':
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   422
  assumes d: "(i::nat) \<le> j \<or> m < j'"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   423
  assumes R1: "i * k \<le> j * k \<Longrightarrow> R"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   424
  assumes R2: "Suc m * k' \<le> j' * k' \<Longrightarrow> R"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   425
  shows "R" using d
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   426
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   427
   apply (rule R1, erule mult_le_mono1)
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   428
  apply (rule R2, erule Suc_le_eq [THEN iffD2 [THEN mult_le_mono1]])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   429
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   430
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   431
lemma lrlem: "(0::nat) < sc ==>
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   432
    (sc - n + (n + lb * n) <= m * n) = (sc + lb * n <= m * n)"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   433
  apply safe
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   434
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   435
  apply (case_tac "sc >= n")
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   436
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   437
  apply (insert linorder_le_less_linear [of m lb])
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   438
  apply (erule_tac k=n and k'=n in lrlem')
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   439
   apply arith
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   440
  apply simp
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   441
  done
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   442
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   443
lemma gen_minus: "0 < n ==> f n = f (Suc (n - 1))"
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   444
  by auto
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   445
27570
9964e59a688c Simplified proofs
chaieb
parents: 26560
diff changeset
   446
lemma mpl_lem: "j <= (i :: nat) ==> k < j ==> i - j + k < i" by arith
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   447
24465
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   448
lemma nonneg_mod_div:
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   449
  "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
   450
  apply (cases "b = 0", clarsimp)
70f0214b3ecc revert to Word library version from 2007/08/20
huffman
parents: 24414
diff changeset
   451
  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
   452
  done
24399
371f8c6b2101 move if_simps from BinBoolList to Num_Lemmas
huffman
parents: 24394
diff changeset
   453
24333
e77ea0ea7f2c * HOL-Word:
kleing
parents:
diff changeset
   454
end