src/HOL/Integ/NatBin.ML
author paulson
Tue, 23 May 2000 18:06:22 +0200
changeset 8935 548901d05a0e
parent 8864 a12ccd629e2c
child 9064 eacebbcafe57
permissions -rw-r--r--
added type constraint ::nat because 0 is now overloaded
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
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
    18
Goal "#0 = (0::nat)";
7032
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
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
    22
Goal "#1 = (1::nat)";
7032
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
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
    26
Goal "#2 = (2::nat)";
7032
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
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
    30
bind_thm ("zero_eq_numeral_0", numeral_0_eq_0 RS sym);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    31
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    32
(** int (coercion from nat to int) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    33
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    34
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    35
Goal "int (number_of v :: nat) = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    36
\        (if neg (number_of v) then #0 \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    37
\         else (number_of v :: int))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    38
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    39
    (simpset_of Int.thy addsimps [neg_nat, nat_number_of_def, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    40
				  not_neg_nat, int_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    41
qed "int_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    42
Addsimps [int_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    43
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    44
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    45
(** Successor **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    46
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    47
Goal "(#0::int) <= z ==> Suc (nat z) = nat (#1 + z)";
7086
f9aa63a5a8b6 expandshort
paulson
parents: 7075
diff changeset
    48
by (rtac sym 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    49
by (asm_simp_tac (simpset() addsimps [nat_eq_iff]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    50
qed "Suc_nat_eq_nat_zadd1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    51
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    52
Goal "Suc (number_of v) = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    53
\       (if neg (number_of v) then #1 else number_of (bin_succ v))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    54
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    55
    (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
    56
				  nat_number_of_def, int_Suc, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    57
				  Suc_nat_eq_nat_zadd1, number_of_succ]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    58
qed "Suc_nat_number_of";
8737
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    59
Addsimps [Suc_nat_number_of];
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    60
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    61
Goal "Suc (number_of v + n) = \
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    62
\       (if neg (number_of v) then #1+n else number_of (bin_succ v) + n)";
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    63
by (Simp_tac 1);
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    64
qed "Suc_nat_number_of_add";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    65
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    66
Goal "Suc #0 = #1";
8737
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    67
by (Simp_tac 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    68
qed "Suc_numeral_0_eq_1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    69
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    70
Goal "Suc #1 = #2";
8737
f9733879ff25 instantiates new simprocs for numerals of type "nat"
paulson
parents: 8698
diff changeset
    71
by (Simp_tac 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    72
qed "Suc_numeral_1_eq_2";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    73
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    74
(** Addition **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    75
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
    76
Goal "[| (#0::int) <= z;  #0 <= z' |] ==> nat (z+z') = nat z + nat z'";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    77
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    78
by (asm_simp_tac (simpset() addsimps [zadd_int RS sym]) 1);
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
    79
qed "nat_add_distrib";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    80
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    81
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    82
Goal "(number_of v :: nat) + number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    83
\        (if neg (number_of v) then number_of v' \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    84
\         else if neg (number_of v') then number_of v \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    85
\         else number_of (bin_add v v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    86
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    87
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
    88
				  nat_add_distrib RS sym, number_of_add]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    89
qed "add_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    90
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    91
Addsimps [add_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    92
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    93
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    94
(** Subtraction **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    95
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
    96
Goal "[| (#0::int) <= z';  z' <= z |] ==> nat (z-z') = nat z - nat z'";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    97
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
    98
by (asm_simp_tac (simpset() addsimps [zdiff_int RS sym, nat_le_eq_zle]) 1);
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
    99
qed "nat_diff_distrib";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   100
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   101
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   102
Goal "nat z - nat z' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   103
\       (if neg z' then nat z  \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   104
\        else let d = z-z' in    \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   105
\             if neg d then 0 else nat d)";
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   106
by (simp_tac (simpset() addsimps [Let_def, nat_diff_distrib RS sym,
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   107
				  neg_eq_less_0, not_neg_eq_ge_0]) 1);
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   108
by (simp_tac (simpset() addsimps [diff_is_0_eq, nat_le_eq_zle]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   109
qed "diff_nat_eq_if";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   110
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   111
Goalw [nat_number_of_def]
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   112
     "(number_of v :: nat) - number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   113
\       (if neg (number_of v') then number_of v \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   114
\        else let d = number_of (bin_add v (bin_minus v')) in    \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   115
\             if neg d then #0 else nat d)";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   116
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   117
    (simpset_of Int.thy delcongs [if_weak_cong]
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   118
			addsimps [not_neg_eq_ge_0, nat_0,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   119
				  diff_nat_eq_if, diff_number_of_eq]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   120
qed "diff_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   121
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   122
Addsimps [diff_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   123
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   124
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   125
(** Multiplication **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   126
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   127
Goal "(#0::int) <= z ==> nat (z*z') = nat z * nat z'";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   128
by (case_tac "#0 <= z'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   129
by (subgoal_tac "z'*z <= #0" 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   130
by (rtac (neg_imp_zmult_nonpos_iff RS iffD2) 3);
7075
5ba8d1e42ca6 zmult_ac are no longer included by default
paulson
parents: 7056
diff changeset
   131
by (auto_tac (claset(),
5ba8d1e42ca6 zmult_ac are no longer included by default
paulson
parents: 7056
diff changeset
   132
	      simpset() addsimps [zmult_commute]));
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   133
by (subgoal_tac "#0 <= z*z'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   134
by (force_tac (claset() addDs [zmult_zle_mono1], simpset()) 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   135
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   136
by (asm_simp_tac (simpset() addsimps [zmult_int RS sym]) 1);
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   137
qed "nat_mult_distrib";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   138
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   139
Goal "(number_of v :: nat) * number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   140
\      (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
   141
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   142
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   143
				  nat_mult_distrib RS sym, number_of_mult, 
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   144
				  nat_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   145
qed "mult_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   146
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   147
Addsimps [mult_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   148
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   149
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   150
(** Quotient **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   151
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   152
Goal "(#0::int) <= z ==> nat (z div z') = nat z div nat z'";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   153
by (case_tac "#0 <= z'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   154
by (auto_tac (claset(), 
7127
48e235179ffb added parentheses to cope with a possible reduction of the precedence of unary
paulson
parents: 7086
diff changeset
   155
	      simpset() addsimps [div_nonneg_neg_le0, DIVISION_BY_ZERO_DIV]));
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   156
by (zdiv_undefined_case_tac "z' = #0" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   157
 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
   158
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   159
by (rename_tac "m m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   160
by (subgoal_tac "#0 <= int m div int m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   161
 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
   162
				       pos_imp_zdiv_nonneg_iff]) 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   163
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   164
by (Asm_simp_tac 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   165
by (res_inst_tac [("r", "int (m mod m')")] quorem_div 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   166
 by (Force_tac 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   167
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, quorem_def, 
8698
8812dad6ef12 made mod_less_divisor a simplification rule.
nipkow
parents: 8552
diff changeset
   168
				      numeral_0_eq_0, zadd_int, zmult_int]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   169
by (rtac (mod_div_equality RS sym RS trans) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   170
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1);
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   171
qed "nat_div_distrib";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   172
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   173
Goal "(number_of v :: nat)  div  number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   174
\         (if neg (number_of v) then #0 \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   175
\          else nat (number_of v div number_of v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   176
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   177
    (simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, neg_nat, 
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   178
				  nat_div_distrib RS sym, nat_0]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   179
qed "div_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   180
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   181
Addsimps [div_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   182
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   183
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   184
(** Remainder **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   185
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   186
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*)
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   187
Goal "[| (#0::int) <= z;  #0 <= z' |] ==> nat (z mod z') = nat z mod nat z'";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   188
by (zdiv_undefined_case_tac "z' = #0" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   189
 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
   190
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   191
by (rename_tac "m m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   192
by (subgoal_tac "#0 <= int m mod int m'" 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   193
 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
   194
				       pos_mod_sign]) 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   195
by (rtac (inj_int RS injD) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   196
by (Asm_simp_tac 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   197
by (res_inst_tac [("q", "int (m div m')")] quorem_mod 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   198
 by (Force_tac 2);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   199
by (asm_simp_tac (simpset() addsimps [nat_less_iff RS sym, quorem_def, 
8698
8812dad6ef12 made mod_less_divisor a simplification rule.
nipkow
parents: 8552
diff changeset
   200
				      numeral_0_eq_0, zadd_int, zmult_int]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   201
by (rtac (mod_div_equality RS sym RS trans) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   202
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1);
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   203
qed "nat_mod_distrib";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   204
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   205
Goal "(number_of v :: nat)  mod  number_of v' = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   206
\       (if neg (number_of v) then #0 \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   207
\        else if neg (number_of v') then number_of v \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   208
\        else nat (number_of v mod number_of v'))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   209
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   210
    (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
   211
				  neg_nat, nat_0, DIVISION_BY_ZERO_MOD,
8028
5357e8eb09c8 tidied, choosing nicer names
paulson
parents: 7625
diff changeset
   212
				  nat_mod_distrib RS sym]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   213
qed "mod_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   214
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   215
Addsimps [mod_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   216
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   217
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   218
(*** Comparisons ***)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   219
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   220
(** Equals (=) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   221
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   222
Goal "[| (#0::int) <= z;  #0 <= z' |] ==> (nat z = nat z') = (z=z')";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   223
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   224
qed "eq_nat_nat_iff";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   225
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   226
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   227
Goal "((number_of v :: nat) = number_of v') = \
8795
3b10d24b5edd a safer way of proving literal equalities
paulson
parents: 8792
diff changeset
   228
\     (if neg (number_of v) then (iszero (number_of v') | neg (number_of v')) \
3b10d24b5edd a safer way of proving literal equalities
paulson
parents: 8792
diff changeset
   229
\      else if neg (number_of v') then iszero (number_of v) \
3b10d24b5edd a safer way of proving literal equalities
paulson
parents: 8792
diff changeset
   230
\      else iszero (number_of (bin_add v (bin_minus v'))))";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   231
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   232
    (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
   233
				  eq_nat_nat_iff, eq_number_of_eq, nat_0]) 1);
8795
3b10d24b5edd a safer way of proving literal equalities
paulson
parents: 8792
diff changeset
   234
by (simp_tac (simpset_of Int.thy addsimps [nat_eq_iff, nat_eq_iff2, 
3b10d24b5edd a safer way of proving literal equalities
paulson
parents: 8792
diff changeset
   235
					   iszero_def]) 1);
3b10d24b5edd a safer way of proving literal equalities
paulson
parents: 8792
diff changeset
   236
by (simp_tac (simpset_of Int.thy addsimps [not_neg_eq_ge_0 RS sym]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   237
qed "eq_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   238
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   239
Addsimps [eq_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   240
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   241
(** Less-than (<) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   242
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   243
(*"neg" is used in rewrite rules for binary comparisons*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   244
Goal "((number_of v :: nat) < number_of v') = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   245
\        (if neg (number_of v) then neg (number_of (bin_minus v')) \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   246
\         else neg (number_of (bin_add v (bin_minus v'))))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   247
by (simp_tac
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   248
    (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
   249
				  nat_less_eq_zless, less_number_of_eq_neg,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   250
				  nat_0]) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   251
by (simp_tac (simpset_of Int.thy addsimps [neg_eq_less_int0, zminus_zless, 
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   252
				number_of_minus, zless_nat_eq_int_zless]) 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   253
qed "less_nat_number_of";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   254
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   255
Addsimps [less_nat_number_of];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   256
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   257
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   258
(** Less-than-or-equals (<=) **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   259
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   260
Goal "(number_of x <= (number_of y::nat)) = \
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   261
\     (~ number_of y < (number_of x::nat))";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   262
by (rtac (linorder_not_less RS sym) 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   263
qed "le_nat_number_of_eq_not_less"; 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   264
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   265
Addsimps [le_nat_number_of_eq_not_less];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   266
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   267
(*** New versions of existing theorems involving 0, 1, 2 ***)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   268
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   269
fun change_theory thy th = 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   270
    [th, read_instantiate_sg (sign_of thy) [("t","dummyVar")] refl] 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   271
    MRS (conjI RS conjunct1) |> standard;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   272
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   273
(*Maps n to #n for n = 0, 1, 2*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   274
val numeral_sym_ss = 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   275
    HOL_ss addsimps [numeral_0_eq_0 RS sym, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   276
		     numeral_1_eq_1 RS sym, 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   277
		     numeral_2_eq_2 RS sym,
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   278
		     Suc_numeral_1_eq_2, Suc_numeral_0_eq_1];
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   279
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   280
fun rename_numerals thy th = simplify numeral_sym_ss (change_theory thy th);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   281
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   282
(*Maps #n to n for n = 0, 1, 2*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   283
val numeral_ss = 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   284
    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
   285
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   286
(** Nat **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   287
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   288
Goal "#0 < n ==> n = Suc(n - #1)";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   289
by (asm_full_simp_tac numeral_ss 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   290
qed "Suc_pred'";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   291
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   292
(*Expresses a natural number constant as the Suc of another one.
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   293
  NOT suitable for rewriting because n recurs in the condition.*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   294
bind_thm ("expand_Suc", inst "n" "number_of ?v" Suc_pred');
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   295
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   296
(** NatDef & Nat **)
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   297
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   298
Addsimps (map (rename_numerals thy) 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   299
	  [min_0L, min_0R, max_0L, max_0R]);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   300
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   301
AddIffs (map (rename_numerals thy) 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   302
	 [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
   303
	  le0, le_0_eq, 
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   304
	  neq0_conv, zero_neq_conv, not_gr0]);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   305
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   306
(** Arith **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   307
8776
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   308
(*Identity laws for + - * *)	 
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   309
val basic_renamed_arith_simps =
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   310
    map (rename_numerals thy) 
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   311
        [diff_0, diff_0_eq_0, add_0, add_0_right, 
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   312
	 mult_0, mult_0_right, mult_1, mult_1_right];
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   313
	 
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   314
(*Non-trivial simplifications*)	 
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   315
val other_renamed_arith_simps =
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   316
    map (rename_numerals thy) 
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   317
	[add_pred, diff_is_0_eq, zero_is_diff_eq, zero_less_diff,
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   318
	 mult_is_0, zero_is_mult, zero_less_mult_iff, mult_eq_1_iff];
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   319
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   320
Addsimps (basic_renamed_arith_simps @ other_renamed_arith_simps);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   321
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   322
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
   323
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   324
Goal "Suc n = n + #1";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   325
by (asm_simp_tac numeral_ss 1);
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   326
qed "Suc_eq_add_numeral_1";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   327
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   328
(* These two can be useful when m = number_of... *)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   329
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   330
Goal "(m::nat) + n = (if m=#0 then n else Suc ((m - #1) + n))";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   331
by (case_tac "m" 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   332
by (ALLGOALS (asm_simp_tac numeral_ss));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   333
qed "add_eq_if";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   334
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   335
Goal "(m::nat) * n = (if m=#0 then #0 else n + ((m - #1) * n))";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   336
by (case_tac "m" 1);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   337
by (ALLGOALS (asm_simp_tac numeral_ss));
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   338
qed "mult_eq_if";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   339
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   340
Goal "(p ^ m :: nat) = (if m=#0 then #1 else p * (p ^ (m - #1)))";
8442
96023903c2df case_tac now subsumes both boolean and datatype cases;
wenzelm
parents: 8423
diff changeset
   341
by (case_tac "m" 1);
7056
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   342
by (ALLGOALS (asm_simp_tac numeral_ss));
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   343
qed "power_eq_if";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   344
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   345
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
   346
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
   347
qed "diff_less'";
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   348
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   349
Addsimps [inst "n" "number_of ?v" diff_less'];
522a7013d7df more existing theorems renamed to use #0; also new results
paulson
parents: 7032
diff changeset
   350
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   351
(*various theorems that aren't in the default simpset*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   352
val add_is_one' = rename_numerals thy add_is_1;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   353
val one_is_add' = rename_numerals thy one_is_add;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   354
val zero_induct' = rename_numerals thy zero_induct;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   355
val diff_self_eq_0' = rename_numerals thy diff_self_eq_0;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   356
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
   357
val le_pred_eq' = rename_numerals thy le_pred_eq;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   358
val less_pred_eq' = rename_numerals thy less_pred_eq;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   359
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   360
(** Divides **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   361
8776
60821dbc9f18 now with combine_numerals
paulson
parents: 8758
diff changeset
   362
Addsimps (map (rename_numerals thy) [mod_1, mod_0, div_1, div_0]);
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   363
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   364
AddIffs (map (rename_numerals thy) 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   365
	  [dvd_1_left, dvd_0_right]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   366
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   367
(*useful?*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   368
val mod_self' = rename_numerals thy mod_self;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   369
val div_self' = rename_numerals thy div_self;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   370
val div_less' = rename_numerals thy div_less;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   371
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
   372
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   373
(** Power **)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   374
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   375
Goal "(p::nat) ^ #0 = #1";
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   376
by (simp_tac numeral_ss 1);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   377
qed "power_zero";
8792
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   378
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   379
Goal "(p::nat) ^ #1 = p";
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   380
by (simp_tac numeral_ss 1);
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   381
qed "power_one";
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   382
Addsimps [power_zero, power_one];
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   383
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   384
Goal "(p::nat) ^ #2 = p*p";
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   385
by (simp_tac numeral_ss 1);
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   386
qed "power_two";
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   387
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   388
Goal "#0 < (i::nat) ==> #0 < i^n";
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   389
by (asm_simp_tac numeral_ss 1);
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   390
qed "zero_less_power'";
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   391
Addsimps [zero_less_power'];
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   392
7032
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   393
val binomial_zero = rename_numerals thy binomial_0;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   394
val binomial_Suc' = rename_numerals thy binomial_Suc;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   395
val binomial_n_n' = rename_numerals thy binomial_n_n;
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   396
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   397
(*binomial_0_Suc doesn't work well on numerals*)
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   398
Addsimps (map (rename_numerals thy) 
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   399
	  [binomial_n_0, binomial_zero, binomial_1]);
d6efb3b8e669 NatBin: binary arithmetic for the naturals
paulson
parents:
diff changeset
   400
8792
59a4b5e6a591 new lemmas concerning powers and #mmm
paulson
parents: 8776
diff changeset
   401
Addsimps [rename_numerals thy card_Pow];
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   402
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
   403
(*** Comparisons involving (0::nat) ***)
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   404
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
   405
Goal "(number_of v = (0::nat)) = \
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   406
\     (if neg (number_of v) then True else iszero (number_of v))";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   407
by (simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym]) 1);
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   408
qed "eq_number_of_0";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   409
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
   410
Goal "((0::nat) = number_of v) = \
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   411
\     (if neg (number_of v) then True else iszero (number_of v))";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   412
by (rtac ([eq_sym_conv, eq_number_of_0] MRS trans) 1);
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   413
qed "eq_0_number_of";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   414
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
   415
Goal "((0::nat) < number_of v) = neg (number_of (bin_minus v))";
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   416
by (simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym]) 1);
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   417
qed "less_0_number_of";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   418
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   419
(*Simplification already handles n<0, n<=0 and 0<=n.*)
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   420
Addsimps [eq_number_of_0, eq_0_number_of, less_0_number_of];
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   421
8935
548901d05a0e added type constraint ::nat because 0 is now overloaded
paulson
parents: 8864
diff changeset
   422
Goal "neg (number_of v) ==> number_of v = (0::nat)";
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   423
by (asm_simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym]) 1);
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   424
qed "neg_imp_number_of_eq_0";
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   425
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   426
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   427
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   428
(*** Comparisons involving Suc ***)
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   429
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   430
Goal "(number_of v = Suc n) = \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   431
\       (let pv = number_of (bin_pred v) in \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   432
\        if neg pv then False else nat pv = n)";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   433
by (simp_tac
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   434
    (simpset_of Int.thy addsimps
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   435
      [Let_def, neg_eq_less_0, linorder_not_less, number_of_pred,
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   436
       nat_number_of_def, zadd_0] @ zadd_ac) 1);
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   437
by (res_inst_tac [("x", "number_of v")] spec 1);
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   438
by (auto_tac (claset(), simpset() addsimps [nat_eq_iff]));
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   439
qed "eq_number_of_Suc";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   440
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   441
Goal "(Suc n = number_of v) = \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   442
\       (let pv = number_of (bin_pred v) in \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   443
\        if neg pv then False else nat pv = n)";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   444
by (rtac ([eq_sym_conv, eq_number_of_Suc] MRS trans) 1);
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   445
qed "Suc_eq_number_of";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   446
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   447
Goal "(number_of v < Suc n) = \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   448
\       (let pv = number_of (bin_pred v) in \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   449
\        if neg pv then True else nat pv < n)";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   450
by (simp_tac
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   451
    (simpset_of Int.thy addsimps
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   452
      [Let_def, neg_eq_less_0, linorder_not_less, number_of_pred,
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   453
       nat_number_of_def, zadd_0] @ zadd_ac) 1);
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   454
by (res_inst_tac [("x", "number_of v")] spec 1);
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   455
by (auto_tac (claset(), simpset() addsimps [nat_less_iff]));
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   456
qed "less_number_of_Suc";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   457
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   458
Goal "(Suc n < number_of v) = \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   459
\       (let pv = number_of (bin_pred v) in \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   460
\        if neg pv then False else n < nat pv)";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   461
by (simp_tac
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   462
    (simpset_of Int.thy addsimps
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   463
      [Let_def, neg_eq_less_0, linorder_not_less, number_of_pred,
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   464
       nat_number_of_def, zadd_0] @ zadd_ac) 1);
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   465
by (res_inst_tac [("x", "number_of v")] spec 1);
8864
a12ccd629e2c tidying, especially to remove zcompare_rls from proofs
paulson
parents: 8798
diff changeset
   466
by (auto_tac (claset(), simpset() addsimps [zless_nat_eq_int_zless]));
7519
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   467
qed "less_Suc_number_of";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   468
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   469
Goal "(number_of v <= Suc n) = \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   470
\       (let pv = number_of (bin_pred v) in \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   471
\        if neg pv then True else nat pv <= n)";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   472
by (simp_tac
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   473
    (simpset_of Int.thy addsimps
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   474
      [Let_def, less_Suc_number_of, linorder_not_less RS sym]) 1);
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   475
qed "le_number_of_Suc";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   476
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   477
Goal "(Suc n <= number_of v) = \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   478
\       (let pv = number_of (bin_pred v) in \
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   479
\        if neg pv then False else n <= nat pv)";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   480
by (simp_tac
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   481
    (simpset_of Int.thy addsimps
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   482
      [Let_def, less_number_of_Suc, linorder_not_less RS sym]) 1);
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   483
qed "le_Suc_number_of";
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   484
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   485
Addsimps [eq_number_of_Suc, Suc_eq_number_of, 
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   486
	  less_number_of_Suc, less_Suc_number_of, 
8e4a21d1ba4f simplification of relations involving 0, Suc and natural-number numerals
paulson
parents: 7127
diff changeset
   487
	  le_number_of_Suc, le_Suc_number_of];
8116
759f712f8f06 int:nat->int is pushed inwards.
nipkow
parents: 8028
diff changeset
   488
8257
fe9bf28e8a58 installed lin arith for nat numerals.
nipkow
parents: 8116
diff changeset
   489
(* Push int(.) inwards: *)
8116
759f712f8f06 int:nat->int is pushed inwards.
nipkow
parents: 8028
diff changeset
   490
Addsimps [int_Suc,zadd_int RS sym];
8798
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   491
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   492
Goal "(m+m = n+n) = (m = (n::int))";
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   493
by Auto_tac;
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   494
val lemma1 = result();
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   495
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   496
Goal "m+m ~= int 1 + n + n";
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   497
by Auto_tac;
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   498
by (dres_inst_tac [("f", "%x. x mod #2")] arg_cong 1);
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   499
by (full_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   500
val lemma2 = result();
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   501
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   502
Goal "((number_of (v BIT x) ::int) = number_of (w BIT y)) = \
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   503
\     (x=y & (((number_of v) ::int) = number_of w))"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   504
by (simp_tac (simpset_of Int.thy addsimps
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   505
	       [number_of_BIT, lemma1, lemma2, eq_commute]) 1); 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   506
qed "eq_number_of_BIT_BIT"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   507
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   508
Goal "((number_of (v BIT x) ::int) = number_of Pls) = \
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   509
\     (x=False & (((number_of v) ::int) = number_of Pls))"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   510
by (simp_tac (simpset_of Int.thy addsimps
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   511
	       [number_of_BIT, number_of_Pls, eq_commute]) 1); 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   512
by (res_inst_tac [("x", "number_of v")] spec 1);
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   513
by Safe_tac;
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   514
by (ALLGOALS Full_simp_tac);
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   515
by (dres_inst_tac [("f", "%x. x mod #2")] arg_cong 1);
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   516
by (full_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   517
qed "eq_number_of_BIT_Pls"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   518
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   519
Goal "((number_of (v BIT x) ::int) = number_of Min) = \
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   520
\     (x=True & (((number_of v) ::int) = number_of Min))"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   521
by (simp_tac (simpset_of Int.thy addsimps
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   522
	       [number_of_BIT, number_of_Min, eq_commute]) 1); 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   523
by (res_inst_tac [("x", "number_of v")] spec 1);
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   524
by Auto_tac;
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   525
by (dres_inst_tac [("f", "%x. x mod #2")] arg_cong 1);
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   526
by Auto_tac;
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   527
qed "eq_number_of_BIT_Min"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   528
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   529
Goal "(number_of Pls ::int) ~= number_of Min"; 
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   530
by Auto_tac;
d289a68e74ea new lemmas about binary division
paulson
parents: 8795
diff changeset
   531
qed "eq_number_of_Pls_Min";