src/HOL/Integ/NatBin.thy
author haftmann
Mon Jan 30 08:20:56 2006 +0100 (2006-01-30)
changeset 18851 9502ce541f01
parent 18708 4b3dadb4fe33
child 18978 8971c306b94f
permissions -rw-r--r--
adaptions to codegen_package
paulson@7032
     1
(*  Title:      HOL/NatBin.thy
paulson@7032
     2
    ID:         $Id$
paulson@7032
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
paulson@7032
     4
    Copyright   1999  University of Cambridge
wenzelm@12838
     5
*)
paulson@7032
     6
wenzelm@12838
     7
header {* Binary arithmetic for the natural numbers *}
paulson@7032
     8
nipkow@15131
     9
theory NatBin
nipkow@15140
    10
imports IntDiv
nipkow@15131
    11
begin
paulson@7032
    12
wenzelm@12838
    13
text {*
paulson@14273
    14
  Arithmetic for naturals is reduced to that for the non-negative integers.
wenzelm@12838
    15
*}
wenzelm@12838
    16
wenzelm@12838
    17
instance nat :: number ..
wenzelm@12838
    18
wenzelm@12838
    19
defs (overloaded)
paulson@14273
    20
  nat_number_of_def:
paulson@14273
    21
     "(number_of::bin => nat) v == nat ((number_of :: bin => int) v)"
wenzelm@12838
    22
paulson@14272
    23
paulson@14353
    24
subsection{*Function @{term nat}: Coercion from Type @{typ int} to @{typ nat}*}
paulson@14272
    25
paulson@14273
    26
declare nat_0 [simp] nat_1 [simp]
paulson@14273
    27
paulson@14273
    28
lemma nat_number_of [simp]: "nat (number_of w) = number_of w"
paulson@14273
    29
by (simp add: nat_number_of_def)
paulson@14272
    30
paulson@14387
    31
lemma nat_numeral_0_eq_0 [simp]: "Numeral0 = (0::nat)"
paulson@14273
    32
by (simp add: nat_number_of_def)
paulson@14272
    33
paulson@14387
    34
lemma nat_numeral_1_eq_1 [simp]: "Numeral1 = (1::nat)"
paulson@14273
    35
by (simp add: nat_1 nat_number_of_def)
paulson@14272
    36
paulson@14272
    37
lemma numeral_1_eq_Suc_0: "Numeral1 = Suc 0"
paulson@14387
    38
by (simp add: nat_numeral_1_eq_1)
paulson@14272
    39
paulson@14272
    40
lemma numeral_2_eq_2: "2 = Suc (Suc 0)"
paulson@14272
    41
apply (unfold nat_number_of_def)
paulson@14272
    42
apply (rule nat_2)
paulson@14272
    43
done
paulson@14272
    44
paulson@14272
    45
paulson@14273
    46
text{*Distributive laws for type @{text nat}.  The others are in theory
paulson@14273
    47
   @{text IntArith}, but these require div and mod to be defined for type
paulson@14273
    48
   "int".  They also need some of the lemmas proved above.*}
paulson@14272
    49
paulson@14272
    50
lemma nat_div_distrib: "(0::int) <= z ==> nat (z div z') = nat z div nat z'"
paulson@14272
    51
apply (case_tac "0 <= z'")
paulson@14272
    52
apply (auto simp add: div_nonneg_neg_le0 DIVISION_BY_ZERO_DIV)
paulson@14273
    53
apply (case_tac "z' = 0", simp add: DIVISION_BY_ZERO)
paulson@14272
    54
apply (auto elim!: nonneg_eq_int)
paulson@14272
    55
apply (rename_tac m m')
paulson@14272
    56
apply (subgoal_tac "0 <= int m div int m'")
paulson@14387
    57
 prefer 2 apply (simp add: nat_numeral_0_eq_0 pos_imp_zdiv_nonneg_iff) 
paulson@14273
    58
apply (rule inj_int [THEN injD], simp)
paulson@14272
    59
apply (rule_tac r = "int (m mod m') " in quorem_div)
paulson@14273
    60
 prefer 2 apply force
paulson@14387
    61
apply (simp add: nat_less_iff [symmetric] quorem_def nat_numeral_0_eq_0 zadd_int 
paulson@14273
    62
                 zmult_int)
paulson@14272
    63
done
paulson@14272
    64
paulson@14272
    65
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*)
paulson@14273
    66
lemma nat_mod_distrib:
paulson@14273
    67
     "[| (0::int) <= z;  0 <= z' |] ==> nat (z mod z') = nat z mod nat z'"
paulson@14273
    68
apply (case_tac "z' = 0", simp add: DIVISION_BY_ZERO)
paulson@14272
    69
apply (auto elim!: nonneg_eq_int)
paulson@14272
    70
