src/HOL/Nat_Numeral.thy
author wenzelm
Tue, 21 Jul 2009 01:03:18 +0200
changeset 32091 30e2ffbba718
parent 32069 6d28bbd33e2c
child 33296 a3924d1069e5
permissions -rw-r--r--
proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
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
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
     9
imports IntDiv
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31034
diff changeset
    10
uses ("Tools/nat_numeral_simprocs.ML")
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    11
begin
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    12
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    13
subsection {* Numerals for natural numbers *}
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    14
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    15
text {*
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    16
  Arithmetic for naturals is reduced to that for the non-negative integers.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    17
*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    18
25571
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    19
instantiation nat :: number
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    20
begin
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    21
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    22
definition
32069
6d28bbd33e2c prefer code_inline over code_unfold; use code_unfold_post where appropriate
haftmann
parents: 31998
diff changeset
    23
  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
    24
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    25
instance ..
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    26
c9e39eafc7a0 instantiation target rather than legacy instance
haftmann
parents: 25481
diff changeset
    27
end
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    28
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31790
diff changeset
    29
lemma [code_post]:
25965
05df64f786a4 improved code theorem setup
haftmann
parents: 25919
diff changeset
    30
  "nat (number_of v) = number_of v"
05df64f786a4 improved code theorem setup
haftmann
parents: 25919
diff changeset
    31
  unfolding nat_number_of_def ..
05df64f786a4 improved code theorem setup
haftmann
parents: 25919
diff changeset
    32
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    33
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    34
subsection {* Special case: squares and cubes *}
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    35
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    36
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    37
  by (simp add: nat_number_of_def)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    38
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    39
lemma numeral_3_eq_3: "3 = Suc (Suc (Suc 0))"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    40
  by (simp add: nat_number_of_def)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    41
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    42
context power
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    43
begin
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    44
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    45
abbreviation (xsymbols)
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    46
  power2 :: "'a \<Rightarrow> 'a"  ("(_\<twosuperior>)" [1000] 999) where
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    47
  "x\<twosuperior> \<equiv> x ^ 2"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    48
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    49
notation (latex output)
29401
94fd5dd918f5 rename abbreviation square -> power2, to match theorem names
huffman
parents: 29045
diff changeset
    50
  power2  ("(_\<twosuperior>)" [1000] 999)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    51
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    52
notation (HTML output)
29401
94fd5dd918f5 rename abbreviation square -> power2, to match theorem names
huffman
parents: 29045
diff changeset
    53
  power2  ("(_\<twosuperior>)" [1000] 999)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
    54
30960
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    55
end
fec1a04b7220 power operation defined generic
haftmann
parents: 30925
diff changeset
    56
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    57
context monoid_mult
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    58
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    59
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    60
lemma power2_eq_square: "a\<twosuperior> = a * a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    61
  by (simp add: numeral_2_eq_2)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    62
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    63
lemma power3_eq_cube: "a ^ 3 = a * a * a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    64
  by (simp add: numeral_3_eq_3 mult_assoc)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    65
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    66
lemma power_even_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    67
  "a ^ (2*n) = (a ^ n) ^ 2"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    68
  by (subst OrderedGroup.mult_commute) (simp add: power_mult)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    69
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    70
lemma power_odd_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    71
  "a ^ Suc (2*n) = a * (a ^ n) ^ 2"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    72
  by (simp add: power_even_eq)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    73
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    74
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    75
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    76
context semiring_1
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    77
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    78
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    79
lemma zero_power2 [simp]: "0\<twosuperior> = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    80
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    81
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    82
lemma one_power2 [simp]: "1\<twosuperior> = 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    83
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    84
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    85
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    86
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    87
context comm_ring_1
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    88
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    89
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    90
lemma power2_minus [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    91
  "(- a)\<twosuperior> = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    92
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    93
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    94
text{*
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    95
  We cannot prove general results about the numeral @{term "-1"},
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    96
  so we have to use @{term "- 1"} instead.
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
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
    99
lemma power_minus1_even [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   100
  "(- 1) ^ (2*n) = 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   101
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   102
  case 0 show ?case by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   103
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   104
  case (Suc n) then show ?case by (simp add: power_add)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   105
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   106
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   107
lemma power_minus1_odd:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   108
  "(- 1) ^ Suc (2*n) = - 1"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   109
  by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   110
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   111
lemma power_minus_even [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   112
  "(-a) ^ (2*n) = a ^ (2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   113
  by (simp add: power_minus [of a]) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   114
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   115
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   116
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   117
context ordered_ring_strict
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   118
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   119
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   120
lemma sum_squares_ge_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   121
  "0 \<le> x * x + y * y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   122
  by (intro add_nonneg_nonneg zero_le_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   123
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   124
lemma not_sum_squares_lt_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   125
  "\<not> x * x + y * y < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   126
  by (simp add: not_less sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   127
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   128
lemma sum_squares_eq_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   129
  "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
   130
  by (simp add: add_nonneg_eq_0_iff)
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   131
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   132
lemma sum_squares_le_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   133
  "x * x + y * y \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   134
  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
   135
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   136
lemma sum_squares_gt_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   137
  "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
   138
proof -
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   139
  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
   140
    by (simp add: sum_squares_eq_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   141
  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
   142
    by auto
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   143
  then show ?thesis
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   144
    by (simp add: less_le sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   145
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   146
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   147
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   148
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   149
context ordered_semidom
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   150
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   151
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   152
lemma power2_le_imp_le:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   153
  "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
   154
  unfolding numeral_2_eq_2 by (rule power_le_imp_le_base)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   155
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   156
lemma power2_less_imp_less:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   157
  "x\<twosuperior> < y\<twosuperior> \<Longrightarrow> 0 \<le> y \<Longrightarrow> x < y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   158
  by (rule power_less_imp_less_base)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   159
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   160
lemma power2_eq_imp_eq:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   161
  "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
   162
  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
   163
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   164
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   165
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   166
context ordered_idom
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   167
begin
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   168
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   169
lemma zero_eq_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   170
  "a\<twosuperior> = 0 \<longleftrightarrow> a = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   171
  by (force simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   172
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   173
lemma zero_le_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   174
  "0 \<le> a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   175
  by (simp add: power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   176
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   177
lemma zero_less_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   178
  "0 < a\<twosuperior> \<longleftrightarrow> a \<noteq> 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   179
  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
   180
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   181
lemma power2_less_0 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   182
  "\<not> a\<twosuperior> < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   183
  by (force simp add: power2_eq_square mult_less_0_iff) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   184
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   185
lemma abs_power2 [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   186
  "abs (a\<twosuperior>) = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   187
  by (simp add: power2_eq_square abs_mult abs_mult_self)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   188
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   189
lemma power2_abs [simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   190
  "(abs a)\<twosuperior> = a\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   191
  by (simp add: power2_eq_square abs_mult_self)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   192
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   193
lemma odd_power_less_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   194
  "a < 0 \<Longrightarrow> a ^ Suc (2*n) < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   195
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   196
  case 0
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   197
  then show ?case by simp
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   198
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   199
  case (Suc n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   200
  have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   201
    by (simp add: mult_ac power_add power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   202
  thus ?case
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   203
    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
   204
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   205
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   206
lemma odd_0_le_power_imp_0_le:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   207
  "0 \<le> a ^ Suc (2*n) \<Longrightarrow> 0 \<le> a"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   208
  using odd_power_less_zero [of a n]
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   209
    by (force simp add: linorder_not_less [symmetric]) 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   210
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   211
lemma zero_le_even_power'[simp]:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   212
  "0 \<le> a ^ (2*n)"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   213
proof (induct n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   214
  case 0
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   215
    show ?case by (simp add: zero_le_one)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   216
next
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   217
  case (Suc n)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   218
    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   219
      by (simp add: mult_ac power_add power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   220
    thus ?case
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   221
      by (simp add: Suc zero_le_mult_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   222
qed
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   223
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   224
lemma sum_power2_ge_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   225
  "0 \<le> x\<twosuperior> + y\<twosuperior>"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   226
  unfolding power2_eq_square by (rule sum_squares_ge_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   227
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   228
lemma not_sum_power2_lt_zero:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   229
  "\<not> x\<twosuperior> + y\<twosuperior> < 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   230
  unfolding power2_eq_square by (rule not_sum_squares_lt_zero)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   231
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   232
lemma sum_power2_eq_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   233
  "x\<twosuperior> + y\<twosuperior> = 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   234
  unfolding power2_eq_square by (rule sum_squares_eq_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   235
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   236
lemma sum_power2_le_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   237
  "x\<twosuperior> + y\<twosuperior> \<le> 0 \<longleftrightarrow> x = 0 \<and> y = 0"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   238
  unfolding power2_eq_square by (rule sum_squares_le_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   239
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   240
lemma sum_power2_gt_zero_iff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   241
  "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
   242
  unfolding power2_eq_square by (rule sum_squares_gt_zero_iff)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   243
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   244
end
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   245
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   246
lemma power2_sum:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   247
  fixes x y :: "'a::number_ring"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   248
  shows "(x + y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> + 2 * x * y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   249
  by (simp add: ring_distribs power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   250
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   251
lemma power2_diff:
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   252
  fixes x y :: "'a::number_ring"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   253
  shows "(x - y)\<twosuperior> = x\<twosuperior> + y\<twosuperior> - 2 * x * y"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   254
  by (simp add: ring_distribs power2_eq_square)
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   255
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   256
29040
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   257
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
   258
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   259
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
   260
  "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
   261
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   262
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
   263
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
   264
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   265
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
   266
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
   267
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   268
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
   269
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   270
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
   271
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
   272
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   273
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
   274
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   275
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
   276
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
   277
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   278
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
   279
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
   280
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   281
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
   282
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
   283
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   284
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
   285
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
   286
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   287
text {*
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   288
  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
   289
  @{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
   290
*}
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   291
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   292
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
   293
  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
   294
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   295
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
   296
  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
   297
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   298
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
   299
  "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
   300
  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
   301
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   302
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
   303
  "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
   304
  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
   305
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   306
lemmas neg_simps [simp] =
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   307
  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
   308
  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
   309
  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
   310
286c669d3a7a move all neg-related lemmas to NatBin; make type of neg specific to int
huffman
parents: 29039
diff changeset
   311
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   312
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   313
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   314
declare nat_0 [simp] nat_1 [simp]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   315
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   316
lemma nat_number_of [simp]: "nat (number_of w) = number_of w"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   317
by (simp add: nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   318
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31790
diff changeset
   319
lemma nat_numeral_0_eq_0 [simp, code_post]: "Numeral0 = (0::nat)"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   320
by (simp add: nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   321
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   322
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   323
by (simp add: nat_1 nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   324
31998
2c7a24f74db9 code attributes use common underscore convention
haftmann
parents: 31790
diff changeset
   325
lemma numeral_1_eq_Suc_0 [code_post]: "Numeral1 = Suc 0"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   326
by (simp add: nat_numeral_1_eq_1)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   327
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   328
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   329
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   330
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   331
lemma int_nat_number_of [simp]:
23365
f31794033ae1 removed constant int :: nat => int;
huffman
parents: 23307
diff changeset
   332
     "int (number_of v) =  
23307
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   333
         (if neg (number_of v :: int) then 0  
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   334
          else (number_of v :: int))"
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   335
  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
   336
  by simp
23307
2fe3345035c7 modify proofs to avoid referring to int::nat=>int
huffman
parents: 23294
diff changeset
   337
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   338
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   339
subsubsection{*Successor *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   340
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   341
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
   342
apply (rule sym)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   343
apply (simp add: nat_eq_iff int_Suc)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   344
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   345
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   346
lemma Suc_nat_number_of_add:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   347
     "Suc (number_of v + n) =  
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   348
        (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
   349
  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
   350
  by (simp add: Suc_nat_eq_nat_zadd1 add_ac)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   351
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   352
lemma Suc_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   353
     "Suc (number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   354
        (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
   355
apply (cut_tac n = 0 in Suc_nat_number_of_add)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   356
apply (simp cong del: if_weak_cong)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   357
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   358
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   359
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   360
subsubsection{*Addition *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   361
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   362
lemma add_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   363
     "(number_of v :: nat) + number_of v' =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   364
         (if v < Int.Pls then number_of v'  
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   365
          else if v' < Int.Pls then number_of v  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   366
          else number_of (v + v'))"
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   367
  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
   368
  by (simp add: nat_add_distrib)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   369
30081
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   370
lemma nat_number_of_add_1 [simp]:
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   371
  "number_of v + (1::nat) =
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   372
    (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
   373
  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
   374
  by (simp add: nat_add_distrib)
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   375
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   376
lemma nat_1_add_number_of [simp]:
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   377
  "(1::nat) + number_of v =
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   378
    (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
   379
  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
   380
  by (simp add: nat_add_distrib)
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   381
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   382
lemma nat_1_add_1 [simp]: "1 + 1 = (2::nat)"
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   383
  by (rule int_int_eq [THEN iffD1]) simp
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   384
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   385
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   386
subsubsection{*Subtraction *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   387
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   388
lemma diff_nat_eq_if:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   389
     "nat z - nat z' =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   390
        (if neg z' then nat z   
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   391
         else let d = z-z' in     
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   392
              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
   393
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
   394
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   395
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   396
lemma diff_nat_number_of [simp]: 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   397
     "(number_of v :: nat) - number_of v' =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   398
        (if v' < Int.Pls then number_of v  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   399
         else let d = number_of (v + uminus v') in     
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   400
              if neg d then 0 else nat d)"
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   401
  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
   402
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   403
30081
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   404
lemma nat_number_of_diff_1 [simp]:
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   405
  "number_of v - (1::nat) =
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   406
    (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
   407
  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
   408
  by auto
46b9c8ae3897 add simp rules for numerals with 1::nat
huffman
parents: 30079
diff changeset
   409
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   410
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   411
subsubsection{*Multiplication *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   412
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   413
lemma mult_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   414
     "(number_of v :: nat) * number_of v' =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   415
       (if v < Int.Pls then 0 else number_of (v * v'))"
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   416
  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
   417
  by (simp add: nat_mult_distrib)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   418
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   419
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   420
subsubsection{*Quotient *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   421
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   422
lemma div_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   423
     "(number_of v :: nat)  div  number_of v' =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   424
          (if neg (number_of v :: int) then 0  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   425
           else nat (number_of v div number_of v'))"
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   426
  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
   427
  by (simp add: nat_div_distrib)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   428
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   429
lemma one_div_nat_number_of [simp]:
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 26342
diff changeset
   430
     "Suc 0 div number_of v' = nat (1 div number_of v')" 
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   431
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   432
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   433
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   434
subsubsection{*Remainder *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   435
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   436
lemma mod_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   437
     "(number_of v :: nat)  mod  number_of v' =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   438
        (if neg (number_of v :: int) then 0  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   439
         else if neg (number_of v' :: int) then number_of v  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   440
         else nat (number_of v mod number_of v'))"
28984
060832a1f087 change arith_special simps to avoid using neg
huffman
parents: 28969
diff changeset
   441
  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
   442
  by (simp add: nat_mod_distrib)
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
lemma one_mod_nat_number_of [simp]:
27651
16a26996c30e moved op dvd to theory Ring_and_Field; generalized a couple of lemmas
haftmann
parents: 26342
diff changeset
   445
     "Suc 0 mod number_of v' =  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   446
        (if neg (number_of v' :: int) then Suc 0
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   447
         else nat (1 mod number_of v'))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   448
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   449
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   450
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   451
subsubsection{* Divisibility *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   452
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   453
lemmas dvd_eq_mod_eq_0_number_of =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   454
  dvd_eq_mod_eq_0 [of "number_of x" "number_of y", standard]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   455
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   456
declare dvd_eq_mod_eq_0_number_of [simp]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   457
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   458
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   459
subsection{*Comparisons*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   460
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   461
subsubsection{*Equals (=) *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   462
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   463
lemma eq_nat_nat_iff:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   464
     "[| (0::int) <= z;  0 <= z' |] ==> (nat z = nat z') = (z=z')"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   465
by (auto elim!: nonneg_eq_int)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   466
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   467
lemma eq_nat_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   468
     "((number_of v :: nat) = number_of v') =  
28969
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   469
      (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
   470
       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
   471
       else v = v')"
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   472
  unfolding nat_number_of_def number_of_is_id neg_def
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   473
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   474
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   475
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   476
subsubsection{*Less-than (<) *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   477
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   478
lemma less_nat_number_of [simp]:
29011
a47003001699 simplify less_nat_number_of
huffman
parents: 29010
diff changeset
   479
  "(number_of v :: nat) < number_of v' \<longleftrightarrow>
a47003001699 simplify less_nat_number_of
huffman
parents: 29010
diff changeset
   480
    (if v < v' then Int.Pls < v' else False)"
a47003001699 simplify less_nat_number_of
huffman
parents: 29010
diff changeset
   481
  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
   482
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   483
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   484
29010
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   485
subsubsection{*Less-than-or-equal *}
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   486
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   487
lemma le_nat_number_of [simp]:
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   488
  "(number_of v :: nat) \<le> number_of v' \<longleftrightarrow>
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   489
    (if v \<le> v' then True else v \<le> Int.Pls)"
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   490
  unfolding nat_number_of_def number_of_is_id numeral_simps
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   491
  by auto
5cd646abf6bc add lemma le_nat_number_of
huffman
parents: 28984
diff changeset
   492
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   493
(*Maps #n to n for n = 0, 1, 2*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   494
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
   495
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   496
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   497
subsection{*Powers with Numeric Exponents*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   498
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   499
text{*Squares of literal numerals will be evaluated.*}
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   500
lemmas power2_eq_square_number_of [simp] =
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   501
    power2_eq_square [of "number_of w", standard]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   502
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{*Simprules for comparisons where common factors can be cancelled.*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   505
lemmas zero_compare_simps =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   506
    add_strict_increasing add_strict_increasing2 add_increasing
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   507
    zero_le_mult_iff zero_le_divide_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   508
    zero_less_mult_iff zero_less_divide_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   509
    mult_le_0_iff divide_le_0_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   510
    mult_less_0_iff divide_less_0_iff 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   511
    zero_le_power2 power2_less_0
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   512
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   513
subsubsection{*Nat *}
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 Suc_pred': "0 < n ==> n = Suc(n - 1)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   516
by (simp add: numerals)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   517
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   518
(*Expresses a natural number constant as the Suc of another one.
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   519
  NOT suitable for rewriting because n recurs in the condition.*)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   520
lemmas expand_Suc = Suc_pred' [of "number_of v", standard]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   521
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   522
subsubsection{*Arith *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   523
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31182
diff changeset
   524
lemma Suc_eq_plus1: "Suc n = n + 1"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   525
by (simp add: numerals)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   526
31790
05c92381363c corrected and unified thm names
nipkow
parents: 31182
diff changeset
   527
lemma Suc_eq_plus1_left: "Suc n = 1 + n"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   528
by (simp add: numerals)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   529
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   530
(* These two can be useful when m = number_of... *)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   531
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   532
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
   533
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   534
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   535
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
   536
  unfolding One_nat_def by (cases m) simp_all
23164
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 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
   539
  unfolding One_nat_def by (cases m) simp_all
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   540
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   541
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   542
subsection{*Comparisons involving (0::nat) *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   543
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   544
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
   545
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   546
lemma eq_number_of_0 [simp]:
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   547
  "number_of v = (0::nat) \<longleftrightarrow> v \<le> Int.Pls"
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   548
  unfolding nat_number_of_def number_of_is_id numeral_simps
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   549
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   550
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   551
lemma eq_0_number_of [simp]:
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   552
  "(0::nat) = number_of v \<longleftrightarrow> v \<le> Int.Pls"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   553
by (rule trans [OF eq_sym_conv eq_number_of_0])
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_0_number_of [simp]:
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   556
   "(0::nat) < number_of v \<longleftrightarrow> Int.Pls < v"
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   557
  unfolding nat_number_of_def number_of_is_id numeral_simps
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   558
  by simp
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   559
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   560
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
   561
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
   562
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   563
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   564
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   565
subsection{*Comparisons involving  @{term Suc} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   566
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   567
lemma eq_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   568
     "(number_of v = Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   569
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   570
         if neg pv then False else nat pv = n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   571
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
   572
                  number_of_pred nat_number_of_def 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   573
            split add: split_if)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   574
apply (rule_tac x = "number_of v" in spec)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   575
apply (auto simp add: nat_eq_iff)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   576
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   577
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   578
lemma Suc_eq_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   579
     "(Suc n = number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   580
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   581
         if neg pv then False else nat pv = n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   582
by (rule trans [OF eq_sym_conv eq_number_of_Suc])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   583
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   584
lemma less_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   585
     "(number_of v < Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   586
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   587
         if neg pv then True else nat pv < n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   588
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
   589
                  number_of_pred nat_number_of_def  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   590
            split add: split_if)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   591
apply (rule_tac x = "number_of v" in spec)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   592
apply (auto simp add: nat_less_iff)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   593
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   594
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   595
lemma less_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   596
     "(Suc n < number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   597
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   598
         if neg pv then False else n < nat pv)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   599
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
   600
                  number_of_pred nat_number_of_def
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   601
            split add: split_if)
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 simp add: zless_nat_eq_int_zless)
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 le_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   607
     "(number_of v <= Suc n) =  
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 True else nat pv <= n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   610
by (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   611
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   612
lemma le_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   613
     "(Suc n <= number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   614
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   615
         if neg pv then False else n <= nat pv)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   616
by (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric])
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   617
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   618
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   619
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Int.Min"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   620
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   621
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   622
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   623
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   624
subsection{*Max and Min Combined with @{term Suc} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   625
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   626
lemma max_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   627
     "max (Suc n) (number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   628
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   629
         if neg pv then Suc n else Suc(max n (nat pv)))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   630
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
   631
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   632
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   633
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   634
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   635
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   636
lemma max_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   637
     "max (number_of v) (Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   638
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   639
         if neg pv then Suc n else Suc(max (nat pv) n))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   640
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
   641
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   642
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   643
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   644
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   645
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   646
lemma min_number_of_Suc [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   647
     "min (Suc n) (number_of v) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   648
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   649
         if neg pv then 0 else Suc(min n (nat pv)))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   650
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
   651
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   652
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   653
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   654
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   655
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   656
lemma min_Suc_number_of [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   657
     "min (number_of v) (Suc n) =  
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   658
        (let pv = number_of (Int.pred v) in  
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   659
         if neg pv then 0 else Suc(min (nat pv) n))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   660
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
   661
            split add: split_if nat.split)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   662
apply (rule_tac x = "number_of v" in spec) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   663
apply auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   664
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   665
 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   666
subsection{*Literal arithmetic involving powers*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   667
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   668
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   669
apply (induct "n")
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   670
apply (simp_all (no_asm_simp) add: nat_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   671
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   672
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   673
lemma power_nat_number_of:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   674
     "(number_of v :: nat) ^ n =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   675
       (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
   676
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
   677
         split add: split_if cong: imp_cong)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   678
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   679
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   680
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
   681
declare power_nat_number_of_number_of [simp]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   682
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   683
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   684
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   685
text{*For arbitrary rings*}
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   686
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   687
lemma power_number_of_even:
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   688
  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
   689
  shows "z ^ number_of (Int.Bit0 w) = (let w = z ^ (number_of w) in w * w)"
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   690
unfolding Let_def nat_number_of_def number_of_Bit0
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   691
apply (rule_tac x = "number_of w" in spec, clarify)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   692
apply (case_tac " (0::int) <= x")
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   693
apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   694
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   695
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   696
lemma power_number_of_odd:
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   697
  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
   698
  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
   699
     then (let w = z ^ (number_of w) in z * w * w) else 1)"
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   700
unfolding Let_def nat_number_of_def number_of_Bit1
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   701
apply (rule_tac x = "number_of w" in spec, auto)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   702
apply (simp only: nat_add_distrib nat_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   703
apply simp
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   704
apply (auto simp add: nat_add_distrib nat_mult_distrib power_even_eq power2_eq_square neg_nat power_Suc)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   705
done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   706
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   707
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
   708
lemmas zpower_number_of_odd = power_number_of_odd [where 'a=int]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   709
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   710
lemmas power_number_of_even_number_of [simp] =
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   711
    power_number_of_even [of "number_of v", standard]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   712
23294
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   713
lemmas power_number_of_odd_number_of [simp] =
9302a50a5bc9 generalize zpower_number_of_{even,odd} lemmas
huffman
parents: 23277
diff changeset
   714
    power_number_of_odd [of "number_of v", standard]
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   715
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   716
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   717
(* Enable arith to deal with div/mod k where k is a numeral: *)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   718
declare split_div[of _ _ "number_of k", standard, arith_split]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   719
declare split_mod[of _ _ "number_of k", standard, arith_split]
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   720
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   721
lemma nat_number_of_Pls: "Numeral0 = (0::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   722
  by (simp add: number_of_Pls nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   723
25919
8b1c0d434824 joined theories IntDef, Numeral, IntArith to theory Int
haftmann
parents: 25571
diff changeset
   724
lemma nat_number_of_Min: "number_of Int.Min = (0::nat)"
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   725
  apply (simp only: number_of_Min nat_number_of_def nat_zminus_int)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   726
  done
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   727
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   728
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
   729
    "number_of (Int.Bit0 w) = (let n::nat = number_of w in n + n)"
28969
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   730
  unfolding nat_number_of_def number_of_is_id numeral_simps Let_def
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   731
  by auto
26086
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   732
3c243098b64a New simpler representation of numerals, using Bit0 and Bit1 instead of BIT, B0, and B1
huffman
parents: 25965
diff changeset
   733
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
   734
  "number_of (Int.Bit1 w) =
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   735
    (if neg (number_of w :: int) then 0
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   736
     else let n = number_of w in Suc (n + n))"
28969
4ed63cdda799 change more lemmas to avoid using iszero
huffman
parents: 28968
diff changeset
   737
  unfolding nat_number_of_def number_of_is_id numeral_simps neg_def Let_def
28968
a4f3db5d1393 change some lemmas to avoid using iszero
huffman
parents: 28961
diff changeset
   738
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   739
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   740
lemmas nat_number =
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   741
  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
   742
  nat_number_of_Bit0 nat_number_of_Bit1
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   743
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   744
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   745
  by (simp add: Let_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   746
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   747
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring})"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   748
  by (simp only: number_of_Min power_minus1_even)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   749
31014
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   750
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring})"
79f0858d9d49 collected square lemmas in Nat_Numeral
haftmann
parents: 31002
diff changeset
   751
  by (simp only: number_of_Min power_minus1_odd)
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   752
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   753
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   754
subsection{*Literal arithmetic and @{term of_nat}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   755
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   756
lemma of_nat_double:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   757
     "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
   758
by (simp only: mult_2 nat_add_distrib of_nat_add) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   759
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   760
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   761
by (simp only: nat_number_of_def)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   762
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   763
lemma of_nat_number_of_lemma:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   764
     "of_nat (number_of v :: nat) =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   765
         (if 0 \<le> (number_of v :: int) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   766
          then (number_of v :: 'a :: number_ring)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   767
          else 0)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   768
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat);
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   769
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   770
lemma of_nat_number_of_eq [simp]:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   771
     "of_nat (number_of v :: nat) =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   772
         (if neg (number_of v :: int) then 0  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   773
          else (number_of v :: 'a :: number_ring))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   774
by (simp only: of_nat_number_of_lemma neg_def, simp) 
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   775
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   776
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   777
subsection {*Lemmas for the Combination and Cancellation Simprocs*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   778
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   779
lemma nat_number_of_add_left:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   780
     "number_of v + (number_of v' + (k::nat)) =  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   781
         (if neg (number_of v :: int) then number_of v' + k  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   782
          else if neg (number_of v' :: int) then number_of v + k  
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   783
          else number_of (v + v') + k)"
28968
a4f3db5d1393 change some lemmas to avoid using iszero
huffman
parents: 28961
diff changeset
   784
  unfolding nat_number_of_def number_of_is_id neg_def
a4f3db5d1393 change some lemmas to avoid using iszero
huffman
parents: 28961
diff changeset
   785
  by auto
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   786
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   787
lemma nat_number_of_mult_left:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   788
     "number_of v * (number_of v' * (k::nat)) =  
29012
9140227dc8c5 change lemmas to avoid using neg
huffman
parents: 29011
diff changeset
   789
         (if v < Int.Pls then 0
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   790
          else number_of (v * v') * k)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   791
by simp
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   792
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   793
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   794
subsubsection{*For @{text combine_numerals}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   795
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   796
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   797
by (simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   798
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   799
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   800
subsubsection{*For @{text cancel_numerals}*}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   801
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   802
lemma nat_diff_add_eq1:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   803
     "j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   804
by (simp split add: nat_diff_split add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   805
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   806
lemma nat_diff_add_eq2:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   807
     "i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   808
by (simp split add: nat_diff_split add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   809
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   810
lemma nat_eq_add_iff1:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   811
     "j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   812
by (auto split add: nat_diff_split simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   813
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   814
lemma nat_eq_add_iff2:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   815
     "i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   816
by (auto split add: nat_diff_split simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   817
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   818
lemma nat_less_add_iff1:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   819
     "j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   820
by (auto split add: nat_diff_split simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   821
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   822
lemma nat_less_add_iff2:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   823
     "i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   824
by (auto split add: nat_diff_split simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   825
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   826
lemma nat_le_add_iff1:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   827
     "j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   828
by (auto split add: nat_diff_split simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   829
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   830
lemma nat_le_add_iff2:
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   831
     "i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   832
by (auto split add: nat_diff_split simp add: add_mult_distrib)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   833
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   834
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   835
subsubsection{*For @{text cancel_numeral_factors} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   836
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   837
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   838
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   839
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   840
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   841
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   842
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   843
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   844
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   845
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   846
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   847
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   848
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   849
lemma nat_mult_dvd_cancel_disj[simp]:
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   850
  "(k*m) dvd (k*n) = (k=0 | m dvd (n::nat))"
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   851
by(auto simp: dvd_eq_mod_eq_0 mod_mult_distrib2[symmetric])
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   852
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   853
lemma nat_mult_dvd_cancel1: "0 < k \<Longrightarrow> (k*m) dvd (k*n::nat) = (m dvd n)"
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   854
by(auto)
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   855
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   856
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   857
subsubsection{*For @{text cancel_factor} *}
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   858
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   859
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   860
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   861
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   862
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   863
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   864
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   865
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   866
by auto
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   867
23969
ef782bbf2d09 Added cancel simprocs for dvd on nat and int
nipkow
parents: 23389
diff changeset
   868
lemma nat_mult_div_cancel_disj[simp]:
23164
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   869
     "(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)"
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   870
by (simp add: nat_mult_div_cancel1)
69e55066dbca moved Integ files to canonical place;
wenzelm
parents:
diff changeset
   871
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   872
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   873
subsection {* Simprocs for the Naturals *}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   874
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31034
diff changeset
   875
use "Tools/nat_numeral_simprocs.ML"
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31034
diff changeset
   876
31100
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   877
declaration {* 
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   878
  K (Lin_Arith.add_simps (@{thms neg_simps} @ [@{thm Suc_nat_number_of}, @{thm int_nat_number_of}])
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   879
  #> Lin_Arith.add_simps (@{thms ring_distribs} @ [@{thm Let_number_of}, @{thm Let_0}, @{thm Let_1},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   880
     @{thm nat_0}, @{thm nat_1},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   881
     @{thm add_nat_number_of}, @{thm diff_nat_number_of}, @{thm mult_nat_number_of},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   882
     @{thm eq_nat_number_of}, @{thm less_nat_number_of}, @{thm le_number_of_eq_not_less},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   883
     @{thm le_Suc_number_of}, @{thm le_number_of_Suc},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   884
     @{thm less_Suc_number_of}, @{thm less_number_of_Suc},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   885
     @{thm Suc_eq_number_of}, @{thm eq_number_of_Suc},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   886
     @{thm mult_Suc}, @{thm mult_Suc_right},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   887
     @{thm add_Suc}, @{thm add_Suc_right},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   888
     @{thm eq_number_of_0}, @{thm eq_0_number_of}, @{thm less_0_number_of},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   889
     @{thm of_int_number_of_eq}, @{thm of_nat_number_of_eq}, @{thm nat_number_of},
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   890
     @{thm if_True}, @{thm if_False}])
6a2e67fe4488 tuned interface of Lin_Arith
haftmann
parents: 31080
diff changeset
   891
  #> Lin_Arith.add_simprocs (Nat_Numeral_Simprocs.combine_numerals :: Nat_Numeral_Simprocs.cancel_numerals))
31068
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31034
diff changeset
   892
*}
f591144b0f17 modules numeral_simprocs, nat_numeral_simprocs; proper structures for numeral simprocs
haftmann
parents: 31034
diff changeset
   893
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   894
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   895
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
   896
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   897
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
   898
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   899
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
   900
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
   901
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   902
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
   903
  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
   904
  tests.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   905
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
   906
  "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
   907
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
   908
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
   909
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
   910
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   911
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   912
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
   913
   simproc*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   914
lemma Suc_diff_number_of:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   915
     "Int.Pls < v ==>
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   916
      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
   917
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
   918
apply simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   919
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
   920
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
   921
                        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
   922
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   923
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   924
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
   925
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
   926
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   927
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   928
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
   929
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   930
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
   931
     "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
   932
        (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
   933
         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
   934
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
   935
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   936
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
   937
     "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
   938
       (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
   939
         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
   940
apply (subst add_eq_if)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   941
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
   942
            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
   943
            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
   944
                 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
   945
                 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
   946
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   947
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   948
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
   949
     "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
   950
        (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
   951
         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
   952
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
   953
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
   954
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
   955
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   956
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   957
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
   958
     "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
   959
        (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
   960
         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
   961
                   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
   962
apply (subst add_eq_if)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   963
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
   964
            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
   965
            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
   966
                 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
   967
                 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
   968
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   969
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   970
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   971
subsubsection{*Various Other Lemmas*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   972
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   973
lemma card_UNIV_bool[simp]: "card (UNIV :: bool set) = 2"
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   974
by(simp add: UNIV_bool)
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 31068
diff changeset
   975
30652
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   976
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
   977
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   978
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
   979
lemma nat_mult_2: "2 * z = (z+z::nat)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   980
proof -
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   981
  have "2*z = (1 + 1)*z" by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   982
  also have "... = z+z" by (simp add: left_distrib)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   983
  finally show ?thesis .
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   984
qed
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   985
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   986
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
   987
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
   988
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   989
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
   990
lemma less_2_cases: "(n::nat) < 2 ==> n = 0 | n = Suc 0"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   991
by arith
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   992
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   993
lemma div2_Suc_Suc [simp]: "Suc(Suc m) div 2 = Suc (m div 2)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   994
by arith
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   995
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   996
lemma add_self_div_2 [simp]: "(m + m) div 2 = (m::nat)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   997
by (simp add: nat_mult_2 [symmetric])
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   998
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
   999
lemma mod2_Suc_Suc [simp]: "Suc(Suc(m)) mod 2 = m mod 2"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1000
apply (subgoal_tac "m mod 2 < 2")
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1001
apply (erule less_2_cases [THEN disjE])
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1002
apply (simp_all (no_asm_simp) add: Let_def mod_Suc nat_1)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1003
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1004
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1005
lemma mod2_gr_0 [simp]: "!!m::nat. (0 < m mod 2) = (m mod 2 = 1)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1006
apply (subgoal_tac "m mod 2 < 2")
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1007
apply (force simp del: mod_less_divisor, simp)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1008
done
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1009
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1010
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
  1011
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1012
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
  1013
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1014
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1015
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
  1016
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1017
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1018
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
  1019
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
  1020
by simp
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1021
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1022
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1023
text{*These lemmas collapse some needless occurrences of Suc:
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1024
    at least three Sucs, since two and fewer are rewritten back to Suc again!
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1025
    We already have some rules to simplify operands smaller than 3.*}
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1026
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1027
lemma div_Suc_eq_div_add3 [simp]: "m div (Suc (Suc (Suc n))) = m div (3+n)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1028
by (simp add: Suc3_eq_add_3)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1029
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1030
lemma mod_Suc_eq_mod_add3 [simp]: "m mod (Suc (Suc (Suc n))) = m mod (3+n)"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1031
by (simp add: Suc3_eq_add_3)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1032
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1033
lemma Suc_div_eq_add3_div: "(Suc (Suc (Suc m))) div n = (3+m) div n"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1034
by (simp add: Suc3_eq_add_3)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1035
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1036
lemma Suc_mod_eq_add3_mod: "(Suc (Suc (Suc m))) mod n = (3+m) mod n"
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1037
by (simp add: Suc3_eq_add_3)
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1038
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1039
lemmas Suc_div_eq_add3_div_number_of =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1040
    Suc_div_eq_add3_div [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1041
declare Suc_div_eq_add3_div_number_of [simp]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1042
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1043
lemmas Suc_mod_eq_add3_mod_number_of =
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1044
    Suc_mod_eq_add3_mod [of _ "number_of v", standard]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1045
declare Suc_mod_eq_add3_mod_number_of [simp]
752329615264 distributed contents of theory Arith_Tools to theories Int, IntDiv and NatBin accordingly
haftmann
parents: 30497
diff changeset
  1046
31096
e546e15089ef newline at end of file
huffman
parents: 31080
diff changeset
  1047
end