src/HOL/Integ/nat_bin.ML
author kleing
Tue, 13 May 2003 08:59:21 +0200
changeset 14024 213dcc39358f
parent 13837 8dd150d36c65
child 14251 b91f632a1d37
permissions -rw-r--r--
HOL-Real -> HOL-Complex
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/nat_bin.ML
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     4
    Copyright   1999  University of Cambridge
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     5
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     6
Binary arithmetic for the natural numbers
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     7
*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     8
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
     9
val nat_number_of_def = thm "nat_number_of_def";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    10
13837
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    11
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    12
(** nat (coercion from int to nat) **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    13
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    14
Goal "nat (number_of w) = number_of w";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    15
by (simp_tac (simpset() addsimps [nat_number_of_def]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    16
qed "nat_number_of";
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    17
Addsimps [nat_number_of, nat_0, nat_1];
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    18
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11464
diff changeset
    19
Goal "Numeral0 = (0::nat)";
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    20
by (simp_tac (simpset() addsimps [nat_number_of_def]) 1); 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    21
qed "numeral_0_eq_0";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    22
11701
3d51fbf81c17 sane numerals (stage 1): added generic 1, removed 1' and 2 on nat,
wenzelm
parents: 11464
diff changeset
    23
Goal "Numeral1 = (1::nat)";
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    24
by (simp_tac (simpset() addsimps [nat_1, nat_number_of_def]) 1); 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    25
qed "numeral_1_eq_1";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    26
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    27
Goal "Numeral1 = Suc 0";
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    28
by (simp_tac (simpset() addsimps [numeral_1_eq_1]) 1); 
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    29
qed "numeral_1_eq_Suc_0";
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    30
12196
a3be6b3a9c0b new theories from Jacques Fleuriot
paulson
parents: 11868
diff changeset
    31
Goalw [nat_number_of_def] "2 = Suc (Suc 0)";
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    32
by (rtac nat_2 1); 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    33
qed "numeral_2_eq_2";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    34
13837
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    35
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    36
(** Distributive laws for "nat".  The others are in IntArith.ML, but these
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    37
    require div and mod to be defined for type "int".  They also need 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    38
    some of the lemmas proved just above.**)
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    39
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    40
Goal "(0::int) <= z ==> nat (z div z') = nat z div nat z'";
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    41
by (case_tac "0 <= z'" 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    42
by (auto_tac (claset(), 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    43
	      simpset() addsimps [div_nonneg_neg_le0, DIVISION_BY_ZERO_DIV]));
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    44
by (case_tac "z' = 0" 1 THEN asm_simp_tac (simpset() addsimps [DIVISION_BY_ZERO]) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    45
 by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_DIV]) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    46
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    47
by (rename_tac "m m'" 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    48
by (subgoal_tac "0 <= int m div int m'" 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    49
 by (asm_full_simp_tac 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    50
     (simpset() addsimps [numeral_0_eq_0, pos_imp_zdiv_nonneg_iff]) 2);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    51
by (rtac (inj_int RS injD) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    52
by (Asm_simp_tac 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    53
by (res_inst_tac [("r", "int (m mod m')")] quorem_div 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    54
 by (Force_tac 2);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    55
by (asm_full_simp_tac 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    56
    (simpset() addsimps [nat_less_iff RS sym, quorem_def, 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    57
	                 numeral_0_eq_0, zadd_int, zmult_int]) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    58
qed "nat_div_distrib";
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    59
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    60
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*)
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    61
Goal "[| (0::int) <= z;  0 <= z' |] ==> nat (z mod z') = nat z mod nat z'";
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    62
by (case_tac "z' = 0" 1 THEN asm_simp_tac (simpset() addsimps [DIVISION_BY_ZERO]) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    63
 by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_MOD]) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    64
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    65
by (rename_tac "m m'" 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    66
by (subgoal_tac "0 <= int m mod int m'" 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    67
 by (asm_full_simp_tac 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    68
     (simpset() addsimps [nat_less_iff, numeral_0_eq_0, pos_mod_sign]) 2);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    69
by (rtac (inj_int RS injD) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    70
by (Asm_simp_tac 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    71
by (res_inst_tac [("q", "int (m div m')")] quorem_mod 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    72
 by (Force_tac 2);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    73
by (asm_full_simp_tac 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    74
     (simpset() addsimps [nat_less_iff RS sym, quorem_def, 
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    75
		          numeral_0_eq_0, zadd_int, zmult_int]) 1);
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    76
qed "nat_mod_distrib";
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    77
8dd150d36c65 Reorganized, moving many results about the integer dvd relation from IntPrimes
paulson
parents: 13517
diff changeset
    78
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    79
(** int (coercion from nat to int) **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    80
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    81
(*"neg" is used in rewrite rules for binary comparisons*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    82
Goal "int (number_of v :: nat) = \
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    83
\        (if neg (number_of v) then 0 \
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    84
\         else (number_of v :: int))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    85
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    86
    (simpset_of Int.thy addsimps [neg_nat, nat_number_of_def, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    87
				  not_neg_nat, int_0]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    88
qed "int_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    89
Addsimps [int_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    90
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    91
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    92
(** Successor **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    93
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    94
Goal "(0::int) <= z ==> Suc (nat z) = nat (1 + z)";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    95
by (rtac sym 1);
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    96
by (asm_simp_tac (simpset() addsimps [nat_eq_iff, int_Suc]) 1);
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    97
qed "Suc_nat_eq_nat_zadd1";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
    98
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
    99
Goal "Suc (number_of v + n) = \
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   100
\       (if neg (number_of v) then 1+n else number_of (bin_succ v) + n)";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   101
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   102
    (simpset_of Int.thy addsimps [neg_nat, nat_1, not_neg_eq_ge_0, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   103
				  nat_number_of_def, int_Suc, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   104
				  Suc_nat_eq_nat_zadd1, number_of_succ]) 1);
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   105
qed "Suc_nat_number_of_add";
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   106
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   107
Goal "Suc (number_of v) = \
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   108
\       (if neg (number_of v) then 1 else number_of (bin_succ v))";
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   109
by (cut_inst_tac [("n","0")] Suc_nat_number_of_add 1);
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   110
by (asm_full_simp_tac (simpset() delcongs [if_weak_cong]) 1); 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   111
qed "Suc_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   112
Addsimps [Suc_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   113
13261
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   114
val nat_bin_arith_setup =
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   115
 [Fast_Arith.map_data 
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   116
   (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} =>
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   117
     {add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms,
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   118
      inj_thms = inj_thms,
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   119
      lessD = lessD,
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   120
      simpset = simpset addsimps [Suc_nat_number_of, int_nat_number_of,
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   121
                                  not_neg_number_of_Pls,
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   122
                                  neg_number_of_Min,neg_number_of_BIT]})];
a0460a450cf9 fixed problem with linear arith.
nipkow
parents: 13183
diff changeset
   123
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   124
(** Addition **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   125
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   126
(*"neg" is used in rewrite rules for binary comparisons*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   127
Goal "(number_of v :: nat) + number_of v' = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   128
\        (if neg (number_of v) then number_of v' \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   129
\         else if neg (number_of v') then number_of v \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   130
\         else number_of (bin_add v v'))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   131
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   132
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   133
				  nat_add_distrib RS sym, number_of_add]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   134
qed "add_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   135
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   136
Addsimps [add_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   137
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   138
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   139
(** Subtraction **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   140
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   141
Goal "nat z - nat z' = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   142
\       (if neg z' then nat z  \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   143
\        else let d = z-z' in    \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   144
\             if neg d then 0 else nat d)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   145
by (simp_tac (simpset() addsimps [Let_def, nat_diff_distrib RS sym,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   146
				  neg_eq_less_0, not_neg_eq_ge_0]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   147
by (simp_tac (simpset() addsimps [diff_is_0_eq, nat_le_eq_zle]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   148
qed "diff_nat_eq_if";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   149
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   150
Goalw [nat_number_of_def]
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   151
     "(number_of v :: nat) - number_of v' = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   152
\       (if neg (number_of v') then number_of v \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   153
\        else let d = number_of (bin_add v (bin_minus v')) in    \
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   154
\             if neg d then 0 else nat d)";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   155
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   156
    (simpset_of Int.thy delcongs [if_weak_cong]
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   157
			addsimps [not_neg_eq_ge_0, nat_0,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   158
				  diff_nat_eq_if, diff_number_of_eq]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   159
qed "diff_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   160
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   161
Addsimps [diff_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   162
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   163
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   164
(** Multiplication **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   165
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   166
Goal "(number_of v :: nat) * number_of v' = \
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   167
\      (if neg (number_of v) then 0 else number_of (bin_mult v v'))";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   168
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   169
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   170
				  nat_mult_distrib RS sym, number_of_mult, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   171
				  nat_0]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   172
qed "mult_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   173
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   174
Addsimps [mult_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   175
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   176
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   177
(** Quotient **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   178
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   179
Goal "(number_of v :: nat)  div  number_of v' = \
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   180
\         (if neg (number_of v) then 0 \
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   181
\          else nat (number_of v div number_of v'))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   182
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   183
    (simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, neg_nat, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   184
				  nat_div_distrib RS sym, nat_0]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   185
qed "div_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   186
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   187
Addsimps [div_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   188
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   189
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   190
(** Remainder **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   191
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   192
Goal "(number_of v :: nat)  mod  number_of v' = \
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   193
\       (if neg (number_of v) then 0 \
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   194
\        else if neg (number_of v') then number_of v \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   195
\        else nat (number_of v mod number_of v'))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   196
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   197
    (simpset_of Int.thy addsimps [not_neg_eq_ge_0, nat_number_of_def, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   198
				  neg_nat, nat_0, DIVISION_BY_ZERO_MOD,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   199
				  nat_mod_distrib RS sym]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   200
qed "mod_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   201
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   202
Addsimps [mod_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   203
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   204
structure NatAbstractNumeralsData =
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   205
  struct
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   206
  val dest_eq		= HOLogic.dest_eq o HOLogic.dest_Trueprop o concl_of
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   207
  val is_numeral	= Bin_Simprocs.is_numeral
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   208
  val numeral_0_eq_0    = numeral_0_eq_0
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   209
  val numeral_1_eq_1    = numeral_1_eq_Suc_0
13485
acf39e924091 tuned prove_conv (error reporting done within meta_simplifier.ML);
wenzelm
parents: 13462
diff changeset
   210
  val prove_conv        = Bin_Simprocs.prove_conv_nohyps_novars
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   211
  fun norm_tac simps	= ALLGOALS (simp_tac (HOL_ss addsimps simps))
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   212
  val simplify_meta_eq  = Bin_Simprocs.simplify_meta_eq 
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   213
  end
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   214
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   215
structure NatAbstractNumerals = AbstractNumeralsFun (NatAbstractNumeralsData)
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   216
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   217
val nat_eval_numerals = 
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   218
  map Bin_Simprocs.prep_simproc
13462
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 13261
diff changeset
   219
   [("nat_div_eval_numerals", ["(Suc 0) div m"], NatAbstractNumerals.proc div_nat_number_of),
56610e2ba220 sane interface for simprocs;
wenzelm
parents: 13261
diff changeset
   220
    ("nat_mod_eval_numerals", ["(Suc 0) mod m"], NatAbstractNumerals.proc mod_nat_number_of)];
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   221
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   222
Addsimprocs nat_eval_numerals;
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   223
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   224
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   225
(*** Comparisons ***)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   226
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   227
(** Equals (=) **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   228
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   229
Goal "[| (0::int) <= z;  0 <= z' |] ==> (nat z = nat z') = (z=z')";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   230
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset()));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   231
qed "eq_nat_nat_iff";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   232
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   233
(*"neg" is used in rewrite rules for binary comparisons*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   234
Goal "((number_of v :: nat) = number_of v') = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   235
\     (if neg (number_of v) then (iszero (number_of v') | neg (number_of v')) \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   236
\      else if neg (number_of v') then iszero (number_of v) \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   237
\      else iszero (number_of (bin_add v (bin_minus v'))))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   238
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   239
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   240
				  eq_nat_nat_iff, eq_number_of_eq, nat_0]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   241
by (simp_tac (simpset_of Int.thy addsimps [nat_eq_iff, nat_eq_iff2, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   242
					   iszero_def]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   243
by (simp_tac (simpset () addsimps [not_neg_eq_ge_0 RS sym]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   244
qed "eq_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   245
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   246
Addsimps [eq_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   247
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   248
(** Less-than (<) **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   249
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   250
(*"neg" is used in rewrite rules for binary comparisons*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   251
Goal "((number_of v :: nat) < number_of v') = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   252
\        (if neg (number_of v) then neg (number_of (bin_minus v')) \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   253
\         else neg (number_of (bin_add v (bin_minus v'))))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   254
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   255
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   256
				  nat_less_eq_zless, less_number_of_eq_neg,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   257
				  nat_0]) 1);
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   258
by (simp_tac (simpset_of Int.thy addsimps [neg_eq_less_0, zminus_zless, 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   259
				number_of_minus, zless_nat_eq_int_zless]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   260
qed "less_nat_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   261
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   262
Addsimps [less_nat_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   263
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   264
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   265
(** Less-than-or-equals (<=) **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   266
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   267
Goal "(number_of x <= (number_of y::nat)) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   268
\     (~ number_of y < (number_of x::nat))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   269
by (rtac (linorder_not_less RS sym) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   270
qed "le_nat_number_of_eq_not_less"; 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   271
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   272
Addsimps [le_nat_number_of_eq_not_less];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   273
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   274
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   275
(*Maps #n to n for n = 0, 1, 2*)
11018
71d624788ce2 added "numerals" theorems;
wenzelm
parents: 10960
diff changeset
   276
bind_thms ("numerals", [numeral_0_eq_0, numeral_1_eq_1, numeral_2_eq_2]);
71d624788ce2 added "numerals" theorems;
wenzelm
parents: 10960
diff changeset
   277
val numeral_ss = simpset() addsimps numerals;
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   278
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   279
(** Nat **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   280
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   281
Goal "0 < n ==> n = Suc(n - 1)";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   282
by (asm_full_simp_tac numeral_ss 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   283
qed "Suc_pred'";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   284
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   285
(*Expresses a natural number constant as the Suc of another one.
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   286
  NOT suitable for rewriting because n recurs in the condition.*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   287
bind_thm ("expand_Suc", inst "n" "number_of ?v" Suc_pred');
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   288
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   289
(** Arith **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   290
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   291
Goal "Suc n = n + 1";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   292
by (asm_simp_tac numeral_ss 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   293
qed "Suc_eq_add_numeral_1";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   294
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   295
(* These two can be useful when m = number_of... *)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   296
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   297
Goal "(m::nat) + n = (if m=0 then n else Suc ((m - 1) + n))";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   298
by (case_tac "m" 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   299
by (ALLGOALS (asm_simp_tac numeral_ss));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   300
qed "add_eq_if";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   301
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   302
Goal "(m::nat) * n = (if m=0 then 0 else n + ((m - 1) * n))";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   303
by (case_tac "m" 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   304
by (ALLGOALS (asm_simp_tac numeral_ss));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   305
qed "mult_eq_if";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   306
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   307
Goal "(p ^ m :: nat) = (if m=0 then 1 else p * (p ^ (m - 1)))";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   308
by (case_tac "m" 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   309
by (ALLGOALS (asm_simp_tac numeral_ss));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   310
qed "power_eq_if";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   311
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   312
Goal "[| 0<n; 0<m |] ==> m - n < (m::nat)";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   313
by (asm_full_simp_tac (numeral_ss addsimps [diff_less]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   314
qed "diff_less'";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   315
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   316
Addsimps [inst "n" "number_of ?v" diff_less'];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   317
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   318
(** Power **)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   319
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   320
Goal "(p::nat) ^ 2 = p*p";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   321
by (simp_tac numeral_ss 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   322
qed "power_two";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   323
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   324
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   325
(*** Comparisons involving (0::nat) ***)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   326
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   327
Goal "(number_of v = (0::nat)) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   328
\     (if neg (number_of v) then True else iszero (number_of v))";
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   329
by (simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym, iszero_0]) 1);
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   330
qed "eq_number_of_0"; 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   331
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   332
Goal "((0::nat) = number_of v) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   333
\     (if neg (number_of v) then True else iszero (number_of v))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   334
by (rtac ([eq_sym_conv, eq_number_of_0] MRS trans) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   335
qed "eq_0_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   336
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   337
Goal "((0::nat) < number_of v) = neg (number_of (bin_minus v))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   338
by (simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   339
qed "less_0_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   340
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   341
(*Simplification already handles n<0, n<=0 and 0<=n.*)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   342
Addsimps [eq_number_of_0, eq_0_number_of, less_0_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   343
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   344
Goal "neg (number_of v) ==> number_of v = (0::nat)";
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   345
by (asm_simp_tac (simpset() addsimps [numeral_0_eq_0 RS sym, iszero_0]) 1);
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   346
qed "neg_imp_number_of_eq_0";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   347
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   348
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   349
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   350
(*** Comparisons involving Suc ***)
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   351
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   352
Goal "(number_of v = Suc n) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   353
\       (let pv = number_of (bin_pred v) in \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   354
\        if neg pv then False else nat pv = n)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   355
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   356
    (simpset_of Int.thy addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   357
      [Let_def, neg_eq_less_0, linorder_not_less, number_of_pred,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   358
       nat_number_of_def, zadd_0] @ zadd_ac) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   359
by (res_inst_tac [("x", "number_of v")] spec 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   360
by (auto_tac (claset(), simpset() addsimps [nat_eq_iff]));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   361
qed "eq_number_of_Suc";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   362
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   363
Goal "(Suc n = number_of v) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   364
\       (let pv = number_of (bin_pred v) in \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   365
\        if neg pv then False else nat pv = n)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   366
by (rtac ([eq_sym_conv, eq_number_of_Suc] MRS trans) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   367
qed "Suc_eq_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   368
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   369
Goal "(number_of v < Suc n) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   370
\       (let pv = number_of (bin_pred v) in \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   371
\        if neg pv then True else nat pv < n)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   372
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   373
    (simpset_of Int.thy addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   374
      [Let_def, neg_eq_less_0, linorder_not_less, number_of_pred,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   375
       nat_number_of_def, zadd_0] @ zadd_ac) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   376
by (res_inst_tac [("x", "number_of v")] spec 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   377
by (auto_tac (claset(), simpset() addsimps [nat_less_iff]));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   378
qed "less_number_of_Suc";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   379
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   380
Goal "(Suc n < number_of v) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   381
\       (let pv = number_of (bin_pred v) in \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   382
\        if neg pv then False else n < nat pv)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   383
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   384
    (simpset_of Int.thy addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   385
      [Let_def, neg_eq_less_0, linorder_not_less, number_of_pred,
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   386
       nat_number_of_def, zadd_0] @ zadd_ac) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   387
by (res_inst_tac [("x", "number_of v")] spec 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   388
by (auto_tac (claset(), simpset() addsimps [zless_nat_eq_int_zless]));
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   389
qed "less_Suc_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   390
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   391
Goal "(number_of v <= Suc n) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   392
\       (let pv = number_of (bin_pred v) in \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   393
\        if neg pv then True else nat pv <= n)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   394
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   395
    (simpset () addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   396
      [Let_def, less_Suc_number_of, linorder_not_less RS sym]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   397
qed "le_number_of_Suc";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   398
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   399
Goal "(Suc n <= number_of v) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   400
\       (let pv = number_of (bin_pred v) in \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   401
\        if neg pv then False else n <= nat pv)";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   402
by (simp_tac
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   403
    (simpset () addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   404
      [Let_def, less_number_of_Suc, linorder_not_less RS sym]) 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   405
qed "le_Suc_number_of";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   406
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   407
Addsimps [eq_number_of_Suc, Suc_eq_number_of, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   408
	  less_number_of_Suc, less_Suc_number_of, 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   409
	  le_number_of_Suc, le_Suc_number_of];
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   410
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   411
(* Push int(.) inwards: *)
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   412
Addsimps [zadd_int RS sym];
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   413
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   414
Goal "(m+m = n+n) = (m = (n::int))";
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   415
by Auto_tac;
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   416
val lemma1 = result();
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   417
11868
56db9f3a6b3e Numerals now work for the integers: the binary numerals for 0 and 1 rewrite
paulson
parents: 11704
diff changeset
   418
Goal "m+m ~= (1::int) + n + n";
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   419
by Auto_tac;
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   420
by (dres_inst_tac [("f", "%x. x mod 2")] arg_cong 1);
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   421
by (full_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   422
val lemma2 = result();
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   423
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   424
Goal "((number_of (v BIT x) ::int) = number_of (w BIT y)) = \
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   425
\     (x=y & (((number_of v) ::int) = number_of w))"; 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   426
by (simp_tac (simpset_of Int.thy addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   427
	       [number_of_BIT, lemma1, lemma2, eq_commute]) 1); 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   428
qed "eq_number_of_BIT_BIT"; 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   429
13491
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13485
diff changeset
   430
Goal "((number_of (v BIT x) ::int) = number_of bin.Pls) = \
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13485
diff changeset
   431
\     (x=False & (((number_of v) ::int) = number_of bin.Pls))"; 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   432
by (simp_tac (simpset_of Int.thy addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   433
	       [number_of_BIT, number_of_Pls, eq_commute]) 1); 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   434
by (res_inst_tac [("x", "number_of v")] spec 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   435
by Safe_tac;
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   436
by (ALLGOALS Full_simp_tac);
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   437
by (dres_inst_tac [("f", "%x. x mod 2")] arg_cong 1);
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   438
by (full_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   439
qed "eq_number_of_BIT_Pls"; 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   440
13491
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13485
diff changeset
   441
Goal "((number_of (v BIT x) ::int) = number_of bin.Min) = \
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13485
diff changeset
   442
\     (x=True & (((number_of v) ::int) = number_of bin.Min))"; 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   443
by (simp_tac (simpset_of Int.thy addsimps
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   444
	       [number_of_BIT, number_of_Min, eq_commute]) 1); 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   445
by (res_inst_tac [("x", "number_of v")] spec 1);
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   446
by Auto_tac;
11704
3c50a2cd6f00 * sane numerals (stage 2): plain "num" syntax (removed "#");
wenzelm
parents: 11701
diff changeset
   447
by (dres_inst_tac [("f", "%x. x mod 2")] arg_cong 1);
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   448
by Auto_tac;
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   449
qed "eq_number_of_BIT_Min"; 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   450
13491
ddf6ae639f21 *** empty log message ***
nipkow
parents: 13485
diff changeset
   451
Goal "(number_of bin.Pls ::int) ~= number_of bin.Min"; 
10574
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   452
by Auto_tac;
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   453
qed "eq_number_of_Pls_Min"; 
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   454
8f98f0301d67 Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff changeset
   455
10754
9bc30e51144c now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents: 10710
diff changeset
   456
(*Distributive laws for literals*)
9bc30e51144c now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents: 10710
diff changeset
   457
Addsimps (map (inst "k" "number_of ?v")
9bc30e51144c now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents: 10710
diff changeset
   458
	  [add_mult_distrib, add_mult_distrib2,
9bc30e51144c now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents: 10710
diff changeset
   459
	   diff_mult_distrib, diff_mult_distrib2]);
9bc30e51144c now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents: 10710
diff changeset
   460
12613
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   461
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   462
(*** Literal arithmetic involving powers, type nat ***)
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   463
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   464
Goal "(0::int) <= z ==> nat (z^n) = nat z ^ n";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   465
by (induct_tac "n" 1); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   466
by (ALLGOALS (asm_simp_tac (simpset() addsimps [nat_mult_distrib])));
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   467
qed "nat_power_eq";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   468
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   469
Goal "(number_of v :: nat) ^ n = \
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   470
\      (if neg (number_of v) then 0^n else nat ((number_of v :: int) ^ n))";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   471
by (simp_tac
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   472
    (simpset_of Int.thy addsimps [neg_nat, not_neg_eq_ge_0, nat_number_of_def, 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   473
				  nat_power_eq]) 1);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   474
qed "power_nat_number_of";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   475
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   476
Addsimps [inst "n" "number_of ?w" power_nat_number_of];
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   477
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   478
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   479
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   480
(*** Literal arithmetic involving powers, type int ***)
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   481
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   482
Goal "(z::int) ^ (2*a) = (z^a)^2";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   483
by (simp_tac (simpset() addsimps [zpower_zpower, mult_commute]) 1); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   484
qed "zpower_even";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   485
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   486
Goal "(p::int) ^ 2 = p*p"; 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   487
by (simp_tac numeral_ss 1);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   488
qed "zpower_two";  
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   489
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   490
Goal "(z::int) ^ (2*a + 1) = z * (z^a)^2";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   491
by (simp_tac (simpset() addsimps [zpower_even, zpower_zadd_distrib]) 1); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   492
qed "zpower_odd";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   493
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   494
Goal "(z::int) ^ number_of (w BIT False) = \
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   495
\     (let w = z ^ (number_of w) in  w*w)";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   496
by (simp_tac (simpset_of Int.thy addsimps [nat_number_of_def,
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   497
        number_of_BIT, Let_def]) 1);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   498
by (res_inst_tac [("x","number_of w")] spec 1 THEN Clarify_tac 1); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   499
by (case_tac "(0::int) <= x" 1);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   500
by (auto_tac (claset(), 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   501
     simpset() addsimps [nat_mult_distrib, zpower_even, zpower_two])); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   502
qed "zpower_number_of_even";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   503
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   504
Goal "(z::int) ^ number_of (w BIT True) = \
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   505
\         (if (0::int) <= number_of w                   \
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   506
\          then (let w = z ^ (number_of w) in  z*w*w)   \
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   507
\          else 1)";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   508
by (simp_tac (simpset_of Int.thy addsimps [nat_number_of_def,
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   509
        number_of_BIT, Let_def]) 1);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   510
by (res_inst_tac [("x","number_of w")] spec 1 THEN Clarify_tac 1); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   511
by (case_tac "(0::int) <= x" 1);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   512
by (auto_tac (claset(), 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   513
              simpset() addsimps [nat_add_distrib, nat_mult_distrib, 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   514
                                  zpower_even, zpower_two])); 
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   515
qed "zpower_number_of_odd";
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   516
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   517
Addsimps (map (inst "z" "number_of ?v")
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   518
              [zpower_number_of_even, zpower_number_of_odd]);
279facb4253a Literal arithmetic: raising numbers to powers (nat, int, real, hypreal)
paulson
parents: 12196
diff changeset
   519