src/HOL/Word/Misc_Arithmetic.thy
author wenzelm
Thu, 16 Jul 2020 20:34:21 +0200
changeset 72050 d4de7e4754d2
parent 71997 4a013c92a091
permissions -rw-r--r--
clarified theory data: more robust merge;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70170
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
     1
(*  Title:      HOL/Word/Misc_Arithmetic.thy  *)
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
     2
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
     3
section \<open>Miscellaneous lemmas, mostly for arithmetic\<close>
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
     4
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
     5
theory Misc_Arithmetic
71997
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
     6
  imports Main Bits_Int
70170
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
     7
begin
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
     8
71997
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
     9
lemma int_mod_lem: "0 < n \<Longrightarrow> 0 \<le> b \<and> b < n \<longleftrightarrow> b mod n = b"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    10
  for b n :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    11
  apply safe
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    12
    apply (erule (1) mod_pos_pos_trivial)
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    13
   apply (erule_tac [!] subst)
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    14
   apply auto
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    15
  done
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    16
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    17
lemma int_mod_ge': "b < 0 \<Longrightarrow> 0 < n \<Longrightarrow> b + n \<le> b mod n"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    18
  for b n :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    19
  by (metis add_less_same_cancel2 int_mod_ge mod_add_self2)
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    20
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    21
lemma int_mod_le': "0 \<le> b - n \<Longrightarrow> b mod n \<le> b - n"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    22
  for b n :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    23
  by (metis minus_mod_self2 zmod_le_nonneg_dividend)
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    24
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    25
lemma emep1: "even n \<Longrightarrow> even d \<Longrightarrow> 0 \<le> d \<Longrightarrow> (n + 1) mod d = (n mod d) + 1"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    26
  for n d :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    27
  by (auto simp add: pos_zmod_mult_2 add.commute dvd_def)
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    28
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    29
lemma m1mod2k: "- 1 mod 2 ^ n = (2 ^ n - 1 :: int)"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    30
  by (rule zmod_minus1) simp
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    31
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    32
lemma sb_inc_lem: "a + 2^k < 0 \<Longrightarrow> a + 2^k + 2^(Suc k) \<le> (a + 2^k) mod 2^(Suc k)"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    33
  for a :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    34
  using int_mod_ge' [where n = "2 ^ (Suc k)" and b = "a + 2 ^ k"]
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    35
  by simp
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    36
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    37
lemma sb_inc_lem': "a < - (2^k) \<Longrightarrow> a + 2^k + 2^(Suc k) \<le> (a + 2^k) mod 2^(Suc k)"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    38
  for a :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    39
  by (rule sb_inc_lem) simp
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    40
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    41
lemma sb_dec_lem: "0 \<le> - (2 ^ k) + a \<Longrightarrow> (a + 2 ^ k) mod (2 * 2 ^ k) \<le> - (2 ^ k) + a"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    42
  for a :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    43
  using int_mod_le'[where n = "2 ^ (Suc k)" and b = "a + 2 ^ k"] by simp
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    44
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    45
lemma sb_dec_lem': "2 ^ k \<le> a \<Longrightarrow> (a + 2 ^ k) mod (2 * 2 ^ k) \<le> - (2 ^ k) + a"
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    46
  for a :: int
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    47
  by (rule sb_dec_lem) simp
4a013c92a091 factored out auxiliary theory
haftmann
parents: 71987
diff changeset
    48
