src/HOL/Integ/NatBin.ML
author paulson
Wed, 21 Jul 1999 15:20:26 +0200
changeset 7056 522a7013d7df
parent 7032 d6efb3b8e669
child 7075 5ba8d1e42ca6
permissions -rw-r--r--
more existing theorems renamed to use #0; also new results
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     1
(*  Title:      HOL/NatBin.ML
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     2
    ID:         $Id$
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     5
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     6
Binary arithmetic for the natural numbers
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     7
*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     8
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
     9
(** nat (coercion from int to nat) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    10
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    11
Goal "nat (number_of w) = number_of w";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    12
by (simp_tac (simpset() addsimps [nat_number_of_def]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    13
qed "nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    14
Addsimps [nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    15
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    16
(*These rewrites should one day be re-oriented...*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    17
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    18
Goal "#0 = 0";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    19
by (simp_tac (simpset_of Int.thy addsimps [nat_0, nat_number_of_def]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    20
qed "numeral_0_eq_0";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    21
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    22
Goal "#1 = 1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    23
by (simp_tac (simpset_of Int.thy addsimps [nat_1, nat_number_of_def]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    24
qed "numeral_1_eq_1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    25
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    26
Goal "#2 = 2";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    27
by (simp_tac (simpset_of Int.thy addsimps [nat_2, nat_number_of_def]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    28
qed "numeral_2_eq_2";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    29
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    30
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    31
(** int (coercion from nat to int) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    32
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    33
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    34
Goal "int (number_of v :: nat) = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    35
\        (if neg (number_of v) then #0 \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    36
\         else (number_of v :: int))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    37
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    38
    (simpset_of Int.thy addsimps [neg_nat, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    39
				  not_neg_nat, int_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    40
qed "int_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    41
Addsimps [int_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    42
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    43
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    44
(** Successor **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    45
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    46
Goal "(#0::int) <= z ==> Suc (nat z) = nat (#1 + z)";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    47
br sym 1;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    48
by (asm_simp_tac (simpset() addsimps [nat_eq_iff]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    49
qed "Suc_nat_eq_nat_zadd1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    50
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    51
Goal "Suc (number_of v) = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    52
\       (if neg (number_of v) then #1 else number_of (bin_succ v))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    53
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    54
    (simpset_of Int.thy addsimps [neg_nat, nat_1, not_neg_eq_ge_0, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    55
				  nat_number_of_def, int_Suc, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    56
				  Suc_nat_eq_nat_zadd1, number_of_succ]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    57
qed "Suc_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    58
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    59
Goal "Suc #0 = #1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    60
by (simp_tac (simpset() addsimps [Suc_nat_number_of]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    61
qed "Suc_numeral_0_eq_1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    62
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    63
Goal "Suc #1 = #2";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    64
by (simp_tac (simpset() addsimps [Suc_nat_number_of]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    65
qed "Suc_numeral_1_eq_2";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    66
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    67
(** Addition **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    68
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    69
Goal "[| (#0::int) <= z;  #0 <= z' |] ==> nat z + nat z' = nat (z+z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    70
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    71
by (asm_simp_tac (simpset() addsimps [zadd_int RS sym]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    72
qed "add_nat_eq_nat_zadd";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    73
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    74
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    75
Goal "(number_of v :: nat) + number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    76
\        (if neg (number_of v) then number_of v' \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    77
\         else if neg (number_of v') then number_of v \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    78
\         else number_of (bin_add v v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    79
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    80
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    81
				  add_nat_eq_nat_zadd, number_of_add]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    82
qed "add_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    83
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    84
Addsimps [add_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    85
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    86
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    87
(** Subtraction **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    88
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    89
Goal "[| (#0::int) <= z';  z' <= z |] ==> nat z - nat z' = nat (z-z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    90
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    91
by (asm_simp_tac (simpset() addsimps [zdiff_int RS sym, nat_le_eq_zle]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    92
qed "diff_nat_eq_nat_zdiff";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    93
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    94
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    95
Goal "nat z - nat z' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    96
\       (if neg z' then nat z  \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    97
\        else let d = z-z' in    \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    98
\             if neg d then 0 else nat d)";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    99
by (simp_tac (simpset() addsimps [Let_def, diff_nat_eq_nat_zdiff,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   100
				  neg_eq_less_0, not_neg_eq_ge_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   101
by (simp_tac (simpset() addsimps zcompare_rls@
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   102
		                 [diff_is_0_eq, nat_le_eq_zle]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   103
qed "diff_nat_eq_if";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   104
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   105
Goalw [nat_number_of_def]
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   106
     "(number_of v :: nat) - number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   107
\       (if neg (number_of v') then number_of v \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   108
\        else let d = number_of (bin_add v (bin_minus v')) in    \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   109
\             if neg d then #0 else nat d)";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   110
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   111
    (simpset_of Int.thy delcongs [if_weak_cong]
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   112
			addsimps [not_neg_eq_ge_0, nat_0,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   113
				  diff_nat_eq_if, diff_number_of_eq]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   114
qed "diff_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   115
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   116
Addsimps [diff_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   117
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   118
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   119
(** Multiplication **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   120
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   121
Goal "(#0::int) <= z ==> nat z * nat z' = nat (z*z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   122
by (case_tac "#0 <= z'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   123
by (subgoal_tac "z'*z <= #0" 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   124
by (rtac (neg_imp_zmult_nonpos_iff RS iffD2) 3);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   125
by Auto_tac;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   126
by (subgoal_tac "#0 <= z*z'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   127
by (force_tac (claset() addDs [zmult_zle_mono1], simpset()) 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   128
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   129
by (asm_simp_tac (simpset() addsimps [zmult_int RS sym]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   130
qed "mult_nat_eq_nat_zmult";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   131
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   132
Goal "(number_of v :: nat) * number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   133
\      (if neg (number_of v) then #0 else number_of (bin_mult v v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   134
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   135
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   136
				  mult_nat_eq_nat_zmult, number_of_mult, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   137
				  nat_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   138
qed "mult_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   139
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   140
Addsimps [mult_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   141
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   142
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   143
(** Quotient **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   144
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   145
Goal "(#0::int) <= z ==> nat z div nat z' = nat (z div z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   146
by (case_tac "#0 <= z'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   147
by (auto_tac (claset(), 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   148
	      simpset() addsimps [div_nonneg_neg, DIVISION_BY_ZERO_DIV]));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   149
by (zdiv_undefined_case_tac "z' = #0" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   150
 by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_DIV]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   151
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   152
by (rename_tac "m m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   153
by (subgoal_tac "#0 <= int m div int m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   154
 by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, numeral_0_eq_0, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   155
				       pos_imp_zdiv_nonneg_iff]) 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   156
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   157
by (Asm_simp_tac 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   158
by (rtac sym 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   159
by (res_inst_tac [("r", "int (m mod m')")] quorem_div 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   160
 by (Force_tac 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   161
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, quorem_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   162
				      numeral_0_eq_0, zadd_int, zmult_int, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   163
				      mod_less_divisor]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   164
by (rtac (mod_div_equality RS sym RS trans) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   165
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   166
qed "div_nat_eq_nat_zdiv";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   167
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   168
Goal "(number_of v :: nat)  div  number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   169
\         (if neg (number_of v) then #0 \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   170
\          else nat (number_of v div number_of v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   171
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   172
    (simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, neg_nat, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   173
				  div_nat_eq_nat_zdiv, nat_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   174
qed "div_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   175
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   176
Addsimps [div_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   177
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   178
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   179
(** Remainder **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   180
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   181
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   182
Goal "[| (#0::int) <= z;  #0 <= z' |] ==> nat z mod nat z' = nat (z mod z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   183
by (zdiv_undefined_case_tac "z' = #0" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   184
 by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_MOD]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   185
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   186
by (rename_tac "m m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   187
by (subgoal_tac "#0 <= int m mod int m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   188
 by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, numeral_0_eq_0, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   189
				       pos_mod_sign]) 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   190
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   191
by (Asm_simp_tac 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   192
by (rtac sym 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   193
by (res_inst_tac [("q", "int (m div m')")] quorem_mod 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   194
 by (Force_tac 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   195
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, quorem_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   196
				      numeral_0_eq_0, zadd_int, zmult_int, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   197
				      mod_less_divisor]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   198
by (rtac (mod_div_equality RS sym RS trans) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   199
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   200
qed "mod_nat_eq_nat_zmod";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   201
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   202
Goal "(number_of v :: nat)  mod  number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   203
\       (if neg (number_of v) then #0 \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   204
\        else if neg (number_of v') then number_of v \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   205
\        else nat (number_of v mod number_of v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   206
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   207
    (simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   208
				  neg_nat, nat_0, DIVISION_BY_ZERO_MOD,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   209
				  mod_nat_eq_nat_zmod]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   210
qed "mod_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   211
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   212
Addsimps [mod_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   213
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   214
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   215
(*** Comparisons ***)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   216
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   217
(** Equals (=) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   218
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   219
Goal "[| (#0::int) <= z;  #0 <= z' |] ==> (nat z = nat z') = (z=z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   220
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   221
qed "eq_nat_nat_iff";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   222
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   223
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   224
Goal "((number_of v :: nat) = number_of v') = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   225
\        (if neg (number_of v) then ((#0::nat) = number_of v') \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   226
\         else if neg (number_of v') then iszero (number_of v) \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   227
\         else iszero (number_of (bin_add v (bin_minus v'))))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   228
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   229
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   230
				  eq_nat_nat_iff, eq_number_of_eq, nat_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   231
by (simp_tac (simpset_of Int.thy addsimps [nat_eq_iff, iszero_def]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   232
qed "eq_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   233
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   234
Addsimps [eq_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   235
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   236
(** Less-than (<) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   237
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   238
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   239
Goal "((number_of v :: nat) < number_of v') = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   240
\        (if neg (number_of v) then neg (number_of (bin_minus v')) \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   241
\         else neg (number_of (bin_add v (bin_minus v'))))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   242
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   243
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   244
				  nat_less_eq_zless, less_number_of_eq_neg,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   245
				  nat_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   246
by (simp_tac (simpset_of Int.thy addsimps [neg_eq_less_int0, zminus_zless, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   247
				    number_of_minus, zless_zero_nat]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   248
qed "less_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   249
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   250
Addsimps [less_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   251
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   252
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   253
(** Less-than-or-equals (<=) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   254
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   255
Goal "(number_of x <= (number_of y::nat)) = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   256
\     (~ number_of y < (number_of x::nat))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   257
by (rtac (linorder_not_less RS sym) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   258
qed "le_nat_number_of_eq_not_less"; 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   259
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   260
Addsimps [le_nat_number_of_eq_not_less];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   261
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   262
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   263
(*** New versions of existing theorems involving 0, 1, 2 ***)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   264
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   265
fun change_theory thy th = 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   266
    [th, read_instantiate_sg (sign_of thy) [("t","dummyVar")] refl] 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   267
    MRS (conjI RS conjunct1) |> standard;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   268
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   269
(*Maps n to #n for n = 0, 1, 2*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   270
val numeral_sym_ss = 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   271
    HOL_ss addsimps [numeral_0_eq_0 RS sym, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   272
		     numeral_1_eq_1 RS sym, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   273
		     numeral_2_eq_2 RS sym,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   274
		     Suc_numeral_1_eq_2, Suc_numeral_0_eq_1];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   275
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   276
fun rename_numerals thy th = simplify numeral_sym_ss (change_theory thy th);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   277
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   278
(*Maps #n to n for n = 0, 1, 2*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   279
val numeral_ss = 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   280
    simpset() addsimps [numeral_0_eq_0, numeral_1_eq_1, numeral_2_eq_2];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   281
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   282
(** Nat **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   283
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   284
Goal "#0 < n ==> n = Suc(n - #1)";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   285
by (asm_full_simp_tac numeral_ss 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   286
qed "Suc_pred'";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   287
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   288
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   289
fun inst x t = read_instantiate_sg (sign_of NatBin.thy) [(x,t)];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   290
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   291
(*Expresses a natural number constant as the Suc of another one.
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   292
  NOT suitable for rewriting because n recurs in the condition.*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   293
bind_thm ("expand_Suc", inst "n" "number_of ?v" Suc_pred');
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   294
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   295
(** NatDef & Nat **)
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   296
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   297
Addsimps (map (rename_numerals thy) 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   298
	  [min_0L, min_0R, max_0L, max_0R]);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   299
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   300
AddIffs (map (rename_numerals thy) 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   301
	 [Suc_not_Zero, Zero_not_Suc, zero_less_Suc, not_less0, less_one, 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   302
	  le0, le_0_eq, 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   303
	  neq0_conv, zero_neq_conv, not_gr0]);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   304
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   305
(** Arith **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   306
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   307
Addsimps (map (rename_numerals thy) 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   308
	  [diff_0_eq_0, add_0, add_0_right, add_pred, 
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   309
	   diff_is_0_eq, zero_is_diff_eq, zero_less_diff,
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   310
	   mult_0, mult_0_right, mult_1, mult_1_right, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   311
	   mult_is_0, zero_less_mult_iff,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   312
	   mult_eq_1_iff]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   313
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   314
AddIffs (map (rename_numerals thy) [add_is_0, zero_is_add, add_gr_0]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   315
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   316
Goal "Suc n = n + #1";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   317
by (asm_simp_tac numeral_ss 1);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   318
qed "Suc_eq_add_numeral_1";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   319
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   320
(* These two can be useful when m = number_of... *)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   321
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   322
Goal "(m::nat) + n = (if m=#0 then n else Suc ((m - #1) + n))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   323
by (exhaust_tac "m" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   324
by (ALLGOALS (asm_simp_tac numeral_ss));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   325
qed "add_eq_if";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   326
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   327
Goal "(m::nat) * n = (if m=#0 then #0 else n + ((m - #1) * n))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   328
by (exhaust_tac "m" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   329
by (ALLGOALS (asm_simp_tac numeral_ss));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   330
qed "mult_eq_if";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   331
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   332
Goal "(p ^ m :: nat) = (if m=#0 then #1 else p * (p ^ (m - #1)))";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   333
by (exhaust_tac "m" 1);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   334
by (ALLGOALS (asm_simp_tac numeral_ss));
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   335
qed "power_eq_if";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   336
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   337
Goal "[| #0<n; #0<m |] ==> m - n < (m::nat)";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   338
by (asm_full_simp_tac (numeral_ss addsimps [diff_less]) 1);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   339
qed "diff_less'";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   340
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   341
Addsimps [inst "n" "number_of ?v" diff_less'];
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   342
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   343
(*various theorems that aren't in the default simpset*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   344
val add_is_one' = rename_numerals thy add_is_1;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   345
val one_is_add' = rename_numerals thy one_is_add;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   346
val zero_induct' = rename_numerals thy zero_induct;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   347
val diff_self_eq_0' = rename_numerals thy diff_self_eq_0;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   348
val mult_eq_self_implies_10' = rename_numerals thy mult_eq_self_implies_10;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   349
val le_pred_eq' = rename_numerals thy le_pred_eq;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   350
val less_pred_eq' = rename_numerals thy less_pred_eq;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   351
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   352
(** Divides **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   353
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   354
Addsimps (map (rename_numerals thy) 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   355
	  [mod_1, mod_0, div_1, div_0, mod2_gr_0, mod2_add_self_eq_0,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   356
	   mod2_add_self]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   357
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   358
AddIffs (map (rename_numerals thy) 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   359
	  [dvd_1_left, dvd_0_right]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   360
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   361
(*useful?*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   362
val mod_self' = rename_numerals thy mod_self;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   363
val div_self' = rename_numerals thy div_self;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   364
val div_less' = rename_numerals thy div_less;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   365
val mod_mult_self_is_zero' = rename_numerals thy mod_mult_self_is_0;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   366
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   367
(** Power **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   368
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   369
Goal "(p::nat) ^ #0 = #1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   370
by (simp_tac numeral_ss 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   371
qed "power_zero";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   372
Addsimps [power_zero];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   373
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   374
val binomial_zero = rename_numerals thy binomial_0;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   375
val binomial_Suc' = rename_numerals thy binomial_Suc;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   376
val binomial_n_n' = rename_numerals thy binomial_n_n;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   377
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   378
(*binomial_0_Suc doesn't work well on numerals*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   379
Addsimps (map (rename_numerals thy) 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   380
	  [binomial_n_0, binomial_zero, binomial_1]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   381