src/HOL/Nat_Numeral.thy
author wenzelm
Mon, 26 Mar 2012 21:03:30 +0200
changeset 47133 89b13238d7f2
parent 47108 2a1953f0d20d
child 47192 0c0501cb6da6
permissions -rw-r--r--
merged
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30925
c38cbc0ac8d1 theory NatBin now named Nat_Numeral
haftmann
parents: 30685
diff changeset
     1
(*  Title:      HOL/Nat_Numeral.thy
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     3
    Copyright   1999  University of Cambridge
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     4
*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     5
30925
c38cbc0ac8d1 theory NatBin now named Nat_Numeral
haftmann
parents: 30685
diff changeset
     6
header {* Binary numerals for the natural numbers *}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     7
30925
c38cbc0ac8d1 theory NatBin now named Nat_Numeral
haftmann
parents: 30685
diff changeset
     8
theory Nat_Numeral
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
     9
imports Int
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    10
begin
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    11
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    12
subsection {* Numerals for natural numbers *}
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    13
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    14
text {*
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    15
  Arithmetic for naturals is reduced to that for the non-negative integers.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    16
*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    17
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    18
subsection {* Special case: squares and cubes *}
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    19
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    20
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
    21
  by (simp add: nat_number(2-4))
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    22
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    23
lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
    24
  by (simp add: nat_number(2-4))
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    25
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    26
context power
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    27
begin
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    28
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    29
abbreviation (xsymbols)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    30
  power2 :: "'a \<Rightarrow> 'a"  ("(_\<twosuperior>)" [1000] 999) where
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    31
  "x\<twosuperior> \<equiv> x ^ 2"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    32
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    33
notation (latex output)
29401
94fd5dd918f5 rename abbreviation square -> power2, to match theorem names
huffman
parents: 29045
diff changeset
    34
  power2  ("(_\<twosuperior>)" [1000] 999)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    35
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    36
notation (HTML output)
29401
94fd5dd918f5 rename abbreviation square -> power2, to match theorem names
huffman
parents: 29045
diff changeset
    37
  power2  ("(_\<twosuperior>)" [1000] 999)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    38
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    39
end
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    40
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    41
context monoid_mult
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    42
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    43
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    44
lemma power2_eq_square: "a\<twosuperior> = a * a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    45
  by (simp add: numeral_2_eq_2)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    46
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    47
lemma power3_eq_cube: "a ^ 3 = a * a * a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    48
  by (simp add: numeral_3_eq_3 mult_assoc)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    49
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    50
lemma power_even_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    51
  "a ^ (2*n) = (a ^ n) ^ 2"
35047
1b2bae06c796 hide fact Nat.add_0_right; make add_0_right from Groups priority
haftmann
parents: 35043
diff changeset
    52
  by (subst mult_commute) (simp add: power_mult)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    53
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    54
lemma power_odd_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    55
  "a ^ Suc (2*n) = a * (a ^ n) ^ 2"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    56
  by (simp add: power_even_eq)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    57
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    58
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    59
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    60
context semiring_1
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    61
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    62
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    63
lemma zero_power2 [simp]: "0\<twosuperior> = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    64
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    65
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    66
lemma one_power2 [simp]: "1\<twosuperior> = 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    67
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    68
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    69
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    70
36823
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
    71
context ring_1
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    72
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    73
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    74
lemma power2_minus [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    75
  "(- a)\<twosuperior> = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    76
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    77
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    78
lemma power_minus1_even [simp]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
    79
  "-1 ^ (2*n) = 1"
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    80
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    81
  case 0 show ?case by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    82
next
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
    83
  case (Suc n) then show ?case by (simp add: power_add power2_eq_square)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    84
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    85
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    86
lemma power_minus1_odd:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
    87
  "-1 ^ Suc (2*n) = -1"
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    88
  by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    89
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    90
lemma power_minus_even [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    91
  "(-a) ^ (2*n) = a ^ (2*n)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
    92
  by (simp add: power_minus [of a])
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    93
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    94
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    95
36823
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
    96
context ring_1_no_zero_divisors
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
    97
begin
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
    98
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
    99
lemma zero_eq_power2 [simp]:
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   100
  "a\<twosuperior> = 0 \<longleftrightarrow> a = 0"
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   101
  unfolding power2_eq_square by simp
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   102
36964
a354605f03dc remove simp attribute from power2_eq_1_iff
huffman
parents: 36841
diff changeset
   103
lemma power2_eq_1_iff:
36823
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   104
  "a\<twosuperior> = 1 \<longleftrightarrow> a = 1 \<or> a = - 1"
36964
a354605f03dc remove simp attribute from power2_eq_1_iff
huffman
parents: 36841
diff changeset
   105
  unfolding power2_eq_square by (rule square_eq_1_iff)
36823
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   106
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   107
end
001d1aad99de add lemma power2_eq_1_iff; generalize some other lemmas
huffman
parents: 36719
diff changeset
   108
44345
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   109
context idom
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   110
begin
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   111
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   112
lemma power2_eq_iff: "x\<twosuperior> = y\<twosuperior> \<longleftrightarrow> x = y \<or> x = - y"
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   113
  unfolding power2_eq_square by (rule square_eq_iff)
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   114
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   115
end
881c324470a2 add lemma power2_eq_iff
huffman
parents: 43531
diff changeset
   116
35631
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   117
context linordered_ring
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   118
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   119
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   120
lemma sum_squares_ge_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   121
  "0 \<le> x * x + y * y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   122
  by (intro add_nonneg_nonneg zero_le_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   123
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   124
lemma not_sum_squares_lt_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   125
  "\<not> x * x + y * y < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   126
  by (simp add: not_less sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   127
35631
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   128
end
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   129
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   130
context linordered_ring_strict
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   131
begin
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   132
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   133
lemma sum_squares_eq_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   134
  "x * x + y * y = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
31034
736f521ad036 dropped duplicate lemma sum_nonneg_eq_zero_iff
haftmann
parents: 31014
diff changeset
   135
  by (simp add: add_nonneg_eq_0_iff)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   136
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   137
lemma sum_squares_le_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   138
  "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   139
  by (simp add: le_less not_sum_squares_lt_zero sum_squares_eq_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   140
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   141
lemma sum_squares_gt_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   142
  "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
35631
0b8a5fd339ab generalize some lemmas from class linordered_ring_strict to linordered_ring
huffman
parents: 35216
diff changeset
   143
  by (simp add: not_le [symmetric] sum_squares_le_zero_iff)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   144
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   145
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   146
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33342
diff changeset
   147
context linordered_semidom
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   148
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   149
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   150
lemma power2_le_imp_le:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   151
  "x\<twosuperior> \<le> y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x \<le> y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   152
  unfolding numeral_2_eq_2 by (rule power_le_imp_le_base)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   153
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   154
lemma power2_less_imp_less:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   155
  "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   156
  by (rule power_less_imp_less_base)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   157
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   158
lemma power2_eq_imp_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   159
  "x\<twosuperior> = y\<twosuperior> \<Longrightarrow> 0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> x = y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   160
  unfolding numeral_2_eq_2 by (erule (2) power_eq_imp_eq_base) simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   161
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   162
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   163
35028
108662d50512 more consistent naming of type classes involving orderings (and lattices) -- c.f. NEWS
haftmann
parents: 33342
diff changeset
   164
context linordered_idom
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   165
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   166
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   167
lemma zero_le_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   168
  "0 \<le> a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   169
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   170
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   171
lemma zero_less_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   172
  "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   173
  by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   174
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   175
lemma power2_less_0 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   176
  "\<not> a\<twosuperior> < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   177
  by (force simp add: power2_eq_square mult_less_0_iff) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   178
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   179
lemma abs_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   180
  "abs (a\<twosuperior>) = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   181
  by (simp add: power2_eq_square abs_mult abs_mult_self)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   182
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   183
lemma power2_abs [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   184
  "(abs a)\<twosuperior> = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   185
  by (simp add: power2_eq_square abs_mult_self)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   186
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   187
lemma odd_power_less_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   188
  "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   189
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   190
  case 0
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   191
  then show ?case by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   192
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   193
  case (Suc n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   194
  have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   195
    by (simp add: mult_ac power_add power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   196
  thus ?case
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   197
    by (simp del: power_Suc add: Suc mult_less_0_iff mult_neg_neg)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   198
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   199
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   200
lemma odd_0_le_power_imp_0_le:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   201
  "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   202
  using odd_power_less_zero [of a n]
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   203
    by (force simp add: linorder_not_less [symmetric]) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   204
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   205
lemma zero_le_even_power'[simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   206
  "0 \<le> a ^ (2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   207
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   208
  case 0
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   209
    show ?case by simp
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   210
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   211
  case (Suc n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   212
    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   213
      by (simp add: mult_ac power_add power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   214
    thus ?case
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   215
      by (simp add: Suc zero_le_mult_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   216
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   217
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   218
lemma sum_power2_ge_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   219
  "0 \<le> x\<twosuperior> + y\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   220
  unfolding power2_eq_square by (rule sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   221
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   222
lemma not_sum_power2_lt_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   223
  "\<not> x\<twosuperior> + y\<twosuperior> < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   224
  unfolding power2_eq_square by (rule not_sum_squares_lt_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   225
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   226
lemma sum_power2_eq_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   227
  "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   228
  unfolding power2_eq_square by (rule sum_squares_eq_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   229
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   230
lemma sum_power2_le_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   231
  "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   232
  unfolding power2_eq_square by (rule sum_squares_le_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   233
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   234
lemma sum_power2_gt_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   235
  "0 < x\<twosuperior> + y\<twosuperior> \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   236
  unfolding power2_eq_square by (rule sum_squares_gt_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   237
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   238
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   239
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   240
lemma power2_sum:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   241
  fixes x y :: "'a::comm_semiring_1"
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   242
  shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   243
  by (simp add: algebra_simps power2_eq_square mult_2_right)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   244
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   245
lemma power2_diff:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   246
  fixes x y :: "'a::comm_ring_1"
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   247
  shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   248
  by (simp add: ring_distribs power2_eq_square mult_2) (rule mult_commute)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   249
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   250
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   251
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   252
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   253
declare nat_1 [simp]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   254
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   255
lemma nat_neg_numeral [simp]: "nat (neg_numeral w) = 0"
36719
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
   256
  by simp
d396f6f63d94 moved some lemmas from Groebner_Basis here
haftmann
parents: 36716
diff changeset
   257
46026
83caa4f4bd56 semiring_numeral_0_eq_0, semiring_numeral_1_eq_1 now [simp], superseeding corresponding simp rules on type nat
haftmann
parents: 45607
diff changeset
   258
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   259
  by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   260
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   261
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   262
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   263
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   264
lemma int_numeral: "int (numeral v) = numeral v"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   265
  by (rule of_nat_numeral) (* already simp *)
23307
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   266
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 43526
diff changeset
   267
lemma nonneg_int_cases:
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 43526
diff changeset
   268
  fixes k :: int assumes "0 \<le> k" obtains n where "k = of_nat n"
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 43526
diff changeset
   269
  using assms by (cases k, simp, simp)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   270
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   271
subsubsection{*Successor *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   272
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   273
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   274
apply (rule sym)
44766
d4d33a4d7548 avoid using legacy theorem names
huffman
parents: 44345
diff changeset
   275
apply (simp add: nat_eq_iff)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   276
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   277
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   278
lemma Suc_nat_number_of_add:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   279
  "Suc (numeral v + n) = numeral (v + Num.One) + n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   280
  by simp
30081
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   281
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   282
lemma Suc_numeral [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   283
  "Suc (numeral v) = numeral (v + Num.One)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   284
  by simp
30081
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   285
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   286
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   287
subsubsection{*Subtraction *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   288
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   289
lemma diff_nat_eq_if:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   290
     "nat z - nat z' =  
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   291
        (if z' < 0 then nat z   
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   292
         else let d = z-z' in     
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   293
              if d < 0 then 0 else nat d)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   294
by (simp add: Let_def nat_diff_distrib [symmetric])
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   295
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   296
(* Int.nat_diff_distrib has too-strong premises *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   297
lemma nat_diff_distrib': "\<lbrakk>0 \<le> x; 0 \<le> y\<rbrakk> \<Longrightarrow> nat (x - y) = nat x - nat y"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   298
apply (rule int_int_eq [THEN iffD1], clarsimp)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   299
apply (subst zdiff_int [symmetric])
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   300
apply (rule nat_mono, simp_all)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   301
done
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   302
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   303
lemma diff_nat_numeral [simp]: 
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   304
  "(numeral v :: nat) - numeral v' = nat (numeral v - numeral v')"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   305
  by (simp only: nat_diff_distrib' zero_le_numeral nat_numeral)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   306
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   307
lemma nat_numeral_diff_1 [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   308
  "numeral v - (1::nat) = nat (numeral v - 1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   309
  using diff_nat_numeral [of v Num.One] by simp
43531
cc46a678faaf added number_semiring class, plus a few new lemmas;
huffman
parents: 43526
diff changeset
   310
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   311
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   312
subsection{*Comparisons*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   314
(*Maps #n to n for n = 1, 2*)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   315
lemmas numerals = numeral_1_eq_1 [where 'a=nat] numeral_2_eq_2
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   318
subsection{*Powers with Numeric Exponents*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   319
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
text{*Squares of literal numerals will be evaluated.*}
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   321
(* FIXME: replace with more general rules for powers of numerals *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   322
lemmas power2_eq_square_numeral [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   323
    power2_eq_square [of "numeral w"] for w
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   324
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   325
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
text{*Simprules for comparisons where common factors can be cancelled.*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
lemmas zero_compare_simps =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
    add_strict_increasing add_strict_increasing2 add_increasing
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
    zero_le_mult_iff zero_le_divide_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
    zero_less_mult_iff zero_less_divide_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   331
    mult_le_0_iff divide_le_0_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   332
    mult_less_0_iff divide_less_0_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   333
    zero_le_power2 power2_less_0
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   334
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   335
subsubsection{*Nat *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   336
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   338
by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
(*Expresses a natural number constant as the Suc of another one.
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   341
  NOT suitable for rewriting because n recurs on the right-hand side.*)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   342
lemmas expand_Suc = Suc_pred' [of "numeral v", OF zero_less_numeral] for v
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
subsubsection{*Arith *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31182
diff changeset
   346
lemma Suc_eq_plus1: "Suc n = n + 1"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   347
  unfolding One_nat_def by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   348
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31182
diff changeset
   349
lemma Suc_eq_plus1_left: "Suc n = 1 + n"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   350
  unfolding One_nat_def by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   352
(* These two can be useful when m = numeral... *)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   353
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   354
lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))"
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 29958
diff changeset
   355
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))"
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 29958
diff changeset
   358
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   359
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   360
lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))"
30079
293b896b9c25 make proofs work whether or not One_nat_def is a simp rule; replace 1 with Suc 0 in the rhs of some simp rules
huffman
parents: 29958
diff changeset
   361
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   363
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   364
subsection{*Comparisons involving  @{term Suc} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   365
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   366
lemma eq_numeral_Suc [simp]: "numeral v = Suc n \<longleftrightarrow> nat (numeral v - 1) = n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   367
  by (subst expand_Suc, simp only: nat.inject nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   368
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   369
lemma Suc_eq_numeral [simp]: "Suc n = numeral v \<longleftrightarrow> n = nat (numeral v - 1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   370
  by (subst expand_Suc, simp only: nat.inject nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   371
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   372
lemma less_numeral_Suc [simp]: "numeral v < Suc n \<longleftrightarrow> nat (numeral v - 1) < n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   373
  by (subst expand_Suc, simp only: Suc_less_eq nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   374
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   375
lemma less_Suc_numeral [simp]: "Suc n < numeral v \<longleftrightarrow> n < nat (numeral v - 1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   376
  by (subst expand_Suc, simp only: Suc_less_eq nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   377
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   378
lemma le_numeral_Suc [simp]: "numeral v \<le> Suc n \<longleftrightarrow> nat (numeral v - 1) \<le> n"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   379
  by (subst expand_Suc, simp only: Suc_le_mono nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   380
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   381
lemma le_Suc_numeral [simp]: "Suc n \<le> numeral v \<longleftrightarrow> n \<le> nat (numeral v - 1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   382
  by (subst expand_Suc, simp only: Suc_le_mono nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   383
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   384
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   385
subsection{*Max and Min Combined with @{term Suc} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   386
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   387
lemma max_Suc_numeral [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   388
  "max (Suc n) (numeral v) = Suc (max n (nat (numeral v - 1)))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   389
  by (subst expand_Suc, simp only: max_Suc_Suc nat_numeral_diff_1)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   390
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   391
lemma max_numeral_Suc [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   392
  "max (numeral v) (Suc n) = Suc (max (nat (numeral v - 1)) n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   393
  by (subst expand_Suc, simp only: max_Suc_Suc nat_numeral_diff_1)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   394
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   395
lemma min_Suc_numeral [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   396
  "min (Suc n) (numeral v) = Suc (min n (nat (numeral v - 1)))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   397
  by (subst expand_Suc, simp only: min_Suc_Suc nat_numeral_diff_1)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   398
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   399
lemma min_numeral_Suc [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   400
  "min (numeral v) (Suc n) = Suc (min (nat (numeral v - 1)) n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   401
  by (subst expand_Suc, simp only: min_Suc_Suc nat_numeral_diff_1)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   402
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   403
subsection{*Literal arithmetic involving powers*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   404
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   405
(* TODO: replace with more generic rule for powers of numerals *)
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   406
lemma power_nat_numeral:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   407
  "(numeral v :: nat) ^ n = nat ((numeral v :: int) ^ n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   408
  by (simp only: nat_power_eq zero_le_numeral nat_numeral)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   409
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   410
lemmas power_nat_numeral_numeral = power_nat_numeral [of _ "numeral w"] for w
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   411
declare power_nat_numeral_numeral [simp]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   412
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   414
text{*For arbitrary rings*}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   415
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   416
lemma power_numeral_even:
43526
2b92a6943915 generalize lemmas power_number_of_even and power_number_of_odd
huffman
parents: 40690
diff changeset
   417
  fixes z :: "'a::monoid_mult"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   418
  shows "z ^ numeral (Num.Bit0 w) = (let w = z ^ (numeral w) in w * w)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   419
  unfolding numeral_Bit0 power_add Let_def ..
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   421
lemma power_numeral_odd:
43526
2b92a6943915 generalize lemmas power_number_of_even and power_number_of_odd
huffman
parents: 40690
diff changeset
   422
  fixes z :: "'a::monoid_mult"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   423
  shows "z ^ numeral (Num.Bit1 w) = (let w = z ^ (numeral w) in z * w * w)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   424
  unfolding numeral_Bit1 One_nat_def add_Suc_right add_0_right
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   425
  unfolding power_Suc power_add Let_def mult_assoc ..
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   426
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   427
lemmas zpower_numeral_even = power_numeral_even [where 'a=int]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   428
lemmas zpower_numeral_odd = power_numeral_odd [where 'a=int]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   429
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   430
lemmas power_numeral_even_numeral [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   431
    power_numeral_even [of "numeral v"] for v
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   432
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   433
lemmas power_numeral_odd_numeral [simp] =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   434
    power_numeral_odd [of "numeral v"] for v
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   435
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   436
lemma nat_numeral_Bit0:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   437
  "numeral (Num.Bit0 w) = (let n::nat = numeral w in n + n)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   438
  unfolding numeral_Bit0 Let_def ..
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   439
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   440
lemma nat_numeral_Bit1:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   441
  "numeral (Num.Bit1 w) = (let n = numeral w in Suc (n + n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   442
  unfolding numeral_Bit1 Let_def by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   443
40077
c8a9eaaa2f59 nat_number -> eval_nat_numeral
nipkow
parents: 36964
diff changeset
   444
lemmas eval_nat_numeral =
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   445
  nat_numeral_Bit0 nat_numeral_Bit1
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   446
36699
816da1023508 moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents: 35815
diff changeset
   447
lemmas nat_arith =
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   448
  diff_nat_numeral
36699
816da1023508 moved nat_arith ot Nat_Numeral: clarified normalizer setup
haftmann
parents: 35815
diff changeset
   449
36716
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36699
diff changeset
   450
lemmas semiring_norm =
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   451
  Let_def arith_simps nat_arith rel_simps
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   452
  if_False if_True
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   453
  add_0 add_Suc add_numeral_left
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   454
  add_neg_numeral_left mult_numeral_left
36716
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36699
diff changeset
   455
  numeral_1_eq_1 [symmetric] Suc_eq_plus1
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   456
  eq_numeral_iff_iszero not_iszero_Numeral1
36716
b09f3ad3208f moved generic lemmas to appropriate places
haftmann
parents: 36699
diff changeset
   457
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   459
  by (fact Let_def)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   460
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   461
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::ring_1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   462
  by (fact power_minus1_even) (* FIXME: duplicate *)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   464
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::ring_1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   465
  by (fact power_minus1_odd) (* FIXME: duplicate *)
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   466
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   468
subsection{*Literal arithmetic and @{term of_nat}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   469
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   470
lemma of_nat_double:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   471
     "0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   472
by (simp only: mult_2 nat_add_distrib of_nat_add) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   473
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   475
subsubsection{*For simplifying @{term "Suc m - K"} and  @{term "K - Suc m"}*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   476
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   477
text{*Where K above is a literal*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   478
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   479
lemma Suc_diff_eq_diff_pred: "0 < n ==> Suc m - n = m - (n - Numeral1)"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   480
by (simp split: nat_diff_split)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   481
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   482
text{*No longer required as a simprule because of the @{text inverse_fold}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   483
   simproc*}
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   484
lemma Suc_diff_numeral: "Suc m - (numeral v) = m - (numeral v - 1)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   485
  by (subst expand_Suc, simp only: diff_Suc_Suc)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   486
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   487
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n"
35216
7641e8d831d2 get rid of many duplicate simp rule warnings
huffman
parents: 35047
diff changeset
   488
by (simp split: nat_diff_split)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   489
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   490
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   491
subsubsection{*For @{term nat_case} and @{term nat_rec}*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   492
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   493
lemma nat_case_numeral [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   494
  "nat_case a f (numeral v) = (let pv = nat (numeral v - 1) in f pv)"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   495
  by (subst expand_Suc, simp only: nat.cases nat_numeral_diff_1 Let_def)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   496
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   497
lemma nat_case_add_eq_if [simp]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   498
  "nat_case a f ((numeral v) + n) = (let pv = nat (numeral v - 1) in f (pv + n))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   499
  by (subst expand_Suc, simp only: nat.cases nat_numeral_diff_1 Let_def add_Suc)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   500
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   501
lemma nat_rec_numeral [simp]:
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   502
  "nat_rec a f (numeral v) = (let pv = nat (numeral v - 1) in f pv (nat_rec a f pv))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   503
  by (subst expand_Suc, simp only: nat_rec_Suc nat_numeral_diff_1 Let_def)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   504
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   505
lemma nat_rec_add_eq_if [simp]:
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   506
  "nat_rec a f (numeral v + n) =
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   507
    (let pv = nat (numeral v - 1) in f (pv + n) (nat_rec a f (pv + n)))"
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   508
  by (subst expand_Suc, simp only: nat_rec_Suc nat_numeral_diff_1 Let_def add_Suc)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   509
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   510
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   511
subsubsection{*Various Other Lemmas*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   512
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   513
lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2"
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   514
by(simp add: UNIV_bool)
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   515
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   516
text {*Evens and Odds, for Mutilated Chess Board*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   517
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   518
text{*Lemmas for specialist use, NOT as default simprules*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   519
lemma nat_mult_2: "2 * z = (z+z::nat)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   520
by (rule mult_2) (* FIXME: duplicate *)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   521
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   522
lemma nat_mult_2_right: "z * 2 = (z+z::nat)"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   523
by (rule mult_2_right) (* FIXME: duplicate *)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   524
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   525
text{*Case analysis on @{term "n<2"}*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   526
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0"
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   527
by (auto simp add: numeral_2_eq_2)
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   528
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   529
text{*Removal of Small Numerals: 0, 1 and (in additive positions) 2*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   530
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   531
lemma add_2_eq_Suc [simp]: "2 + n = Suc (Suc n)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   532
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   533
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   534
lemma add_2_eq_Suc' [simp]: "n + 2 = Suc (Suc n)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   535
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   536
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   537
text{*Can be used to eliminate long strings of Sucs, but not by default*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   538
lemma Suc3_eq_add_3: "Suc (Suc (Suc n)) = 3 + n"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   539
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   540
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   541
text{*Legacy theorems*}
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   542
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   543
lemmas nat_1_add_1 = one_add_one [where 'a=nat]
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46026
diff changeset
   544
31096
e546e15089ef newline at end of file
huffman
parents: 31080
diff changeset
   545
end