70170
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    49
lemma one_mod_exp_eq_one [simp]:
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    50
  "1 mod (2 * 2 ^ n) = (1::int)"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    51
  using power_gt1 [of 2 n] by (auto intro: mod_pos_pos_trivial)
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    52
  
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    53
lemma mod_2_neq_1_eq_eq_0: "k mod 2 \<noteq> 1 \<longleftrightarrow> k mod 2 = 0"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    54
  for k :: int
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    55
  by (fact not_mod_2_eq_1_eq_0)
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    56
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    57
lemma z1pmod2: "(2 * b + 1) mod 2 = (1::int)"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    58
  for b :: int
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    59
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    60
70170
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    61
lemma diff_le_eq': "a - b \<le> c \<longleftrightarrow> a \<le> b + c"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    62
  for a b c :: int
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    63
  by arith
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    64
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    65
lemma zless2: "0 < (2 :: int)"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    66
  by (fact zero_less_numeral)
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    67
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    68
lemma zless2p: "0 < (2 ^ n :: int)"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    69
  by arith
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    70
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    71
lemma zle2p: "0 \<le> (2 ^ n :: int)"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    72
  by arith
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    73
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    74
lemma p1mod22k': "(1 + 2 * b) mod (2 * 2 ^ n) = 1 + 2 * (b mod 2 ^ n)"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    75
  for b :: int
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    76
  using zle2p by (rule pos_zmod_mult_2)
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    77
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    78
lemma p1mod22k: "(2 * b + 1) mod (2 * 2 ^ n) = 2 * (b mod 2 ^ n) + 1"
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    79
  for b :: int
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
    80
  by (simp add: p1mod22k' add.commute)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    81
70169
8bb835f10a39 moved instance to appropriate place
haftmann
parents: 68157
diff changeset
    82
lemma ex_eq_or: "(\<exists>m. n = Suc m \<and> (m = k \<or> P m)) \<longleftrightarrow> n = Suc k \<or> (\<exists>m. n = Suc m \<and> P m)"
8bb835f10a39 moved instance to appropriate place
haftmann
parents: 68157
diff changeset
    83
  by auto
8bb835f10a39 moved instance to appropriate place
haftmann
parents: 68157
diff changeset
    84
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
    85
lemma power_minus_simp: "0 < n \<Longrightarrow> a ^ n = a * a ^ (n - 1)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    86
  by (auto dest: gr0_implies_Suc)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    87
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
    88
lemma funpow_minus_simp: "0 < n \<Longrightarrow> f ^^ n = f \<circ> f ^^ (n - 1)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    89
  by (auto dest: gr0_implies_Suc)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    90
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
    91
lemma power_numeral: "a ^ numeral k = a * a ^ (pred_numeral k)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    92
  by (simp add: numeral_eq_Suc)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    93
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
    94
lemma funpow_numeral [simp]: "f ^^ numeral k = f \<circ> f ^^ (pred_numeral k)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    95
  by (simp add: numeral_eq_Suc)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    96
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
    97
lemma replicate_numeral [simp]: "replicate (numeral k) x = x # replicate (pred_numeral k) x"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    98
  by (simp add: numeral_eq_Suc)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
    99
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   100
lemma rco_alt: "(f \<circ> g) ^^ n \<circ> f = f \<circ> (g \<circ> f) ^^ n"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   101
  apply (rule ext)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   102
  apply (induct n)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   103
   apply (simp_all add: o_def)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   104
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   105
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   106
lemma list_exhaust_size_gt0:
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66886
diff changeset
   107
  assumes "\<And>a list. y = a # list \<Longrightarrow> P"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   108
  shows "0 < length y \<Longrightarrow> P"
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   109
  apply (cases y)
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   110
   apply simp
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66886
diff changeset
   111
  apply (rule assms)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   112
  apply fastforce
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   113
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   114
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   115
lemma list_exhaust_size_eq0:
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66886
diff changeset
   116
  assumes "y = [] \<Longrightarrow> P"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   117
  shows "length y = 0 \<Longrightarrow> P"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   118
  apply (cases y)
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66886
diff changeset
   119
   apply (rule assms)
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   120
   apply simp
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   121
  apply simp
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   122
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   123
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   124
lemma size_Cons_lem_eq: "y = xa # list \<Longrightarrow> size y = Suc k \<Longrightarrow> size list = k"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   125
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   126
62390
842917225d56 more canonical names
nipkow
parents: 61799
diff changeset
   127
lemmas ls_splits = prod.split prod.split_asm if_split_asm
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   128
67443
3abf6a722518 standardized towards new-style formal comments: isabelle update_comments;
wenzelm
parents: 67408
diff changeset
   129
\<comment> \<open>simplifications for specific word lengths\<close>
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   130
lemmas n2s_ths [THEN eq_reflection] = add_2_eq_Suc add_2_eq_Suc'
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   131
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   132
lemmas s2n_ths = n2s_ths [symmetric]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   133
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   134
lemma and_len: "xs = ys \<Longrightarrow> xs = ys \<and> length xs = length ys"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   135
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   136
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   137
lemma size_if: "size (if p then xs else ys) = (if p then size xs else size ys)"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   138
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   139
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   140
lemma tl_if: "tl (if p then xs else ys) = (if p then tl xs else tl ys)"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   141
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   142
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   143
lemma hd_if: "hd (if p then xs else ys) = (if p then hd xs else hd ys)"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   144
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   145
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   146
lemma if_Not_x: "(if p then \<not> x else x) = (p = (\<not> x))"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   147
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   148
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   149
lemma if_x_Not: "(if p then x else \<not> x) = (p = x)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   150
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   151
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   152
lemma if_same_and: "(If p x y \<and> If p u v) = (if p then x \<and> u else y \<and> v)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   153
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   154
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   155
lemma if_same_eq: "(If p x y  = (If p u v)) = (if p then x = u else y = v)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   156
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   157
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   158
lemma if_same_eq_not: "(If p x y = (\<not> If p u v)) = (if p then x = (\<not> u) else y = (\<not> v))"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   159
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   160
67408
4a4c14b24800 prefer formal comments;
wenzelm
parents: 67120
diff changeset
   161
\<comment> \<open>note -- \<open>if_Cons\<close> can cause blowup in the size, if \<open>p\<close> is complex, so make a simproc\<close>
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   162
lemma if_Cons: "(if p then x # xs else y # ys) = If p x y # If p xs ys"
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   163
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   164
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   165
lemma if_single: "(if xc then [xab] else [an]) = [if xc then xab else an]"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   166
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   167
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   168
lemma if_bool_simps:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   169
  "If p True y = (p \<or> y) \<and> If p False y = (\<not> p \<and> y) \<and>
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   170
    If p y True = (p \<longrightarrow> y) \<and> If p y False = (p \<and> y)"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   171
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   172
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   173
lemmas if_simps =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   174
  if_x_Not if_Not_x if_cancel if_True if_False if_bool_simps
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   175
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   176
lemmas seqr = eq_reflection [where x = "size w"] for w (* FIXME: delete *)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   177
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   178
lemma the_elemI: "y = {x} \<Longrightarrow> the_elem y = x"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   179
  by simp
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   180
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   181
lemma nonemptyE: "S \<noteq> {} \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> R) \<Longrightarrow> R"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   182
  by auto
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   183
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   184
lemma gt_or_eq_0: "0 < y \<or> 0 = y"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   185
  for y :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   186
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   187
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   188
lemmas xtr1 = xtrans(1)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   189
lemmas xtr2 = xtrans(2)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   190
lemmas xtr3 = xtrans(3)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   191
lemmas xtr4 = xtrans(4)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   192
lemmas xtr5 = xtrans(5)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   193
lemmas xtr6 = xtrans(6)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   194
lemmas xtr7 = xtrans(7)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   195
lemmas xtr8 = xtrans(8)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   196
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   197
lemmas nat_simps = diff_add_inverse2 diff_add_inverse
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   198
lemmas nat_iffs = le_add1 le_add2
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   199
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   200
lemma sum_imp_diff: "j = k + i \<Longrightarrow> j - i = k"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   201
  for k :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   202
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   203
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   204
lemmas pos_mod_sign2 = zless2 [THEN pos_mod_sign [where b = "2::int"]]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   205
lemmas pos_mod_bound2 = zless2 [THEN pos_mod_bound [where b = "2::int"]]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   206
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   207
lemma nmod2: "n mod 2 = 0 \<or> n mod 2 = 1"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   208
  for n :: int
58681
a478a0742a8e legacy cleanup
haftmann
parents: 57514
diff changeset
   209
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   210
70190
ff9efdc84289 clarified structure of theories
haftmann
parents: 70170
diff changeset
   211
lemma eme1p:
ff9efdc84289 clarified structure of theories
haftmann
parents: 70170
diff changeset
   212
  "even n \<Longrightarrow> even d \<Longrightarrow> 0 \<le> d \<Longrightarrow> (1 + n) mod d = 1 + n mod d" for n d :: int
ff9efdc84289 clarified structure of theories
haftmann
parents: 70170
diff changeset
   213
  using emep1 [of n d] by (simp add: ac_simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   214
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   215
lemma le_diff_eq': "a \<le> c - b \<longleftrightarrow> b + a \<le> c"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   216
  for a b c :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   217
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   218
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   219
lemma less_diff_eq': "a < c - b \<longleftrightarrow> b + a < c"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   220
  for a b c :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   221
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   222
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   223
lemma diff_less_eq': "a - b < c \<longleftrightarrow> a < b + c"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   224
  for a b c :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   225
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   226
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   227
lemmas m1mod22k = mult_pos_pos [OF zless2 zless2p, THEN zmod_minus1]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   228
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   229
lemma z1pdiv2: "(2 * b + 1) div 2 = b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   230
  for b :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   231
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   232
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   233
lemmas zdiv_le_dividend = xtr3 [OF div_by_1 [symmetric] zdiv_mono2,
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   234
  simplified int_one_le_iff_zero_less, simplified]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   235
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   236
lemma axxbyy: "a + m + m = b + n + n \<Longrightarrow> a = 0 \<or> a = 1 \<Longrightarrow> b = 0 \<or> b = 1 \<Longrightarrow> a = b \<and> m = n"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   237
  for a b m n :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   238
  by arith
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   239
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   240
lemma axxmod2: "(1 + x + x) mod 2 = 1 \<and> (0 + x + x) mod 2 = 0"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   241
  for x :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   242
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   243
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   244
lemma axxdiv2: "(1 + x + x) div 2 = x \<and> (0 + x + x) div 2 = x"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   245
  for x :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   246
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   247
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   248
lemmas iszero_minus =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   249
  trans [THEN trans, OF iszero_def neg_equal_0_iff_equal iszero_def [symmetric]]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   250
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   251
lemmas zadd_diff_inverse =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   252
  trans [OF diff_add_cancel [symmetric] add.commute]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   253
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   254
lemmas add_diff_cancel2 =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   255
  add.commute [THEN diff_eq_eq [THEN iffD2]]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   256
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   257
lemmas rdmods [symmetric] = mod_minus_eq
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   258
  mod_diff_left_eq mod_diff_right_eq mod_add_left_eq
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   259
  mod_add_right_eq mod_mult_right_eq mod_mult_left_eq
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   260
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   261
lemma mod_plus_right: "(a + x) mod m = (b + x) mod m \<longleftrightarrow> a mod m = b mod m"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   262
  for a b m x :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   263
  by (induct x) (simp_all add: mod_Suc, arith)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   264
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   265
lemma nat_minus_mod: "(n - n mod m) mod m = 0"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   266
  for m n :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   267
  by (induct n) (simp_all add: mod_Suc)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   268
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   269
lemmas nat_minus_mod_plus_right =
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   270
  trans [OF nat_minus_mod mod_0 [symmetric],
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   271
    THEN mod_plus_right [THEN iffD2], simplified]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   272
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   273
lemmas push_mods' = mod_add_eq
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   274
  mod_mult_eq mod_diff_eq
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   275
  mod_minus_eq
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   276
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   277
lemmas push_mods = push_mods' [THEN eq_reflection]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   278
lemmas pull_mods = push_mods [symmetric] rdmods [THEN eq_reflection]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   279
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   280
lemma nat_mod_eq: "b < n \<Longrightarrow> a mod n = b mod n \<Longrightarrow> a mod n = b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   281
  for a b n :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   282
  by (induct a) auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   283
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   284
lemmas nat_mod_eq' = refl [THEN [2] nat_mod_eq]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   285
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   286
lemma nat_mod_lem: "0 < n \<Longrightarrow> b < n \<longleftrightarrow> b mod n = b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   287
  for b n :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   288
  apply safe
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   289
   apply (erule nat_mod_eq')
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   290
  apply (erule subst)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   291
  apply (erule mod_less_divisor)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   292
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   293
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   294
lemma mod_nat_add: "x < z \<Longrightarrow> y < z \<Longrightarrow> (x + y) mod z = (if x + y < z then x + y else x + y - z)"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   295
  for x y z :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   296
  apply (rule nat_mod_eq)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   297
   apply auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   298
  apply (rule trans)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   299
   apply (rule le_mod_geq)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   300
   apply simp
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   301
  apply (rule nat_mod_eq')
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   302
  apply arith
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   303
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   304
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   305
lemma mod_nat_sub: "x < z \<Longrightarrow> (x - y) mod z = x - y"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   306
  for x y :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   307
  by (rule nat_mod_eq') arith
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   308
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   309
lemma int_mod_eq: "0 \<le> b \<Longrightarrow> b < n \<Longrightarrow> a mod n = b mod n \<Longrightarrow> a mod n = b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   310
  for a b n :: int
55816
e8dd03241e86 cursory polishing: tuned proofs, tuned symbols, tuned headings
haftmann
parents: 55417
diff changeset
   311
  by (metis mod_pos_pos_trivial)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   312
55816
e8dd03241e86 cursory polishing: tuned proofs, tuned symbols, tuned headings
haftmann
parents: 55417
diff changeset
   313
lemmas int_mod_eq' = mod_pos_pos_trivial (* FIXME delete *)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   314
66801
f3fda9777f9a avoid fact name clashes
haftmann
parents: 66453
diff changeset
   315
lemmas int_mod_le = zmod_le_nonneg_dividend (* FIXME: delete *)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   316
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   317
lemma mod_add_if_z:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   318
  "x < z \<Longrightarrow> y < z \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> z \<Longrightarrow>
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   319
    (x + y) mod z = (if x + y < z then x + y else x + y - z)"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   320
  for x y z :: int
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   321
  by (auto intro: int_mod_eq)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   322
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   323
lemma mod_sub_if_z:
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   324
  "x < z \<Longrightarrow> y < z \<Longrightarrow> 0 \<le> y \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> z \<Longrightarrow>
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   325
    (x - y) mod z = (if y \<le> x then x - y else x - y + z)"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   326
  for x y z :: int
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   327
  by (auto intro: int_mod_eq)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   328
64246
15d1ee6e847b eliminated irregular aliasses
haftmann
parents: 64245
diff changeset
   329
lemmas zmde = mult_div_mod_eq [symmetric, THEN diff_eq_eq [THEN iffD2], symmetric]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   330
lemmas mcl = mult_cancel_left [THEN iffD1, THEN make_pos_rule]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   331
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   332
(* already have this for naturals, div_mult_self1/2, but not for ints *)
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   333
lemma zdiv_mult_self: "m \<noteq> 0 \<Longrightarrow> (a + m * n) div m = a div m + n"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   334
  for a m n :: int
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   335
  apply (rule mcl)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   336
   prefer 2
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   337
   apply (erule asm_rl)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   338
  apply (simp add: zmde ring_distribs)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   339
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   340
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   341
lemma mod_power_lem: "a > 1 \<Longrightarrow> a ^ n mod a ^ m = (if m \<le> n then 0 else a ^ n)"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   342
  for a :: int
68157
057d5b4ce47e removed some non-essential rules
haftmann
parents: 67443
diff changeset
   343
  by (simp add: mod_eq_0_iff_dvd le_imp_power_dvd)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   344
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   345
lemma pl_pl_rels: "a + b = c + d \<Longrightarrow> a \<ge> c \<and> b \<le> d \<or> a \<le> c \<and> b \<ge> d"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   346
  for a b c d :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   347
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   348
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55816
diff changeset
   349
lemmas pl_pl_rels' = add.commute [THEN [2] trans, THEN pl_pl_rels]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   350
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   351
lemma minus_eq: "m - k = m \<longleftrightarrow> k = 0 \<or> m = 0"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   352
  for k m :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   353
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   354
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   355
lemma pl_pl_mm: "a + b = c + d \<Longrightarrow> a - c = d - b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   356
  for a b c d :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   357
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   358
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55816
diff changeset
   359
lemmas pl_pl_mm' = add.commute [THEN [2] trans, THEN pl_pl_mm]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   360
64245
3d00821444fc avoid references to lemmas designed for prover tools
haftmann
parents: 62390
diff changeset
   361
lemmas dme = div_mult_mod_eq
66808
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66801
diff changeset
   362
lemmas dtle = div_times_less_eq_dividend
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66801
diff changeset
   363
lemmas th2 = order_trans [OF order_refl [THEN [2] mult_le_mono] div_times_less_eq_dividend]
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   364
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   365
lemma td_gal: "0 < c \<Longrightarrow> a \<ge> b * c \<longleftrightarrow> a div c \<ge> b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   366
  for a b c :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   367
  apply safe
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   368
   apply (erule (1) xtr4 [OF div_le_mono div_mult_self_is_m])
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   369
  apply (erule th2)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   370
  done
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   371
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   372
lemmas td_gal_lt = td_gal [simplified not_less [symmetric], simplified]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   373
67120
491fd7f0b5df misc tuning and modernization;
wenzelm
parents: 66886
diff changeset
   374
lemmas div_mult_le = div_times_less_eq_dividend
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   375
66808
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66801
diff changeset
   376
lemmas sdl = div_nat_eqI
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   377
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   378
lemma given_quot: "f > 0 \<Longrightarrow> (f * l + (f - 1)) div f = l"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   379
  for f l :: nat
66808
1907167b6038 elementary definition of division on natural numbers
haftmann
parents: 66801
diff changeset
   380
  by (rule div_nat_eqI) (simp_all)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   381
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   382
lemma given_quot_alt: "f > 0 \<Longrightarrow> (l * f + f - Suc 0) div f = l"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   383
  for f l :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   384
  apply (frule given_quot)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   385
  apply (rule trans)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   386
   prefer 2
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   387
   apply (erule asm_rl)
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   388
  apply (rule_tac f="\<lambda>n. n div f" in arg_cong)
57514
bdc2c6b40bf2 prefer ac_simps collections over separate name bindings for add and mult
haftmann
parents: 57512
diff changeset
   389
  apply (simp add : ac_simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   390
  done
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   391
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   392
lemma diff_mod_le: "a < d \<Longrightarrow> b dvd d \<Longrightarrow> a - a mod b \<le> d - b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   393
  for a b d :: nat
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   394
  apply (unfold dvd_def)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   395
  apply clarify
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   396
  apply (case_tac k)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   397
   apply clarsimp
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   398
  apply clarify
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   399
  apply (cases "b > 0")
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 55816
diff changeset
   400
   apply (drule mult.commute [THEN xtr1])
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   401
   apply (frule (1) td_gal_lt [THEN iffD1])
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   402
   apply (clarsimp simp: le_simps)
64246
15d1ee6e847b eliminated irregular aliasses
haftmann
parents: 64245
diff changeset
   403
   apply (rule minus_mod_eq_mult_div [symmetric, THEN [2] xtr4])
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   404
   apply (rule mult_mono)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   405
      apply auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   406
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   407
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   408
lemma less_le_mult': "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> (w + 1) * c \<le> b * c"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   409
  for b c w :: int
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   410
  apply (rule mult_right_mono)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   411
   apply (rule zless_imp_add1_zle)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   412
   apply (erule (1) mult_right_less_imp_less)
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   413
  apply assumption
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   414
  done
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   415
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   416
lemma less_le_mult: "w * c < b * c \<Longrightarrow> 0 \<le> c \<Longrightarrow> w * c + c \<le> b * c"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   417
  for b c w :: int
55816
e8dd03241e86 cursory polishing: tuned proofs, tuned symbols, tuned headings
haftmann
parents: 55417
diff changeset
   418
  using less_le_mult' [of w c b] by (simp add: algebra_simps)
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   419
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   420
lemmas less_le_mult_minus = iffD2 [OF le_diff_eq less_le_mult,
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   421
  simplified left_diff_distrib]
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   422
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   423
lemma gen_minus: "0 < n \<Longrightarrow> f n = f (Suc (n - 1))"
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   424
  by auto
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   425
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   426
lemma mpl_lem: "j \<le> i \<Longrightarrow> k < j \<Longrightarrow> i - j + k < i"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   427
  for i j k :: nat
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   428
  by arith
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   429
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   430
lemma nonneg_mod_div: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> 0 \<le> (a mod b) \<and> 0 \<le> a div b"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   431
  for a b :: int
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   432
  by (cases "b = 0") (auto intro: pos_imp_zdiv_nonneg_iff [THEN iffD2])
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   433
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   434
declare iszero_0 [intro]
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   435
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   436
lemma min_pm [simp]: "min a b + (a - b) = a"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   437
  for a b :: nat
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   438
  by arith
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   439
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   440
lemma min_pm1 [simp]: "a - b + min a b = a"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   441
  for a b :: nat
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   442
  by arith
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   443
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   444
lemma rev_min_pm [simp]: "min b a + (a - b) = a"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   445
  for a b :: nat
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   446
  by arith
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   447
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   448
lemma rev_min_pm1 [simp]: "a - b + min b a = a"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   449
  for a b :: nat
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   450
  by arith
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   451
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   452
lemma min_minus [simp]: "min m (m - k) = m - k"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   453
  for m k :: nat
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   454
  by arith
65363
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   455
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   456
lemma min_minus' [simp]: "min (m - k) m = m - k"
5eb619751b14 misc tuning and modernization;
wenzelm
parents: 64593
diff changeset
   457
  for m k :: nat
54872
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   458
  by arith
af81b2357e08 postpone dis"useful" lemmas
haftmann
parents: 54871
diff changeset
   459
70170
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
   460
lemmas m2pths = pos_mod_sign pos_mod_bound [OF zless2p]
56727602d0a5 prefer one theory for misc material
haftmann
parents: 70169
diff changeset
   461
53062
3af1a6020014 some vague grouping of related theorems, with slight tuning of headings and sorting out of dubious lemmas into separate theory
haftmann
parents:
diff changeset
   462
end