apply (rename_tac m m')
paulson@14272
    71
apply (subgoal_tac "0 <= int m mod int m'")
paulson@14387
    72
 prefer 2 apply (simp add: nat_less_iff nat_numeral_0_eq_0 pos_mod_sign) 
paulson@14273
    73
apply (rule inj_int [THEN injD], simp)
paulson@14272
    74
apply (rule_tac q = "int (m div m') " in quorem_mod)
paulson@14273
    75
 prefer 2 apply force
paulson@14387
    76
apply (simp add: nat_less_iff [symmetric] quorem_def nat_numeral_0_eq_0 zadd_int zmult_int)
paulson@14272
    77
done
paulson@14272
    78
paulson@16413
    79
text{*Suggested by Matthias Daum*}
paulson@16413
    80
lemma int_div_less_self: "\<lbrakk>0 < x; 1 < k\<rbrakk> \<Longrightarrow> x div k < (x::int)"
paulson@16413
    81
apply (subgoal_tac "nat x div nat k < nat x") 
paulson@16413
    82
 apply (simp add: nat_div_distrib [symmetric])
paulson@16413
    83
apply (rule Divides.div_less_dividend, simp_all) 
paulson@16413
    84
done
paulson@16413
    85
paulson@14272
    86
paulson@14353
    87
subsection{*Function @{term int}: Coercion from Type @{typ nat} to @{typ int}*}
paulson@14272
    88
paulson@14272
    89
(*"neg" is used in rewrite rules for binary comparisons*)
paulson@14387
    90
lemma int_nat_number_of [simp]:
paulson@14273
    91
     "int (number_of v :: nat) =  
paulson@14378
    92
         (if neg (number_of v :: int) then 0  
paulson@14272
    93
          else (number_of v :: int))"
paulson@14272
    94
by (simp del: nat_number_of
paulson@14272
    95
	 add: neg_nat nat_number_of_def not_neg_nat add_assoc)
paulson@14272
    96
paulson@14272
    97
paulson@14390
    98
subsubsection{*Successor *}
paulson@14272
    99
paulson@14272
   100
lemma Suc_nat_eq_nat_zadd1: "(0::int) <= z ==> Suc (nat z) = nat (1 + z)"
paulson@14272
   101
apply (rule sym)
paulson@14273
   102
apply (simp add: nat_eq_iff int_Suc)
paulson@14272
   103
done
paulson@14272
   104
paulson@14273
   105
lemma Suc_nat_number_of_add:
paulson@14273
   106
     "Suc (number_of v + n) =  
paulson@14378
   107
        (if neg (number_of v :: int) then 1+n else number_of (bin_succ v) + n)" 
paulson@14272
   108
by (simp del: nat_number_of 
paulson@14272
   109
         add: nat_number_of_def neg_nat
paulson@14272
   110
              Suc_nat_eq_nat_zadd1 number_of_succ) 
paulson@14272
   111
paulson@14387
   112
lemma Suc_nat_number_of [simp]:
paulson@14273
   113
     "Suc (number_of v) =  
paulson@14378
   114
        (if neg (number_of v :: int) then 1 else number_of (bin_succ v))"
paulson@14273
   115
apply (cut_tac n = 0 in Suc_nat_number_of_add)
paulson@14272
   116
apply (simp cong del: if_weak_cong)
paulson@14272
   117
done
paulson@14272
   118
paulson@14272
   119
paulson@14390
   120
subsubsection{*Addition *}
paulson@14272
   121
paulson@14272
   122
(*"neg" is used in rewrite rules for binary comparisons*)
paulson@14387
   123
lemma add_nat_number_of [simp]:
paulson@14273
   124
     "(number_of v :: nat) + number_of v' =  
paulson@14378
   125
         (if neg (number_of v :: int) then number_of v'  
paulson@14378
   126
          else if neg (number_of v' :: int) then number_of v  
paulson@14272
   127
          else number_of (bin_add v v'))"
paulson@14272
   128
by (force dest!: neg_nat
paulson@14272
   129
          simp del: nat_number_of
paulson@14272
   130
          simp add: nat_number_of_def nat_add_distrib [symmetric]) 
paulson@14272
   131
paulson@14272
   132
paulson@14390
   133
subsubsection{*Subtraction *}
paulson@14272
   134
paulson@14273
   135
lemma diff_nat_eq_if:
paulson@14273
   136
     "nat z - nat z' =  
paulson@14272
   137
        (if neg z' then nat z   
paulson@14272
   138
         else let d = z-z' in     
paulson@14272
   139
              if neg d then 0 else nat d)"
paulson@14273
   140
apply (simp add: Let_def nat_diff_distrib [symmetric] neg_eq_less_0 not_neg_eq_ge_0)
paulson@14273
   141
apply (simp add: diff_is_0_eq nat_le_eq_zle)
paulson@14272
   142
done
paulson@14272
   143
paulson@14387
   144
lemma diff_nat_number_of [simp]: 
paulson@14272
   145
     "(number_of v :: nat) - number_of v' =  
paulson@14378
   146
        (if neg (number_of v' :: int) then number_of v  
paulson@14272
   147
         else let d = number_of (bin_add v (bin_minus v')) in     
paulson@14272
   148
              if neg d then 0 else nat d)"
paulson@14272
   149
by (simp del: nat_number_of add: diff_nat_eq_if nat_number_of_def) 
paulson@14272
   150
paulson@14272
   151
paulson@14272
   152
paulson@14390
   153
subsubsection{*Multiplication *}
paulson@14272
   154
paulson@14387
   155
lemma mult_nat_number_of [simp]:
paulson@14273
   156
     "(number_of v :: nat) * number_of v' =  
paulson@14378
   157
       (if neg (number_of v :: int) then 0 else number_of (bin_mult v v'))"
paulson@14272
   158
by (force dest!: neg_nat
paulson@14272
   159
          simp del: nat_number_of
paulson@14272
   160
          simp add: nat_number_of_def nat_mult_distrib [symmetric]) 
paulson@14272
   161
paulson@14272
   162
paulson@14272
   163
paulson@14390
   164
subsubsection{*Quotient *}
paulson@14272
   165
paulson@14387
   166
lemma div_nat_number_of [simp]:
paulson@14273
   167
     "(number_of v :: nat)  div  number_of v' =  
paulson@14378
   168
          (if neg (number_of v :: int) then 0  
paulson@14272
   169
           else nat (number_of v div number_of v'))"
paulson@14272
   170
by (force dest!: neg_nat
paulson@14272
   171
          simp del: nat_number_of
paulson@14272
   172
          simp add: nat_number_of_def nat_div_distrib [symmetric]) 
paulson@14272
   173
paulson@14387
   174
lemma one_div_nat_number_of [simp]:
paulson@14387
   175
     "(Suc 0)  div  number_of v' = (nat (1 div number_of v'))" 
paulson@14387
   176
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) 
paulson@14272
   177
paulson@14272
   178
paulson@14390
   179
subsubsection{*Remainder *}
paulson@14272
   180
paulson@14387
   181
lemma mod_nat_number_of [simp]:
paulson@14273
   182
     "(number_of v :: nat)  mod  number_of v' =  
paulson@14378
   183
        (if neg (number_of v :: int) then 0  
paulson@14378
   184
         else if neg (number_of v' :: int) then number_of v  
paulson@14272
   185
         else nat (number_of v mod number_of v'))"
paulson@14272
   186
by (force dest!: neg_nat
paulson@14272
   187
          simp del: nat_number_of
paulson@14272
   188
          simp add: nat_number_of_def nat_mod_distrib [symmetric]) 
paulson@14272
   189
paulson@14387
   190
lemma one_mod_nat_number_of [simp]:
paulson@14387
   191
     "(Suc 0)  mod  number_of v' =  
paulson@14387
   192
        (if neg (number_of v' :: int) then Suc 0
paulson@14387
   193
         else nat (1 mod number_of v'))"
paulson@14387
   194
by (simp del: nat_numeral_1_eq_1 add: numeral_1_eq_Suc_0 [symmetric]) 
paulson@14387
   195
paulson@14387
   196
paulson@14272
   197
paulson@14272
   198
ML
paulson@14272
   199
{*
paulson@14272
   200
val nat_number_of_def = thm"nat_number_of_def";
paulson@14272
   201
paulson@14272
   202
val nat_number_of = thm"nat_number_of";
paulson@14387
   203
val nat_numeral_0_eq_0 = thm"nat_numeral_0_eq_0";
paulson@14387
   204
val nat_numeral_1_eq_1 = thm"nat_numeral_1_eq_1";
paulson@14272
   205
val numeral_1_eq_Suc_0 = thm"numeral_1_eq_Suc_0";
paulson@14272
   206
val numeral_2_eq_2 = thm"numeral_2_eq_2";
paulson@14272
   207
val nat_div_distrib = thm"nat_div_distrib";
paulson@14272
   208
val nat_mod_distrib = thm"nat_mod_distrib";
paulson@14272
   209
val int_nat_number_of = thm"int_nat_number_of";
paulson@14272
   210
val Suc_nat_eq_nat_zadd1 = thm"Suc_nat_eq_nat_zadd1";
paulson@14272
   211
val Suc_nat_number_of_add = thm"Suc_nat_number_of_add";
paulson@14272
   212
val Suc_nat_number_of = thm"Suc_nat_number_of";
paulson@14272
   213
val add_nat_number_of = thm"add_nat_number_of";
paulson@14272
   214
val diff_nat_eq_if = thm"diff_nat_eq_if";
paulson@14272
   215
val diff_nat_number_of = thm"diff_nat_number_of";
paulson@14272
   216
val mult_nat_number_of = thm"mult_nat_number_of";
paulson@14272
   217
val div_nat_number_of = thm"div_nat_number_of";
paulson@14272
   218
val mod_nat_number_of = thm"mod_nat_number_of";
paulson@14272
   219
*}
paulson@14272
   220
paulson@14272
   221
paulson@14390
   222
subsection{*Comparisons*}
paulson@14272
   223
paulson@14390
   224
subsubsection{*Equals (=) *}
paulson@14272
   225
paulson@14273
   226
lemma eq_nat_nat_iff:
paulson@14273
   227
     "[| (0::int) <= z;  0 <= z' |] ==> (nat z = nat z') = (z=z')"
paulson@14273
   228
by (auto elim!: nonneg_eq_int)
paulson@14272
   229
paulson@14272
   230
(*"neg" is used in rewrite rules for binary comparisons*)
paulson@14390
   231
lemma eq_nat_number_of [simp]:
paulson@14273
   232
     "((number_of v :: nat) = number_of v') =  
paulson@14378
   233
      (if neg (number_of v :: int) then (iszero (number_of v' :: int) | neg (number_of v' :: int))  
paulson@14378
   234
       else if neg (number_of v' :: int) then iszero (number_of v :: int)  
paulson@14378
   235
       else iszero (number_of (bin_add v (bin_minus v')) :: int))"
paulson@14272
   236
apply (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def
paulson@14272
   237
                  eq_nat_nat_iff eq_number_of_eq nat_0 iszero_def
paulson@14273
   238
            split add: split_if cong add: imp_cong)
paulson@14272
   239
apply (simp only: nat_eq_iff nat_eq_iff2)
paulson@14272
   240
apply (simp add: not_neg_eq_ge_0 [symmetric])
paulson@14272
   241
done
paulson@14272
   242
paulson@14272
   243
paulson@14390
   244
subsubsection{*Less-than (<) *}
paulson@14272
   245
paulson@14272
   246
(*"neg" is used in rewrite rules for binary comparisons*)
paulson@14390
   247
lemma less_nat_number_of [simp]:
paulson@14273
   248
     "((number_of v :: nat) < number_of v') =  
paulson@14378
   249
         (if neg (number_of v :: int) then neg (number_of (bin_minus v') :: int)  
paulson@14378
   250
          else neg (number_of (bin_add v (bin_minus v')) :: int))"
paulson@14390
   251
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def
paulson@14272
   252
                nat_less_eq_zless less_number_of_eq_neg zless_nat_eq_int_zless
paulson@14390
   253
         cong add: imp_cong, simp) 
paulson@14272
   254
paulson@14390
   255
paulson@14272
   256
paulson@14272
   257
paulson@14272
   258
(*Maps #n to n for n = 0, 1, 2*)
paulson@14387
   259
lemmas numerals = nat_numeral_0_eq_0 nat_numeral_1_eq_1 numeral_2_eq_2
paulson@14272
   260
paulson@14272
   261
paulson@15234
   262
subsection{*Powers with Numeric Exponents*}
paulson@14353
   263
paulson@14353
   264
text{*We cannot refer to the number @{term 2} in @{text Ring_and_Field.thy}.
paulson@14353
   265
We cannot prove general results about the numeral @{term "-1"}, so we have to
paulson@14353
   266
use @{term "- 1"} instead.*}
paulson@14353
   267
paulson@15003
   268
lemma power2_eq_square: "(a::'a::{comm_semiring_1_cancel,recpower})\<twosuperior> = a * a"
paulson@14353
   269
  by (simp add: numeral_2_eq_2 Power.power_Suc)
paulson@14353
   270
paulson@17724
   271
lemma zero_power2 [simp]: "(0::'a::{comm_semiring_1_cancel,recpower})\<twosuperior> = 0"
paulson@14353
   272
  by (simp add: power2_eq_square)
paulson@14353
   273
paulson@17724
   274
lemma one_power2 [simp]: "(1::'a::{comm_semiring_1_cancel,recpower})\<twosuperior> = 1"
paulson@14353
   275
  by (simp add: power2_eq_square)
paulson@14353
   276
avigad@16775
   277
lemma power3_eq_cube: "(x::'a::recpower) ^ 3 = x * x * x"
avigad@16775
   278
  apply (subgoal_tac "3 = Suc (Suc (Suc 0))")
avigad@16775
   279
  apply (erule ssubst)
avigad@16775
   280
  apply (simp add: power_Suc mult_ac)
avigad@16775
   281
  apply (unfold nat_number_of_def)
avigad@16775
   282
  apply (subst nat_eq_iff)
avigad@16775
   283
  apply simp
avigad@16775
   284
done
avigad@16775
   285
paulson@14353
   286
text{*Squares of literal numerals will be evaluated.*}
paulson@17085
   287
lemmas power2_eq_square_number_of =
paulson@17085
   288
    power2_eq_square [of "number_of w", standard]
paulson@17085
   289
declare power2_eq_square_number_of [simp]
paulson@17085
   290
paulson@14353
   291
avigad@16775
   292
lemma zero_le_power2: "0 \<le> (a\<twosuperior>::'a::{ordered_idom,recpower})"
paulson@14353
   293
  by (simp add: power2_eq_square zero_le_square)
paulson@14353
   294
avigad@16775
   295
lemma zero_less_power2:
paulson@15003
   296
     "(0 < a\<twosuperior>) = (a \<noteq> (0::'a::{ordered_idom,recpower}))"
paulson@14353
   297
  by (force simp add: power2_eq_square zero_less_mult_iff linorder_neq_iff)
paulson@14353
   298
avigad@16775
   299
lemma power2_less_0:
paulson@15234
   300
  fixes a :: "'a::{ordered_idom,recpower}"
paulson@15234
   301
  shows "~ (a\<twosuperior> < 0)"
paulson@15234
   302
by (force simp add: power2_eq_square mult_less_0_iff) 
paulson@15234
   303
avigad@16775
   304
lemma zero_eq_power2:
paulson@15003
   305
     "(a\<twosuperior> = 0) = (a = (0::'a::{ordered_idom,recpower}))"
paulson@14353
   306
  by (force simp add: power2_eq_square mult_eq_0_iff)
paulson@14353
   307
avigad@16775
   308
lemma abs_power2:
paulson@15003
   309
     "abs(a\<twosuperior>) = (a\<twosuperior>::'a::{ordered_idom,recpower})"
paulson@14353
   310
  by (simp add: power2_eq_square abs_mult abs_mult_self)
paulson@14353
   311
avigad@16775
   312
lemma power2_abs:
paulson@15003
   313
     "(abs a)\<twosuperior> = (a\<twosuperior>::'a::{ordered_idom,recpower})"
paulson@14353
   314
  by (simp add: power2_eq_square abs_mult_self)
paulson@14353
   315
avigad@16775
   316
lemma power2_minus:
paulson@15003
   317
     "(- a)\<twosuperior> = (a\<twosuperior>::'a::{comm_ring_1,recpower})"
paulson@14353
   318
  by (simp add: power2_eq_square)
paulson@14353
   319
paulson@15003
   320
lemma power_minus1_even: "(- 1) ^ (2*n) = (1::'a::{comm_ring_1,recpower})"
paulson@15251
   321
apply (induct "n")
avigad@16775
   322
apply (auto simp add: power_Suc power_add power2_minus)
paulson@14353
   323
done
paulson@14353
   324
paulson@15003
   325
lemma power_even_eq: "(a::'a::recpower) ^ (2*n) = (a^n)^2"
paulson@14443
   326
by (simp add: power_mult power_mult_distrib power2_eq_square)
paulson@14443
   327
paulson@14443
   328
lemma power_odd_eq: "(a::int) ^ Suc(2*n) = a * (a^n)^2"
paulson@14443
   329
by (simp add: power_even_eq) 
paulson@14443
   330
paulson@14353
   331
lemma power_minus_even [simp]:
paulson@15003
   332
     "(-a) ^ (2*n) = (a::'a::{comm_ring_1,recpower}) ^ (2*n)"
paulson@14353
   333
by (simp add: power_minus1_even power_minus [of a]) 
paulson@14353
   334
avigad@16775
   335
lemma zero_le_even_power':
paulson@15003
   336
     "0 \<le> (a::'a::{ordered_idom,recpower}) ^ (2*n)"
paulson@14353
   337
proof (induct "n")
paulson@14353
   338
  case 0
paulson@14353
   339
    show ?case by (simp add: zero_le_one)
paulson@14353
   340
next
paulson@14353
   341
  case (Suc n)
paulson@14353
   342
    have "a ^ (2 * Suc n) = (a*a) * a ^ (2*n)" 
paulson@14353
   343
      by (simp add: mult_ac power_add power2_eq_square)
paulson@14353
   344
    thus ?case
paulson@14353
   345
      by (simp add: prems zero_le_square zero_le_mult_iff)
paulson@14353
   346
qed
paulson@14353
   347
paulson@14353
   348
lemma odd_power_less_zero:
paulson@15003
   349
     "(a::'a::{ordered_idom,recpower}) < 0 ==> a ^ Suc(2*n) < 0"
paulson@14353
   350
proof (induct "n")
paulson@14353
   351
  case 0
paulson@14353
   352
    show ?case by (simp add: Power.power_Suc)
paulson@14353
   353
next
paulson@14353
   354
  case (Suc n)
paulson@14353
   355
    have "a ^ Suc (2 * Suc n) = (a*a) * a ^ Suc(2*n)" 
paulson@14353
   356
      by (simp add: mult_ac power_add power2_eq_square Power.power_Suc)
paulson@14353
   357
    thus ?case
avigad@16775
   358
      by (simp add: prems mult_less_0_iff mult_neg_neg)
paulson@14353
   359
qed
paulson@14353
   360
paulson@14353
   361
lemma odd_0_le_power_imp_0_le:
paulson@15003
   362
     "0 \<le> a  ^ Suc(2*n) ==> 0 \<le> (a::'a::{ordered_idom,recpower})"
paulson@14353
   363
apply (insert odd_power_less_zero [of a n]) 
paulson@14353
   364
apply (force simp add: linorder_not_less [symmetric]) 
paulson@14353
   365
done
paulson@14353
   366
paulson@15234
   367
text{*Simprules for comparisons where common factors can be cancelled.*}
paulson@15234
   368
lemmas zero_compare_simps =
paulson@15234
   369
    add_strict_increasing add_strict_increasing2 add_increasing
paulson@15234
   370
    zero_le_mult_iff zero_le_divide_iff 
paulson@15234
   371
    zero_less_mult_iff zero_less_divide_iff 
paulson@15234
   372
    mult_le_0_iff divide_le_0_iff 
paulson@15234
   373
    mult_less_0_iff divide_less_0_iff 
paulson@15234
   374
    zero_le_power2 power2_less_0
paulson@14353
   375
paulson@14390
   376
subsubsection{*Nat *}
paulson@14272
   377
paulson@14272
   378
lemma Suc_pred': "0 < n ==> n = Suc(n - 1)"
paulson@14273
   379
by (simp add: numerals)
paulson@14272
   380
paulson@14272
   381
(*Expresses a natural number constant as the Suc of another one.
paulson@14272
   382
  NOT suitable for rewriting because n recurs in the condition.*)
paulson@14272
   383
lemmas expand_Suc = Suc_pred' [of "number_of v", standard]
paulson@14272
   384
paulson@14390
   385
subsubsection{*Arith *}
paulson@14272
   386
paulson@14272
   387
lemma Suc_eq_add_numeral_1: "Suc n = n + 1"
paulson@14273
   388
by (simp add: numerals)
paulson@14272
   389
paulson@14467
   390
lemma Suc_eq_add_numeral_1_left: "Suc n = 1 + n"
paulson@14467
   391
by (simp add: numerals)
paulson@14467
   392
paulson@14272
   393
(* These two can be useful when m = number_of... *)
paulson@14272
   394
paulson@14272
   395
lemma add_eq_if: "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))"
paulson@14272
   396
apply (case_tac "m")
paulson@14272
   397
apply (simp_all add: numerals)
paulson@14272
   398
done
paulson@14272
   399
paulson@14272
   400
lemma mult_eq_if: "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))"
paulson@14272
   401
apply (case_tac "m")
paulson@14272
   402
apply (simp_all add: numerals)
paulson@14272
   403
done
paulson@14272
   404
paulson@14272
   405
lemma power_eq_if: "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))"
paulson@14272
   406
apply (case_tac "m")
paulson@14272
   407
apply (simp_all add: numerals)
paulson@14272
   408
done
paulson@14272
   409
paulson@14272
   410
paulson@14390
   411
subsection{*Comparisons involving (0::nat) *}
paulson@14272
   412
paulson@14390
   413
text{*Simplification already does @{term "n<0"}, @{term "n\<le>0"} and @{term "0\<le>n"}.*}
paulson@14390
   414
paulson@14390
   415
lemma eq_number_of_0 [simp]:
paulson@14273
   416
     "(number_of v = (0::nat)) =  
paulson@14378
   417
      (if neg (number_of v :: int) then True else iszero (number_of v :: int))"
paulson@14390
   418
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] iszero_0)
paulson@14272
   419
paulson@14390
   420
lemma eq_0_number_of [simp]:
paulson@14273
   421
     "((0::nat) = number_of v) =  
paulson@14378
   422
      (if neg (number_of v :: int) then True else iszero (number_of v :: int))"
paulson@14390
   423
by (rule trans [OF eq_sym_conv eq_number_of_0])
paulson@14272
   424
paulson@14390
   425
lemma less_0_number_of [simp]:
paulson@14378
   426
     "((0::nat) < number_of v) = neg (number_of (bin_minus v) :: int)"
paulson@14387
   427
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric])
paulson@14272
   428
paulson@14272
   429
paulson@14378
   430
lemma neg_imp_number_of_eq_0: "neg (number_of v :: int) ==> number_of v = (0::nat)"
paulson@14387
   431
by (simp del: nat_numeral_0_eq_0 add: nat_numeral_0_eq_0 [symmetric] iszero_0)
paulson@14272
   432
paulson@14272
   433
paulson@14272
   434
paulson@14390
   435
subsection{*Comparisons involving Suc *}
paulson@14272
   436
paulson@14273
   437
lemma eq_number_of_Suc [simp]:
paulson@14273
   438
     "(number_of v = Suc n) =  
paulson@14272
   439
        (let pv = number_of (bin_pred v) in  
paulson@14272
   440
         if neg pv then False else nat pv = n)"
paulson@14272
   441
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
paulson@14272
   442
                  number_of_pred nat_number_of_def 
paulson@14273
   443
            split add: split_if)
paulson@14272
   444
apply (rule_tac x = "number_of v" in spec)
paulson@14272
   445
apply (auto simp add: nat_eq_iff)
paulson@14272
   446
done
paulson@14272
   447
paulson@14273
   448
lemma Suc_eq_number_of [simp]:
paulson@14273
   449
     "(Suc n = number_of v) =  
paulson@14272
   450
        (let pv = number_of (bin_pred v) in  
paulson@14272
   451
         if neg pv then False else nat pv = n)"
paulson@14390
   452
by (rule trans [OF eq_sym_conv eq_number_of_Suc])
paulson@14272
   453
paulson@14273
   454
lemma less_number_of_Suc [simp]:
paulson@14273
   455
     "(number_of v < Suc n) =  
paulson@14272
   456
        (let pv = number_of (bin_pred v) in  
paulson@14272
   457
         if neg pv then True else nat pv < n)"
paulson@14272
   458
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
paulson@14272
   459
                  number_of_pred nat_number_of_def  
paulson@14273
   460
            split add: split_if)
paulson@14272
   461
apply (rule_tac x = "number_of v" in spec)
paulson@14272
   462
apply (auto simp add: nat_less_iff)
paulson@14272
   463
done
paulson@14272
   464
paulson@14273
   465
lemma less_Suc_number_of [simp]:
paulson@14273
   466
     "(Suc n < number_of v) =  
paulson@14272
   467
        (let pv = number_of (bin_pred v) in  
paulson@14272
   468
         if neg pv then False else n < nat pv)"
paulson@14272
   469
apply (simp only: simp_thms Let_def neg_eq_less_0 linorder_not_less 
paulson@14272
   470
                  number_of_pred nat_number_of_def
paulson@14273
   471
            split add: split_if)
paulson@14272
   472
apply (rule_tac x = "number_of v" in spec)
paulson@14272
   473
apply (auto simp add: zless_nat_eq_int_zless)
paulson@14272
   474
done
paulson@14272
   475
paulson@14273
   476
lemma le_number_of_Suc [simp]:
paulson@14273
   477
     "(number_of v <= Suc n) =  
paulson@14272
   478
        (let pv = number_of (bin_pred v) in  
paulson@14272
   479
         if neg pv then True else nat pv <= n)"
paulson@14390
   480
by (simp add: Let_def less_Suc_number_of linorder_not_less [symmetric])
paulson@14272
   481
paulson@14273
   482
lemma le_Suc_number_of [simp]:
paulson@14273
   483
     "(Suc n <= number_of v) =  
paulson@14272
   484
        (let pv = number_of (bin_pred v) in  
paulson@14272
   485
         if neg pv then False else n <= nat pv)"
paulson@14390
   486
by (simp add: Let_def less_number_of_Suc linorder_not_less [symmetric])
paulson@14272
   487
paulson@14272
   488
paulson@14272
   489
(* Push int(.) inwards: *)
paulson@14272
   490
declare zadd_int [symmetric, simp]
paulson@14272
   491
paulson@14272
   492
lemma lemma1: "(m+m = n+n) = (m = (n::int))"
paulson@14273
   493
by auto
paulson@14272
   494
paulson@14272
   495
lemma lemma2: "m+m ~= (1::int) + (n + n)"
paulson@14272
   496
apply auto
paulson@14272
   497
apply (drule_tac f = "%x. x mod 2" in arg_cong)
paulson@14273
   498
apply (simp add: zmod_zadd1_eq)
paulson@14272
   499
done
paulson@14272
   500
paulson@14273
   501
lemma eq_number_of_BIT_BIT:
paulson@14273
   502
     "((number_of (v BIT x) ::int) = number_of (w BIT y)) =  
paulson@14272
   503
      (x=y & (((number_of v) ::int) = number_of w))"
paulson@15620
   504
apply (simp only: number_of_BIT lemma1 lemma2 eq_commute
obua@14738
   505
               OrderedGroup.add_left_cancel add_assoc OrderedGroup.add_0
paulson@15620
   506
            split add: bit.split) 
paulson@15620
   507
apply simp
paulson@15620
   508
done
paulson@14272
   509
paulson@14273
   510
lemma eq_number_of_BIT_Pls:
paulson@15013
   511
     "((number_of (v BIT x) ::int) = Numeral0) =  
paulson@15620
   512
      (x=bit.B0 & (((number_of v) ::int) = Numeral0))"
paulson@14272
   513
apply (simp only: simp_thms  add: number_of_BIT number_of_Pls eq_commute
paulson@15620
   514
            split add: bit.split cong: imp_cong)
paulson@14273
   515
apply (rule_tac x = "number_of v" in spec, safe)
paulson@14272
   516
apply (simp_all (no_asm_use))
paulson@14272
   517
apply (drule_tac f = "%x. x mod 2" in arg_cong)
paulson@14273
   518
apply (simp add: zmod_zadd1_eq)
paulson@14272
   519
done
paulson@14272
   520
paulson@14273
   521
lemma eq_number_of_BIT_Min:
paulson@15013
   522
     "((number_of (v BIT x) ::int) = number_of Numeral.Min) =  
paulson@15620
   523
      (x=bit.B1 & (((number_of v) ::int) = number_of Numeral.Min))"
paulson@14272
   524
apply (simp only: simp_thms  add: number_of_BIT number_of_Min eq_commute
paulson@15620
   525
            split add: bit.split cong: imp_cong)
paulson@14273
   526
apply (rule_tac x = "number_of v" in spec, auto)
paulson@14273
   527
apply (drule_tac f = "%x. x mod 2" in arg_cong, auto)
paulson@14272
   528
done
paulson@14272
   529
paulson@15013
   530
lemma eq_number_of_Pls_Min: "(Numeral0 ::int) ~= number_of Numeral.Min"
paulson@14273
   531
by auto
paulson@14272
   532
paulson@14272
   533
paulson@14272
   534
paulson@14390
   535
subsection{*Literal arithmetic involving powers*}
paulson@14272
   536
paulson@14272
   537
lemma nat_power_eq: "(0::int) <= z ==> nat (z^n) = nat z ^ n"
paulson@15251
   538
apply (induct "n")
paulson@14272
   539
apply (simp_all (no_asm_simp) add: nat_mult_distrib)
paulson@14272
   540
done
paulson@14272
   541
paulson@14273
   542
lemma power_nat_number_of:
paulson@14273
   543
     "(number_of v :: nat) ^ n =  
paulson@14378
   544
       (if neg (number_of v :: int) then 0^n else nat ((number_of v :: int) ^ n))"
paulson@14272
   545
by (simp only: simp_thms neg_nat not_neg_eq_ge_0 nat_number_of_def nat_power_eq
paulson@14272
   546
         split add: split_if cong: imp_cong)
paulson@14272
   547
paulson@14272
   548
paulson@17085
   549
lemmas power_nat_number_of_number_of = power_nat_number_of [of _ "number_of w", standard]
paulson@17085
   550
declare power_nat_number_of_number_of [simp]
paulson@17085
   551
paulson@14272
   552
paulson@14272
   553
paulson@14390
   554
text{*For the integers*}
paulson@14272
   555
paulson@14273
   556
lemma zpower_number_of_even:
paulson@15620
   557
     "(z::int) ^ number_of (w BIT bit.B0) =  
paulson@14272
   558
      (let w = z ^ (number_of w) in  w*w)"
paulson@14272
   559
apply (simp del: nat_number_of  add: nat_number_of_def number_of_BIT Let_def)
paulson@14272
   560
apply (simp only: number_of_add) 
paulson@14273
   561
apply (rule_tac x = "number_of w" in spec, clarify)
paulson@14272
   562
apply (case_tac " (0::int) <= x")
paulson@14443
   563
apply (auto simp add: nat_mult_distrib power_even_eq power2_eq_square)
paulson@14272
   564
done
paulson@14272
   565
paulson@14273
   566
lemma zpower_number_of_odd:
paulson@15620
   567
     "(z::int) ^ number_of (w BIT bit.B1) =  
paulson@14272
   568
          (if (0::int) <= number_of w                    
paulson@14272
   569
           then (let w = z ^ (number_of w) in  z*w*w)    
paulson@14272
   570
           else 1)"
paulson@14272
   571
apply (simp del: nat_number_of  add: nat_number_of_def number_of_BIT Let_def)
paulson@14387
   572
apply (simp only: number_of_add nat_numeral_1_eq_1 not_neg_eq_ge_0 neg_eq_less_0) 
paulson@14273
   573
apply (rule_tac x = "number_of w" in spec, clarify)
paulson@14443
   574
apply (auto simp add: nat_add_distrib nat_mult_distrib power_even_eq power2_eq_square neg_nat)
paulson@14272
   575
done
paulson@14272
   576
paulson@17085
   577
lemmas zpower_number_of_even_number_of =
paulson@17085
   578
    zpower_number_of_even [of "number_of v", standard]
paulson@17085
   579
declare zpower_number_of_even_number_of [simp]
paulson@17085
   580
paulson@17085
   581
lemmas zpower_number_of_odd_number_of =
paulson@17085
   582
    zpower_number_of_odd [of "number_of v", standard]
paulson@17085
   583
declare zpower_number_of_odd_number_of [simp]
paulson@17085
   584
paulson@14272
   585
paulson@14272
   586
paulson@14272
   587
paulson@14272
   588
ML
paulson@14272
   589
{*
paulson@14272
   590
val numerals = thms"numerals";
paulson@14272
   591
val numeral_ss = simpset() addsimps numerals;
paulson@14272
   592
paulson@14272
   593
val nat_bin_arith_setup =
wenzelm@18708
   594
 Fast_Arith.map_data
nipkow@15921
   595
   (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, neqE, simpset} =>
paulson@14272
   596
     {add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms,
paulson@14272
   597
      inj_thms = inj_thms,
nipkow@15921
   598
      lessD = lessD, neqE = neqE,
paulson@14272
   599
      simpset = simpset addsimps [Suc_nat_number_of, int_nat_number_of,
paulson@14272
   600
                                  not_neg_number_of_Pls,
wenzelm@18708
   601
                                  neg_number_of_Min,neg_number_of_BIT]})
paulson@14272
   602
*}
paulson@14272
   603
wenzelm@12838
   604
setup nat_bin_arith_setup
wenzelm@12838
   605
nipkow@13189
   606
(* Enable arith to deal with div/mod k where k is a numeral: *)
nipkow@13189
   607
declare split_div[of _ _ "number_of k", standard, arith_split]
nipkow@13189
   608
declare split_mod[of _ _ "number_of k", standard, arith_split]
nipkow@13154
   609
paulson@15013
   610
lemma nat_number_of_Pls: "Numeral0 = (0::nat)"
wenzelm@12838
   611
  by (simp add: number_of_Pls nat_number_of_def)
wenzelm@12838
   612
paulson@15013
   613
lemma nat_number_of_Min: "number_of Numeral.Min = (0::nat)"
wenzelm@12838
   614
  apply (simp only: number_of_Min nat_number_of_def nat_zminus_int)
wenzelm@12838
   615
  apply (simp add: neg_nat)
wenzelm@12838
   616
  done
paulson@7032
   617
paulson@15620
   618
lemma nat_number_of_BIT_1:
paulson@15620
   619
  "number_of (w BIT bit.B1) =
paulson@14378
   620
    (if neg (number_of w :: int) then 0
wenzelm@12838
   621
     else let n = number_of w in Suc (n + n))"
wenzelm@12838
   622
  apply (simp only: nat_number_of_def Let_def split: split_if)
wenzelm@12838
   623
  apply (intro conjI impI)
wenzelm@12838
   624
   apply (simp add: neg_nat neg_number_of_BIT)
wenzelm@12838
   625
  apply (rule int_int_eq [THEN iffD1])
wenzelm@12838
   626
  apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms)
paulson@15620
   627
  apply (simp only: number_of_BIT zadd_assoc split: bit.split)
paulson@15620
   628
  apply simp
wenzelm@12838
   629
  done
paulson@7032
   630
paulson@15620
   631
lemma nat_number_of_BIT_0:
paulson@15620
   632
    "number_of (w BIT bit.B0) = (let n::nat = number_of w in n + n)"
wenzelm@12838
   633
  apply (simp only: nat_number_of_def Let_def)
paulson@14378
   634
  apply (cases "neg (number_of w :: int)")
wenzelm@12838
   635
   apply (simp add: neg_nat neg_number_of_BIT)
wenzelm@12838
   636
  apply (rule int_int_eq [THEN iffD1])
wenzelm@12838
   637
  apply (simp only: not_neg_nat neg_number_of_BIT int_Suc zadd_int [symmetric] simp_thms)
paulson@15620
   638
  apply (simp only: number_of_BIT zadd_assoc)
paulson@15620
   639
  apply simp
wenzelm@12838
   640
  done
wenzelm@12838
   641
wenzelm@13043
   642
lemmas nat_number =
wenzelm@12838
   643
  nat_number_of_Pls nat_number_of_Min
paulson@15620
   644
  nat_number_of_BIT_1 nat_number_of_BIT_0
wenzelm@12838
   645
wenzelm@12838
   646
lemma Let_Suc [simp]: "Let (Suc n) f == f (Suc n)"
wenzelm@12838
   647
  by (simp add: Let_def)
nipkow@10574
   648
paulson@15003
   649
lemma power_m1_even: "(-1) ^ (2*n) = (1::'a::{number_ring,recpower})"
paulson@14443
   650
by (simp add: power_mult); 
paulson@14443
   651
paulson@15003
   652
lemma power_m1_odd: "(-1) ^ Suc(2*n) = (-1::'a::{number_ring,recpower})"
paulson@14443
   653
by (simp add: power_mult power_Suc); 
paulson@14443
   654
berghofe@12440
   655
paulson@14390
   656
subsection{*Literal arithmetic and @{term of_nat}*}
paulson@14390
   657
paulson@14390
   658
lemma of_nat_double:
paulson@14390
   659
     "0 \<le> x ==> of_nat (nat (2 * x)) = of_nat (nat x) + of_nat (nat x)"
paulson@14390
   660
by (simp only: mult_2 nat_add_distrib of_nat_add) 
paulson@14390
   661
paulson@14390
   662
lemma nat_numeral_m1_eq_0: "-1 = (0::nat)"
paulson@14390
   663
by (simp only:  nat_number_of_def, simp)
paulson@14390
   664
paulson@14390
   665
lemma of_nat_number_of_lemma:
paulson@14390
   666
     "of_nat (number_of v :: nat) =  
paulson@14390
   667
         (if 0 \<le> (number_of v :: int) 
paulson@14390
   668
          then (number_of v :: 'a :: number_ring)
paulson@14390
   669
          else 0)"
paulson@15013
   670
by (simp add: int_number_of_def nat_number_of_def number_of_eq of_nat_nat);
paulson@14390
   671
paulson@14390
   672
lemma of_nat_number_of_eq [simp]:
paulson@14390
   673
     "of_nat (number_of v :: nat) =  
paulson@14390
   674
         (if neg (number_of v :: int) then 0  
paulson@14390
   675
          else (number_of v :: 'a :: number_ring))"
paulson@14390
   676
by (simp only: of_nat_number_of_lemma neg_def, simp) 
paulson@14390
   677
paulson@14390
   678
paulson@14273
   679
subsection {*Lemmas for the Combination and Cancellation Simprocs*}
paulson@14273
   680
paulson@14273
   681
lemma nat_number_of_add_left:
paulson@14273
   682
     "number_of v + (number_of v' + (k::nat)) =  
paulson@14378
   683
         (if neg (number_of v :: int) then number_of v' + k  
paulson@14378
   684
          else if neg (number_of v' :: int) then number_of v + k  
paulson@14273
   685
          else number_of (bin_add v v') + k)"
paulson@14390
   686
by simp
paulson@14273
   687
paulson@14430
   688
lemma nat_number_of_mult_left:
paulson@14430
   689
     "number_of v * (number_of v' * (k::nat)) =  
paulson@14430
   690
         (if neg (number_of v :: int) then 0
paulson@14430
   691
          else number_of (bin_mult v v') * k)"
paulson@14430
   692
by simp
paulson@14430
   693
paulson@14273
   694
paulson@14390
   695
subsubsection{*For @{text combine_numerals}*}
paulson@14273
   696
paulson@14273
   697
lemma left_add_mult_distrib: "i*u + (j*u + k) = (i+j)*u + (k::nat)"
paulson@14273
   698
by (simp add: add_mult_distrib)
paulson@14273
   699
paulson@14273
   700
paulson@14390
   701
subsubsection{*For @{text cancel_numerals}*}
paulson@14273
   702
paulson@14273
   703
lemma nat_diff_add_eq1:
paulson@14273
   704
     "j <= (i::nat) ==> ((i*u + m) - (j*u + n)) = (((i-j)*u + m) - n)"
paulson@14273
   705
by (simp split add: nat_diff_split add: add_mult_distrib)
paulson@14273
   706
paulson@14273
   707
lemma nat_diff_add_eq2:
paulson@14273
   708
     "i <= (j::nat) ==> ((i*u + m) - (j*u + n)) = (m - ((j-i)*u + n))"
paulson@14273
   709
by (simp split add: nat_diff_split add: add_mult_distrib)
paulson@14273
   710
paulson@14273
   711
lemma nat_eq_add_iff1:
paulson@14273
   712
     "j <= (i::nat) ==> (i*u + m = j*u + n) = ((i-j)*u + m = n)"
paulson@14273
   713
by (auto split add: nat_diff_split simp add: add_mult_distrib)
paulson@14273
   714
paulson@14273
   715
lemma nat_eq_add_iff2:
paulson@14273
   716
     "i <= (j::nat) ==> (i*u + m = j*u + n) = (m = (j-i)*u + n)"
paulson@14273
   717
by (auto split add: nat_diff_split simp add: add_mult_distrib)
paulson@14273
   718
paulson@14273
   719
lemma nat_less_add_iff1:
paulson@14273
   720
     "j <= (i::nat) ==> (i*u + m < j*u + n) = ((i-j)*u + m < n)"
paulson@14273
   721
by (auto split add: nat_diff_split simp add: add_mult_distrib)
paulson@14273
   722
paulson@14273
   723
lemma nat_less_add_iff2:
paulson@14273
   724
     "i <= (j::nat) ==> (i*u + m < j*u + n) = (m < (j-i)*u + n)"
paulson@14273
   725
by (auto split add: nat_diff_split simp add: add_mult_distrib)
paulson@14273
   726
paulson@14273
   727
lemma nat_le_add_iff1:
paulson@14273
   728
     "j <= (i::nat) ==> (i*u + m <= j*u + n) = ((i-j)*u + m <= n)"
paulson@14273
   729
by (auto split add: nat_diff_split simp add: add_mult_distrib)
paulson@14273
   730
paulson@14273
   731
lemma nat_le_add_iff2:
paulson@14273
   732
     "i <= (j::nat) ==> (i*u + m <= j*u + n) = (m <= (j-i)*u + n)"
paulson@14273
   733
by (auto split add: nat_diff_split simp add: add_mult_distrib)
paulson@14273
   734
paulson@14273
   735
paulson@14390
   736
subsubsection{*For @{text cancel_numeral_factors} *}
paulson@14273
   737
paulson@14273
   738
lemma nat_mult_le_cancel1: "(0::nat) < k ==> (k*m <= k*n) = (m<=n)"
paulson@14273
   739
by auto
paulson@14273
   740
paulson@14273
   741
lemma nat_mult_less_cancel1: "(0::nat) < k ==> (k*m < k*n) = (m<n)"
paulson@14273
   742
by auto
paulson@14273
   743
paulson@14273
   744
lemma nat_mult_eq_cancel1: "(0::nat) < k ==> (k*m = k*n) = (m=n)"
paulson@14273
   745
by auto
paulson@14273
   746
paulson@14273
   747
lemma nat_mult_div_cancel1: "(0::nat) < k ==> (k*m) div (k*n) = (m div n)"
paulson@14273
   748
by auto
paulson@14273
   749
paulson@14273
   750
paulson@14390
   751
subsubsection{*For @{text cancel_factor} *}
paulson@14273
   752
paulson@14273
   753
lemma nat_mult_le_cancel_disj: "(k*m <= k*n) = ((0::nat) < k --> m<=n)"
paulson@14273
   754
by auto
paulson@14273
   755
paulson@14273
   756
lemma nat_mult_less_cancel_disj: "(k*m < k*n) = ((0::nat) < k & m<n)"
paulson@14273
   757
by auto
paulson@14273
   758
paulson@14273
   759
lemma nat_mult_eq_cancel_disj: "(k*m = k*n) = (k = (0::nat) | m=n)"
paulson@14273
   760
by auto
paulson@14273
   761
paulson@14273
   762
lemma nat_mult_div_cancel_disj:
paulson@14273
   763
     "(k*m) div (k*n) = (if k = (0::nat) then 0 else m div n)"
paulson@14273
   764
by (simp add: nat_mult_div_cancel1)
paulson@14273
   765
paulson@14273
   766
ML
paulson@14273
   767
{*
paulson@14353
   768
val eq_nat_nat_iff = thm"eq_nat_nat_iff";
paulson@14353
   769
val eq_nat_number_of = thm"eq_nat_number_of";
paulson@14353
   770
val less_nat_number_of = thm"less_nat_number_of";
paulson@14353
   771
val power2_eq_square = thm "power2_eq_square";
paulson@14353
   772
val zero_le_power2 = thm "zero_le_power2";
paulson@14353
   773
val zero_less_power2 = thm "zero_less_power2";
paulson@14353
   774
val zero_eq_power2 = thm "zero_eq_power2";
paulson@14353
   775
val abs_power2 = thm "abs_power2";
paulson@14353
   776
val power2_abs = thm "power2_abs";
paulson@14353
   777
val power2_minus = thm "power2_minus";
paulson@14353
   778
val power_minus1_even = thm "power_minus1_even";
paulson@14353
   779
val power_minus_even = thm "power_minus_even";
avigad@16775
   780
(* val zero_le_even_power = thm "zero_le_even_power"; *)
paulson@14353
   781
val odd_power_less_zero = thm "odd_power_less_zero";
paulson@14353
   782
val odd_0_le_power_imp_0_le = thm "odd_0_le_power_imp_0_le";
paulson@14353
   783
paulson@14353
   784
val Suc_pred' = thm"Suc_pred'";
paulson@14353
   785
val expand_Suc = thm"expand_Suc";
paulson@14353
   786
val Suc_eq_add_numeral_1 = thm"Suc_eq_add_numeral_1";
paulson@14467
   787
val Suc_eq_add_numeral_1_left = thm"Suc_eq_add_numeral_1_left";
paulson@14353
   788
val add_eq_if = thm"add_eq_if";
paulson@14353
   789
val mult_eq_if = thm"mult_eq_if";
paulson@14353
   790
val power_eq_if = thm"power_eq_if";
paulson@14353
   791
val eq_number_of_0 = thm"eq_number_of_0";
paulson@14353
   792
val eq_0_number_of = thm"eq_0_number_of";
paulson@14353
   793
val less_0_number_of = thm"less_0_number_of";
paulson@14353
   794
val neg_imp_number_of_eq_0 = thm"neg_imp_number_of_eq_0";
paulson@14353
   795
val eq_number_of_Suc = thm"eq_number_of_Suc";
paulson@14353
   796
val Suc_eq_number_of = thm"Suc_eq_number_of";
paulson@14353
   797
val less_number_of_Suc = thm"less_number_of_Suc";
paulson@14353
   798
val less_Suc_number_of = thm"less_Suc_number_of";
paulson@14353
   799
val le_number_of_Suc = thm"le_number_of_Suc";
paulson@14353
   800
val le_Suc_number_of = thm"le_Suc_number_of";
paulson@14353
   801
val eq_number_of_BIT_BIT = thm"eq_number_of_BIT_BIT";
paulson@14353
   802
val eq_number_of_BIT_Pls = thm"eq_number_of_BIT_Pls";
paulson@14353
   803
val eq_number_of_BIT_Min = thm"eq_number_of_BIT_Min";
paulson@14353
   804
val eq_number_of_Pls_Min = thm"eq_number_of_Pls_Min";
paulson@14390
   805
val of_nat_number_of_eq = thm"of_nat_number_of_eq";
paulson@14353
   806
val nat_power_eq = thm"nat_power_eq";
paulson@14353
   807
val power_nat_number_of = thm"power_nat_number_of";
paulson@14353
   808
val zpower_number_of_even = thm"zpower_number_of_even";
paulson@14353
   809
val zpower_number_of_odd = thm"zpower_number_of_odd";
paulson@14353
   810
val nat_number_of_Pls = thm"nat_number_of_Pls";
paulson@14353
   811
val nat_number_of_Min = thm"nat_number_of_Min";
paulson@14353
   812
val Let_Suc = thm"Let_Suc";
paulson@14353
   813
paulson@14353
   814
val nat_number = thms"nat_number";
paulson@14353
   815
paulson@14273
   816
val nat_number_of_add_left = thm"nat_number_of_add_left";
paulson@14430
   817
val nat_number_of_mult_left = thm"nat_number_of_mult_left";
paulson@14273
   818
val left_add_mult_distrib = thm"left_add_mult_distrib";
paulson@14273
   819
val nat_diff_add_eq1 = thm"nat_diff_add_eq1";
paulson@14273
   820
val nat_diff_add_eq2 = thm"nat_diff_add_eq2";
paulson@14273
   821
val nat_eq_add_iff1 = thm"nat_eq_add_iff1";
paulson@14273
   822
val nat_eq_add_iff2 = thm"nat_eq_add_iff2";
paulson@14273
   823
val nat_less_add_iff1 = thm"nat_less_add_iff1";
paulson@14273
   824
val nat_less_add_iff2 = thm"nat_less_add_iff2";
paulson@14273
   825
val nat_le_add_iff1 = thm"nat_le_add_iff1";
paulson@14273
   826
val nat_le_add_iff2 = thm"nat_le_add_iff2";
paulson@14273
   827
val nat_mult_le_cancel1 = thm"nat_mult_le_cancel1";
paulson@14273
   828
val nat_mult_less_cancel1 = thm"nat_mult_less_cancel1";
paulson@14273
   829
val nat_mult_eq_cancel1 = thm"nat_mult_eq_cancel1";
paulson@14273
   830
val nat_mult_div_cancel1 = thm"nat_mult_div_cancel1";
paulson@14273
   831
val nat_mult_le_cancel_disj = thm"nat_mult_le_cancel_disj";
paulson@14273
   832
val nat_mult_less_cancel_disj = thm"nat_mult_less_cancel_disj";
paulson@14273
   833
val nat_mult_eq_cancel_disj = thm"nat_mult_eq_cancel_disj";
paulson@14273
   834
val nat_mult_div_cancel_disj = thm"nat_mult_div_cancel_disj";
paulson@14353
   835
paulson@14353
   836
val power_minus_even = thm"power_minus_even";
avigad@16775
   837
(* val zero_le_even_power = thm"zero_le_even_power"; *)
paulson@14273
   838
*}
paulson@14273
   839
paulson@7032
   840
end