src/HOL/Nat_Numeral.thy
author blanchet
Thu, 29 Oct 2009 12:09:32 +0100
changeset 33566 1c62ac4ef6d1
parent 33296 a3924d1069e5
child 33342 df8b5c05546f
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
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    18
instantiation nat :: number
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    19
begin
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    20
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    21
definition
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
    22
  nat_number_of_def [code_unfold, code del]: "number_of v = nat (number_of v)"
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    23
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    24
instance ..
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    25
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    26
end
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    27
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31790
diff changeset
    28
lemma [code_post]:
25965
05df64f786a4 improved code theorem setup
haftmann
parents: 25919
diff changeset
    29
  "nat (number_of v) = number_of v"
05df64f786a4 improved code theorem setup
haftmann
parents: 25919
diff changeset
    30
  unfolding nat_number_of_def ..
05df64f786a4 improved code theorem setup
haftmann
parents: 25919
diff changeset
    31
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    32
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    33
subsection {* Special case: squares and cubes *}
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    34
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    35
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    36
  by (simp add: nat_number_of_def)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    37
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    38
lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    39
  by (simp add: nat_number_of_def)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    40
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    41
context power
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    42
begin
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    43
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    44
abbreviation (xsymbols)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    45
  power2 :: "'a \<Rightarrow> 'a"  ("(_\<twosuperior>)" [1000] 999) where
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    46
  "x\<twosuperior> \<equiv> x ^ 2"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    47
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    48
notation (latex output)
29401
94fd5dd918f5 rename abbreviation square -> power2, to match theorem names
huffman
parents: 29045
diff changeset
    49
  power2  ("(_\<twosuperior>)" [1000] 999)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    50
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    51
notation (HTML output)
29401
94fd5dd918f5 rename abbreviation square -> power2, to match theorem names
huffman
parents: 29045
diff changeset
    52
  power2  ("(_\<twosuperior>)" [1000] 999)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    53
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    54
end
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    55
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    56
context monoid_mult
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    57
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    58
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    59
lemma power2_eq_square: "a\<twosuperior> = a * a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    60
  by (simp add: numeral_2_eq_2)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    61
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    62
lemma power3_eq_cube: "a ^ 3 = a * a * a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    63
  by (simp add: numeral_3_eq_3 mult_assoc)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    64
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    65
lemma power_even_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    66
  "a ^ (2*n) = (a ^ n) ^ 2"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    67
  by (subst OrderedGroup.mult_commute) (simp add: power_mult)
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
lemma power_odd_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    70
  "a ^ Suc (2*n) = a * (a ^ n) ^ 2"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    71
  by (simp add: power_even_eq)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    72
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    73
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    74
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    75
context semiring_1
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    76
begin
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 zero_power2 [simp]: "0\<twosuperior> = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    79
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    80
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    81
lemma one_power2 [simp]: "1\<twosuperior> = 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    82
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    83
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    84
end
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
context comm_ring_1
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    87
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    88
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    89
lemma power2_minus [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    90
  "(- a)\<twosuperior> = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    91
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    92
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    93
text{*
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    94
  We cannot prove general results about the numeral @{term "-1"},
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    95
  so we have to use @{term "- 1"} instead.
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    96
*}
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    97
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    98
lemma power_minus1_even [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    99
  "(- 1) ^ (2*n) = 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   100
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   101
  case 0 show ?case by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   102
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   103
  case (Suc n) then show ?case by (simp add: power_add)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   104
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   105
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   106
lemma power_minus1_odd:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   107
  "(- 1) ^ Suc (2*n) = - 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   108
  by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   109
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   110
lemma power_minus_even [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   111
  "(-a) ^ (2*n) = a ^ (2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   112
  by (simp add: power_minus [of a]) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   113
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   114
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   115
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   116
context ordered_ring_strict
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   117
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   118
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   119
lemma sum_squares_ge_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   120
  "0 \<le> x * x + y * y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   121
  by (intro add_nonneg_nonneg zero_le_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   122
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   123
lemma not_sum_squares_lt_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   124
  "\<not> x * x + y * y < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   125
  by (simp add: not_less sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   126
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   127
lemma sum_squares_eq_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   128
  "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
   129
  by (simp add: add_nonneg_eq_0_iff)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   130
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   131
lemma sum_squares_le_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   132
  "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   133
  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
   134
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   135
lemma sum_squares_gt_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   136
  "0 < x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   137
proof -
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   138
  have "x * x + y * y \<noteq> 0 \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   139
    by (simp add: sum_squares_eq_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   140
  then have "0 \<noteq> x * x + y * y \<longleftrightarrow> x \<noteq> 0 \<or> y \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   141
    by auto
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   142
  then show ?thesis
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   143
    by (simp add: less_le sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   144
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   145
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   146
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   147
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   148
context ordered_semidom
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   149
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   150
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   151
lemma power2_le_imp_le:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   152
  "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
   153
  unfolding numeral_2_eq_2 by (rule power_le_imp_le_base)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   154
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   155
lemma power2_less_imp_less:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   156
  "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   157
  by (rule power_less_imp_less_base)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   158
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   159
lemma power2_eq_imp_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   160
  "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
   161
  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
   162
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   163
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   164
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   165
context ordered_idom
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   166
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   167
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   168
lemma zero_eq_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   169
  "a\<twosuperior> = 0 \<longleftrightarrow> a = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   170
  by (force simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   171
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   172
lemma zero_le_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   173
  "0 \<le> a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   174
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   175
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   176
lemma zero_less_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   177
  "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   178
  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
   179
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   180
lemma power2_less_0 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   181
  "\<not> a\<twosuperior> < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   182
  by (force simp add: power2_eq_square mult_less_0_iff) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   183
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   184
lemma abs_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   185
  "abs (a\<twosuperior>) = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   186
  by (simp add: power2_eq_square abs_mult abs_mult_self)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   187
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   188
lemma power2_abs [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   189
  "(abs a)\<twosuperior> = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   190
  by (simp add: power2_eq_square abs_mult_self)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   191
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   192
lemma odd_power_less_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   193
  "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   194
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   195
  case 0
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   196
  then show ?case by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   197
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   198
  case (Suc n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   199
  have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   200
    by (simp add: mult_ac power_add power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   201
  thus ?case
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   202
    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
   203
qed
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 odd_0_le_power_imp_0_le:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   206
  "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   207
  using odd_power_less_zero [of a n]
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   208
    by (force simp add: linorder_not_less [symmetric]) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   209
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   210
lemma zero_le_even_power'[simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   211
  "0 \<le> a ^ (2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   212
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   213
  case 0
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   214
    show ?case by (simp add: zero_le_one)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   215
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   216
  case (Suc n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   217
    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   218
      by (simp add: mult_ac power_add power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   219
    thus ?case
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   220
      by (simp add: Suc zero_le_mult_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   221
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   222
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   223
lemma sum_power2_ge_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   224
  "0 \<le> x\<twosuperior> + y\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   225
  unfolding power2_eq_square by (rule sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   226
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   227
lemma not_sum_power2_lt_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   228
  "\<not> x\<twosuperior> + y\<twosuperior> < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   229
  unfolding power2_eq_square by (rule not_sum_squares_lt_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   230
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   231
lemma sum_power2_eq_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   232
  "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   233
  unfolding power2_eq_square by (rule sum_squares_eq_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   234
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   235
lemma sum_power2_le_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   236
  "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   237
  unfolding power2_eq_square by (rule sum_squares_le_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   238
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   239
lemma sum_power2_gt_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   240
  "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
   241
  unfolding power2_eq_square by (rule sum_squares_gt_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   242
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   243
end
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_sum:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   246
  fixes x y :: "'a::number_ring"
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
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   250
lemma power2_diff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   251
  fixes x y :: "'a::number_ring"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   252
  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
   253
  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
   254
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   255
29040
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   256
subsection {* Predicate for negative binary numbers *}
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   257
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   258
definition neg  :: "int \<Rightarrow> bool" where
29040
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   259
  "neg Z \<longleftrightarrow> Z < 0"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   260
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   261
lemma not_neg_int [simp]: "~ neg (of_nat n)"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   262
by (simp add: neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   263
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   264
lemma neg_zminus_int [simp]: "neg (- (of_nat (Suc n)))"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   265
by (simp add: neg_def neg_less_0_iff_less del: of_nat_Suc)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   266
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   267
lemmas neg_eq_less_0 = neg_def
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   268
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   269
lemma not_neg_eq_ge_0: "(~neg x) = (0 \<le> x)"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   270
by (simp add: neg_def linorder_not_less)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   271
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   272
text{*To simplify inequalities when Numeral1 can get simplified to 1*}
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   273
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   274
lemma not_neg_0: "~ neg 0"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   275
by (simp add: One_int_def neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   276
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   277
lemma not_neg_1: "~ neg 1"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   278
by (simp add: neg_def linorder_not_less zero_le_one)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   279
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   280
lemma neg_nat: "neg z ==> nat z = 0"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   281
by (simp add: neg_def order_less_imp_le) 
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   282
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   283
lemma not_neg_nat: "~ neg z ==> of_nat (nat z) = z"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   284
by (simp add: linorder_not_less neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   285
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   286
text {*
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   287
  If @{term Numeral0} is rewritten to 0 then this rule can't be applied:
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   288
  @{term Numeral0} IS @{term "number_of Pls"}
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   289
*}
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   290
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   291
lemma not_neg_number_of_Pls: "~ neg (number_of Int.Pls)"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   292
  by (simp add: neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   293
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   294
lemma neg_number_of_Min: "neg (number_of Int.Min)"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   295
  by (simp add: neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   296
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   297
lemma neg_number_of_Bit0:
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   298
  "neg (number_of (Int.Bit0 w)) = neg (number_of w)"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   299
  by (simp add: neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   300
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   301
lemma neg_number_of_Bit1:
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   302
  "neg (number_of (Int.Bit1 w)) = neg (number_of w)"
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   303
  by (simp add: neg_def)
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   304
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   305
lemmas neg_simps [simp] =
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   306
  not_neg_0 not_neg_1
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   307
  not_neg_number_of_Pls neg_number_of_Min
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   308
  neg_number_of_Bit0 neg_number_of_Bit1
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   309
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   310
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   311
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   312
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
declare nat_0 [simp] nat_1 [simp]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   314
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   315
lemma nat_number_of [simp]: "nat (number_of w) = number_of w"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
by (simp add: nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31790
diff changeset
   318
lemma nat_numeral_0_eq_0 [simp, code_post]: "Numeral0 = (0::nat)"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   319
by (simp add: nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
by (simp add: nat_1 nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   323
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31790
diff changeset
   324
lemma numeral_1_eq_Suc_0 [code_post]: "Numeral1 = Suc 0"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   325
by (simp add: nat_numeral_1_eq_1)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
lemma int_nat_number_of [simp]:
23365
f31794033ae1 removed constant int :: nat => int;
huffman
parents: 23307
diff changeset
   331
     "int (number_of v) =  
23307
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   332
         (if neg (number_of v :: int) then 0  
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   333
          else (number_of v :: int))"
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   334
  unfolding nat_number_of_def number_of_is_id neg_def
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   335
  by simp
23307
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   336
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   337
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
subsubsection{*Successor *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
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
   341
apply (rule sym)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   342
apply (simp add: nat_eq_iff int_Suc)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
lemma Suc_nat_number_of_add:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   346
     "Suc (number_of v + n) =  
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   347
        (if neg (number_of v :: int) then 1+n else number_of (Int.succ v) + n)"
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   348
  unfolding nat_number_of_def number_of_is_id neg_def numeral_simps
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   349
  by (simp add: Suc_nat_eq_nat_zadd1 add_ac)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   350
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
lemma Suc_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   352
     "Suc (number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   353
        (if neg (number_of v :: int) then 1 else number_of (Int.succ v))"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   354
apply (cut_tac n = 0 in Suc_nat_number_of_add)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   355
apply (simp cong del: if_weak_cong)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   358
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   359
subsubsection{*Addition *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   360
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   361
lemma add_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
     "(number_of v :: nat) + number_of v' =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   363
         (if v < Int.Pls then number_of v'  
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   364
          else if v' < Int.Pls then number_of v  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   365
          else number_of (v + v'))"
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   366
  unfolding nat_number_of_def number_of_is_id numeral_simps
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   367
  by (simp add: nat_add_distrib)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   368
30081
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   369
lemma nat_number_of_add_1 [simp]:
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   370
  "number_of v + (1::nat) =
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   371
    (if v < Int.Pls then 1 else number_of (Int.succ v))"
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   372
  unfolding nat_number_of_def number_of_is_id numeral_simps
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   373
  by (simp add: nat_add_distrib)
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   374
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   375
lemma nat_1_add_number_of [simp]:
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   376
  "(1::nat) + number_of v =
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   377
    (if v < Int.Pls then 1 else number_of (Int.succ v))"
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   378
  unfolding nat_number_of_def number_of_is_id numeral_simps
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   379
  by (simp add: nat_add_distrib)
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   380
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   381
lemma nat_1_add_1 [simp]: "1 + 1 = (2::nat)"
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   382
  by (rule int_int_eq [THEN iffD1]) simp
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   383
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   384
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   385
subsubsection{*Subtraction *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   386
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   387
lemma diff_nat_eq_if:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   388
     "nat z - nat z' =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   389
        (if neg z' then nat z   
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   390
         else let d = z-z' in     
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   391
              if neg d then 0 else nat d)"
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 26342
diff changeset
   392
by (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0)
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 26342
diff changeset
   393
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   394
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   395
lemma diff_nat_number_of [simp]: 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   396
     "(number_of v :: nat) - number_of v' =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   397
        (if v' < Int.Pls then number_of v  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   398
         else let d = number_of (v + uminus v') in     
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   399
              if neg d then 0 else nat d)"
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   400
  unfolding nat_number_of_def number_of_is_id numeral_simps neg_def
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   401
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   402
30081
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   403
lemma nat_number_of_diff_1 [simp]:
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   404
  "number_of v - (1::nat) =
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   405
    (if v \<le> Int.Pls then 0 else number_of (Int.pred v))"
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   406
  unfolding nat_number_of_def number_of_is_id numeral_simps
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   407
  by auto
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   408
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   409
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   410
subsubsection{*Multiplication *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   411
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   412
lemma mult_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
     "(number_of v :: nat) * number_of v' =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   414
       (if v < Int.Pls then 0 else number_of (v * v'))"
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   415
  unfolding nat_number_of_def number_of_is_id numeral_simps
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   416
  by (simp add: nat_mult_distrib)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   417
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   418
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   419
subsection{*Comparisons*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   421
subsubsection{*Equals (=) *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   422
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   423
lemma eq_nat_nat_iff:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   424
     "[| (0::int) <= z;  0 <= z' |] ==> (nat z = nat z') = (z=z')"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   425
by (auto elim!: nonneg_eq_int)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   426
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   427
lemma eq_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   428
     "((number_of v :: nat) = number_of v') =  
28969
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   429
      (if neg (number_of v :: int) then (number_of v' :: int) \<le> 0
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   430
       else if neg (number_of v' :: int) then (number_of v :: int) = 0
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   431
       else v = v')"
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   432
  unfolding nat_number_of_def number_of_is_id neg_def
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   433
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   434
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   435
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   436
subsubsection{*Less-than (<) *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   437
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   438
lemma less_nat_number_of [simp]:
29011
a47003001699 simplify less_nat_number_of
huffman
parents: 29010
diff changeset
   439
  "(number_of v :: nat) < number_of v' \<longleftrightarrow>
a47003001699 simplify less_nat_number_of
huffman
parents: 29010
diff changeset
   440
    (if v < v' then Int.Pls < v' else False)"
a47003001699 simplify less_nat_number_of
huffman
parents: 29010
diff changeset
   441
  unfolding nat_number_of_def number_of_is_id numeral_simps
28961
9f33ab8e15db simplify proof of less_nat_number_of
huffman
parents: 28562
diff changeset
   442
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   443
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   444
29010
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   445
subsubsection{*Less-than-or-equal *}
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   446
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   447
lemma le_nat_number_of [simp]:
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   448
  "(number_of v :: nat) \<le> number_of v' \<longleftrightarrow>
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   449
    (if v \<le> v' then True else v \<le> Int.Pls)"
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   450
  unfolding nat_number_of_def number_of_is_id numeral_simps
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   451
  by auto
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   452
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   453
(*Maps #n to n for n = 0, 1, 2*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   454
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   455
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   456
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   457
subsection{*Powers with Numeric Exponents*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   459
text{*Squares of literal numerals will be evaluated.*}
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   460
lemmas power2_eq_square_number_of [simp] =
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   461
    power2_eq_square [of "number_of w", standard]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   462
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   464
text{*Simprules for comparisons where common factors can be cancelled.*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   465
lemmas zero_compare_simps =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   466
    add_strict_increasing add_strict_increasing2 add_increasing
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
    zero_le_mult_iff zero_le_divide_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   468
    zero_less_mult_iff zero_less_divide_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   469
    mult_le_0_iff divide_le_0_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   470
    mult_less_0_iff divide_less_0_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   471
    zero_le_power2 power2_less_0
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   472
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   473
subsubsection{*Nat *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   475
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   476
by (simp add: numerals)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   477
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   478
(*Expresses a natural number constant as the Suc of another one.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   479
  NOT suitable for rewriting because n recurs in the condition.*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   480
lemmas expand_Suc = Suc_pred' [of "number_of v", standard]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   481
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   482
subsubsection{*Arith *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   483
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31182
diff changeset
   484
lemma Suc_eq_plus1: "Suc n = n + 1"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   485
by (simp add: numerals)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   486
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31182
diff changeset
   487
lemma Suc_eq_plus1_left: "Suc n = 1 + n"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   488
by (simp add: numerals)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   489
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   490
(* These two can be useful when m = number_of... *)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   491
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   492
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
   493
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   494
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   495
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
   496
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   497
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   498
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
   499
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   500
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   501
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   502
subsection{*Comparisons involving (0::nat) *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   503
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   504
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   505
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   506
lemma eq_number_of_0 [simp]:
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   507
  "number_of v = (0::nat) \<longleftrightarrow> v \<le> Int.Pls"
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   508
  unfolding nat_number_of_def number_of_is_id numeral_simps
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   509
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   510
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   511
lemma eq_0_number_of [simp]:
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   512
  "(0::nat) = number_of v \<longleftrightarrow> v \<le> Int.Pls"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   513
by (rule trans [OF eq_sym_conv eq_number_of_0])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   514
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   515
lemma less_0_number_of [simp]:
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   516
   "(0::nat) < number_of v \<longleftrightarrow> Int.Pls < v"
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   517
  unfolding nat_number_of_def number_of_is_id numeral_simps
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   518
  by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   519
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   520
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)"
28969
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   521
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric])
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   522
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   523
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   524
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   525
subsection{*Comparisons involving  @{term Suc} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   526
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   527
lemma eq_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   528
     "(number_of v = Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   529
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   530
         if neg pv then False else nat pv = n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   531
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   532
                  number_of_pred nat_number_of_def 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   533
            split add: split_if)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   534
apply (rule_tac x = "number_of v" in spec)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   535
apply (auto simp add: nat_eq_iff)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   536
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   537
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   538
lemma Suc_eq_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   539
     "(Suc n = number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   540
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   541
         if neg pv then False else nat pv = n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   542
by (rule trans [OF eq_sym_conv eq_number_of_Suc])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   543
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   544
lemma less_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   545
     "(number_of v < Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   546
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   547
         if neg pv then True else nat pv < n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   548
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   549
                  number_of_pred nat_number_of_def  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   550
            split add: split_if)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   551
apply (rule_tac x = "number_of v" in spec)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   552
apply (auto simp add: nat_less_iff)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   553
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   554
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   555
lemma less_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   556
     "(Suc n < number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   557
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   558
         if neg pv then False else n < nat pv)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   559
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   560
                  number_of_pred nat_number_of_def
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   561
            split add: split_if)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   562
apply (rule_tac x = "number_of v" in spec)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   563
apply (auto simp add: zless_nat_eq_int_zless)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   564
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   565
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   566
lemma le_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   567
     "(number_of v <= Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   568
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   569
         if neg pv then True else nat pv <= n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   570
by (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   571
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   572
lemma le_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   573
     "(Suc n <= number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   574
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   575
         if neg pv then False else n <= nat pv)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   576
by (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   577
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   578
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   579
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   580
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   581
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   582
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   583
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   584
subsection{*Max and Min Combined with @{term Suc} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   585
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   586
lemma max_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   587
     "max (Suc n) (number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   588
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   589
         if neg pv then Suc n else Suc(max n (nat pv)))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   590
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   591
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   592
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   593
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   594
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   595
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   596
lemma max_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   597
     "max (number_of v) (Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   598
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   599
         if neg pv then Suc n else Suc(max (nat pv) n))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   600
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   601
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   602
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   603
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   604
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   605
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   606
lemma min_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   607
     "min (Suc n) (number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   608
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   609
         if neg pv then 0 else Suc(min n (nat pv)))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   610
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   611
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   612
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   613
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   614
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   615
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   616
lemma min_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   617
     "min (number_of v) (Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   618
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   619
         if neg pv then 0 else Suc(min (nat pv) n))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   620
apply (simp only: Let_def neg_eq_less_0 number_of_pred nat_number_of_def 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   621
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   622
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   623
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   624
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   625
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   626
subsection{*Literal arithmetic involving powers*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   627
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   628
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   629
apply (induct "n")
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   630
apply (simp_all (no_asm_simp) add: nat_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   631
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   632
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   633
lemma power_nat_number_of:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   634
     "(number_of v :: nat) ^ n =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   635
       (if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   636
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   637
         split add: split_if cong: imp_cong)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   638
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   639
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   640
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   641
declare power_nat_number_of_number_of [simp]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   642
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   643
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   644
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   645
text{*For arbitrary rings*}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   646
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   647
lemma power_number_of_even:
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   648
  fixes z :: "'a::number_ring"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   649
  shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   650
by (cases "w \<ge> 0") (auto simp add: Let_def Bit0_def nat_number_of_def number_of_is_id
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   651
  nat_add_distrib power_add simp del: nat_number_of)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   652
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   653
lemma power_number_of_odd:
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   654
  fixes z :: "'a::number_ring"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   655
  shows "z ^ number_of (Int.Bit1 w) = (if (0::int) <= number_of w
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   656
     then (let w = z ^ (number_of w) in z * w * w) else 1)"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   657
apply (auto simp add: Let_def Bit1_def nat_number_of_def number_of_is_id
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   658
  mult_assoc nat_add_distrib power_add not_le simp del: nat_number_of)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   659
apply (simp add: not_le mult_2 [symmetric] add_assoc)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   660
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   661
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   662
lemmas zpower_number_of_even = power_number_of_even [where 'a=int]
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   663
lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   664
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   665
lemmas power_number_of_even_number_of [simp] =
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   666
    power_number_of_even [of "number_of v", standard]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   667
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   668
lemmas power_number_of_odd_number_of [simp] =
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   669
    power_number_of_odd [of "number_of v", standard]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   670
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   671
lemma nat_number_of_Pls: "Numeral0 = (0::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   672
  by (simp add: number_of_Pls nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   673
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   674
lemma nat_number_of_Min: "number_of Int.Min = (0::nat)"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   675
  apply (simp only: number_of_Min nat_number_of_def nat_zminus_int)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   676
  done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   677
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   678
lemma nat_number_of_Bit0:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   679
    "number_of (Int.Bit0 w) = (let n::nat = number_of w in n + n)"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   680
by (cases "w \<ge> 0") (auto simp add: Let_def Bit0_def nat_number_of_def number_of_is_id
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   681
  nat_add_distrib simp del: nat_number_of)
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   682
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   683
lemma nat_number_of_Bit1:
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   684
  "number_of (Int.Bit1 w) =
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   685
    (if neg (number_of w :: int) then 0
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   686
     else let n = number_of w in Suc (n + n))"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   687
apply (auto simp add: Let_def Bit1_def nat_number_of_def number_of_is_id neg_def
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   688
  nat_add_distrib simp del: nat_number_of)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   689
apply (simp add: mult_2 [symmetric] add_assoc)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   690
done
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   691
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   692
lemmas nat_number =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   693
  nat_number_of_Pls nat_number_of_Min
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   694
  nat_number_of_Bit0 nat_number_of_Bit1
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   695
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   696
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
   697
  by (fact Let_def)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   698
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   699
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring})"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   700
  by (simp only: number_of_Min power_minus1_even)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   701
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   702
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring})"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   703
  by (simp only: number_of_Min power_minus1_odd)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   704
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   705
lemma nat_number_of_add_left:
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   706
     "number_of v + (number_of v' + (k::nat)) =  
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   707
         (if neg (number_of v :: int) then number_of v' + k  
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   708
          else if neg (number_of v' :: int) then number_of v + k  
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   709
          else number_of (v + v') + k)"
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   710
by (auto simp add: neg_def)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   711
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   712
lemma nat_number_of_mult_left:
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   713
     "number_of v * (number_of v' * (k::nat)) =  
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   714
         (if v < Int.Pls then 0
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   715
          else number_of (v * v') * k)"
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   716
by (auto simp add: not_less Pls_def nat_number_of_def number_of_is_id
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   717
  nat_mult_distrib simp del: nat_number_of)
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   718
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   719
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   720
subsection{*Literal arithmetic and @{term of_nat}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   721
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   722
lemma of_nat_double:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   723
     "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
   724
by (simp only: mult_2 nat_add_distrib of_nat_add) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   725
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   726
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   727
by (simp only: nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   728
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   729
lemma of_nat_number_of_lemma:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   730
     "of_nat (number_of v :: nat) =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   731
         (if 0 \<le> (number_of v :: int) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   732
          then (number_of v :: 'a :: number_ring)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   733
          else 0)"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   734
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   735
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   736
lemma of_nat_number_of_eq [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   737
     "of_nat (number_of v :: nat) =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   738
         (if neg (number_of v :: int) then 0  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   739
          else (number_of v :: 'a :: number_ring))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   740
by (simp only: of_nat_number_of_lemma neg_def, simp) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   741
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   742
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   743
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
   744
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   745
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
   746
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   747
lemma Suc_diff_eq_diff_pred: "Numeral0 < n ==> Suc m - n = m - (n - Numeral1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   748
by (simp add: numeral_0_eq_0 numeral_1_eq_1 split add: nat_diff_split)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   749
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   750
text {*Now just instantiating @{text n} to @{text "number_of v"} does
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   751
  the right simplification, but with some redundant inequality
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   752
  tests.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   753
lemma neg_number_of_pred_iff_0:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   754
  "neg (number_of (Int.pred v)::int) = (number_of v = (0::nat))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   755
apply (subgoal_tac "neg (number_of (Int.pred v)) = (number_of v < Suc 0) ")
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   756
apply (simp only: less_Suc_eq_le le_0_eq)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   757
apply (subst less_number_of_Suc, simp)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   758
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   759
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   760
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
   761
   simproc*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   762
lemma Suc_diff_number_of:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   763
     "Int.Pls < v ==>
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   764
      Suc m - (number_of v) = m - (number_of (Int.pred v))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   765
apply (subst Suc_diff_eq_diff_pred)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   766
apply simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   767
apply (simp del: nat_numeral_1_eq_1)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   768
apply (auto simp only: diff_nat_number_of less_0_number_of [symmetric]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   769
                        neg_number_of_pred_iff_0)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   770
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   771
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   772
lemma diff_Suc_eq_diff_pred: "m - Suc n = (m - 1) - n"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   773
by (simp add: numerals split add: nat_diff_split)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   774
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   775
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   776
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
   777
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   778
lemma nat_case_number_of [simp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   779
     "nat_case a f (number_of v) =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   780
        (let pv = number_of (Int.pred v) in
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   781
         if neg pv then a else f (nat pv))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   782
by (simp split add: nat.split add: Let_def neg_number_of_pred_iff_0)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   783
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   784
lemma nat_case_add_eq_if [simp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   785
     "nat_case a f ((number_of v) + n) =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   786
       (let pv = number_of (Int.pred v) in
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   787
         if neg pv then nat_case a f n else f (nat pv + n))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   788
apply (subst add_eq_if)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   789
apply (simp split add: nat.split
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   790
            del: nat_numeral_1_eq_1
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   791
            add: nat_numeral_1_eq_1 [symmetric]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   792
                 numeral_1_eq_Suc_0 [symmetric]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   793
                 neg_number_of_pred_iff_0)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   794
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   795
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   796
lemma nat_rec_number_of [simp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   797
     "nat_rec a f (number_of v) =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   798
        (let pv = number_of (Int.pred v) in
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   799
         if neg pv then a else f (nat pv) (nat_rec a f (nat pv)))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   800
apply (case_tac " (number_of v) ::nat")
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   801
apply (simp_all (no_asm_simp) add: Let_def neg_number_of_pred_iff_0)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   802
apply (simp split add: split_if_asm)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   803
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   804
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   805
lemma nat_rec_add_eq_if [simp]:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   806
     "nat_rec a f (number_of v + n) =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   807
        (let pv = number_of (Int.pred v) in
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   808
         if neg pv then nat_rec a f n
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   809
                   else f (nat pv + n) (nat_rec a f (nat pv + n)))"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   810
apply (subst add_eq_if)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   811
apply (simp split add: nat.split
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   812
            del: nat_numeral_1_eq_1
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   813
            add: nat_numeral_1_eq_1 [symmetric]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   814
                 numeral_1_eq_Suc_0 [symmetric]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   815
                 neg_number_of_pred_iff_0)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   816
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   817
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   818
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   819
subsubsection{*Various Other Lemmas*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   820
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   821
lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2"
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   822
by(simp add: UNIV_bool)
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   823
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   824
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
   825
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   826
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
   827
lemma nat_mult_2: "2 * z = (z+z::nat)"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   828
unfolding nat_1_add_1 [symmetric] left_distrib by simp
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   829
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   830
lemma nat_mult_2_right: "z * 2 = (z+z::nat)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   831
by (subst mult_commute, rule nat_mult_2)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   832
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   833
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
   834
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0"
33296
a3924d1069e5 moved theory Divides after theory Nat_Numeral; tuned some proof texts
haftmann
parents: 32069
diff changeset
   835
by (auto simp add: nat_1_add_1 [symmetric])
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   836
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   837
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
   838
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   839
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
   840
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   841
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   842
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
   843
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   844
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   845
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
   846
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
   847
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   848
31096
e546e15089ef newline at end of file
huffman
parents: 31080
diff changeset
   849
end