author | nipkow |
Mon, 06 Aug 2001 13:43:24 +0200 | |
changeset 11464 | ddea204de5bc |
parent 11018 | 71d624788ce2 |
child 11701 | 3d51fbf81c17 |
permissions | -rw-r--r-- |
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 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
11 |
(** nat (coercion from int to nat) **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
12 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
13 |
Goal "nat (number_of w) = number_of w"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
14 |
by (simp_tac (simpset() addsimps [nat_number_of_def]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
15 |
qed "nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
16 |
Addsimps [nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
17 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
18 |
(*These rewrites should one day be re-oriented...*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
19 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
20 |
Goal "#0 = (0::nat)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
21 |
by (simp_tac (HOL_basic_ss addsimps [nat_0, nat_number_of_def]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
22 |
qed "numeral_0_eq_0"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
23 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
24 |
Goal "#1 = (1::nat)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
25 |
by (simp_tac (HOL_basic_ss addsimps [nat_1, nat_number_of_def]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
26 |
qed "numeral_1_eq_1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
27 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
28 |
Goal "#2 = (2::nat)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
29 |
by (simp_tac (HOL_basic_ss addsimps [nat_2, nat_number_of_def]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
30 |
qed "numeral_2_eq_2"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
31 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
32 |
bind_thm ("zero_eq_numeral_0", numeral_0_eq_0 RS sym); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
33 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
34 |
(** int (coercion from nat to int) **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
35 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
36 |
(*"neg" is used in rewrite rules for binary comparisons*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
37 |
Goal "int (number_of v :: nat) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
38 |
\ (if neg (number_of v) then #0 \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
39 |
\ else (number_of v :: int))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
40 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
41 |
(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
|
42 |
not_neg_nat, int_0]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
43 |
qed "int_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
44 |
Addsimps [int_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
45 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
46 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
47 |
val nat_bin_arith_setup = |
10693 | 48 |
[Fast_Arith.map_data (fn {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} => |
49 |
{add_mono_thms = add_mono_thms, mult_mono_thms = mult_mono_thms, |
|
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
50 |
inj_thms = inj_thms, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
51 |
lessD = lessD, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
52 |
simpset = simpset addsimps [int_nat_number_of, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
53 |
not_neg_number_of_Pls,neg_number_of_Min,neg_number_of_BIT]})]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
54 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
55 |
(** Successor **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
56 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
57 |
Goal "(#0::int) <= z ==> Suc (nat z) = nat (#1 + z)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
58 |
by (rtac sym 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
59 |
by (asm_simp_tac (simpset() addsimps [nat_eq_iff]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
60 |
qed "Suc_nat_eq_nat_zadd1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
61 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
62 |
Goal "Suc (number_of v) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
63 |
\ (if neg (number_of v) then #1 else number_of (bin_succ v))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
64 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
65 |
(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
|
66 |
nat_number_of_def, int_Suc, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
67 |
Suc_nat_eq_nat_zadd1, number_of_succ]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
68 |
qed "Suc_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
69 |
Addsimps [Suc_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
70 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
71 |
Goal "Suc (number_of v + n) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
72 |
\ (if neg (number_of v) then #1+n else number_of (bin_succ v) + n)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
73 |
by (Simp_tac 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
74 |
qed "Suc_nat_number_of_add"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
75 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
76 |
Goal "Suc #0 = #1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
77 |
by (Simp_tac 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
78 |
qed "Suc_numeral_0_eq_1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
79 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
80 |
Goal "Suc #1 = #2"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
81 |
by (Simp_tac 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
82 |
qed "Suc_numeral_1_eq_2"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
83 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
84 |
(** Addition **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
85 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
86 |
Goal "[| (#0::int) <= z; #0 <= z' |] ==> nat (z+z') = nat z + nat z'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
87 |
by (rtac (inj_int RS injD) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
88 |
by (asm_simp_tac (simpset() addsimps [zadd_int RS sym]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
89 |
qed "nat_add_distrib"; |
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 |
(*"neg" is used in rewrite rules for binary comparisons*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
92 |
Goal "(number_of v :: nat) + number_of v' = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
93 |
\ (if neg (number_of v) then number_of v' \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
94 |
\ else if neg (number_of v') then number_of v \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
95 |
\ else number_of (bin_add v v'))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
96 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
97 |
(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
|
98 |
nat_add_distrib RS sym, number_of_add]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
99 |
qed "add_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
100 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
101 |
Addsimps [add_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
102 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
103 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
104 |
(** Subtraction **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
105 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
106 |
Goal "[| (#0::int) <= z'; z' <= z |] ==> nat (z-z') = nat z - nat z'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
107 |
by (rtac (inj_int RS injD) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
108 |
by (asm_simp_tac (simpset() addsimps [zdiff_int RS sym, nat_le_eq_zle]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
109 |
qed "nat_diff_distrib"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
110 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
111 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
112 |
Goal "nat z - nat z' = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
113 |
\ (if neg z' then nat z \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
114 |
\ else let d = z-z' in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
115 |
\ if neg d then 0 else nat d)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
116 |
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
|
117 |
neg_eq_less_0, not_neg_eq_ge_0]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
118 |
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
|
119 |
qed "diff_nat_eq_if"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
120 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
121 |
Goalw [nat_number_of_def] |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
122 |
"(number_of v :: nat) - number_of v' = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
123 |
\ (if neg (number_of v') then number_of v \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
124 |
\ else let d = number_of (bin_add v (bin_minus v')) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
125 |
\ if neg d then #0 else nat d)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
126 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
127 |
(simpset_of Int.thy delcongs [if_weak_cong] |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
128 |
addsimps [not_neg_eq_ge_0, nat_0, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
129 |
diff_nat_eq_if, diff_number_of_eq]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
130 |
qed "diff_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
131 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
132 |
Addsimps [diff_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
133 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
134 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
135 |
(** Multiplication **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
136 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
137 |
Goal "(#0::int) <= z ==> nat (z*z') = nat z * nat z'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
138 |
by (case_tac "#0 <= z'" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
139 |
by (asm_full_simp_tac (simpset() addsimps [zmult_le_0_iff]) 2); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
140 |
by (rtac (inj_int RS injD) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
141 |
by (asm_simp_tac (simpset() addsimps [zmult_int RS sym, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
142 |
int_0_le_mult_iff]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
143 |
qed "nat_mult_distrib"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
144 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
145 |
Goal "z <= (#0::int) ==> nat(z*z') = nat(-z) * nat(-z')"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
146 |
by (rtac trans 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
147 |
by (rtac nat_mult_distrib 2); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
148 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
149 |
qed "nat_mult_distrib_neg"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
150 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
151 |
Goal "(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 #0 else number_of (bin_mult v v'))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
153 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
154 |
(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
|
155 |
nat_mult_distrib RS sym, number_of_mult, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
156 |
nat_0]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
157 |
qed "mult_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
158 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
159 |
Addsimps [mult_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 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
162 |
(** Quotient **) |
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 |
Goal "(#0::int) <= z ==> nat (z div z') = nat z div nat z'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
165 |
by (case_tac "#0 <= z'" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
166 |
by (auto_tac (claset(), |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
167 |
simpset() addsimps [div_nonneg_neg_le0, DIVISION_BY_ZERO_DIV])); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
168 |
by (zdiv_undefined_case_tac "z' = #0" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
169 |
by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_DIV]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
170 |
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset())); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
171 |
by (rename_tac "m m'" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
172 |
by (subgoal_tac "#0 <= int m div int m'" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
173 |
by (asm_full_simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
174 |
(simpset() addsimps [numeral_0_eq_0, pos_imp_zdiv_nonneg_iff]) 2); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
175 |
by (rtac (inj_int RS injD) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
176 |
by (Asm_simp_tac 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
177 |
by (res_inst_tac [("r", "int (m mod m')")] quorem_div 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
178 |
by (Force_tac 2); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
179 |
by (asm_full_simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
180 |
(simpset() addsimps [nat_less_iff RS sym, quorem_def, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
181 |
numeral_0_eq_0, zadd_int, zmult_int]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
182 |
by (rtac (mod_div_equality RS sym RS trans) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
183 |
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
184 |
qed "nat_div_distrib"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
185 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
186 |
Goal "(number_of v :: nat) div number_of v' = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
187 |
\ (if neg (number_of v) then #0 \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
188 |
\ else nat (number_of v div number_of v'))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
189 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
190 |
(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
|
191 |
nat_div_distrib RS sym, nat_0]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
192 |
qed "div_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
193 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
194 |
Addsimps [div_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
195 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
196 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
197 |
(** Remainder **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
198 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
199 |
(*Fails if z'<0: the LHS collapses to (nat z) but the RHS doesn't*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
200 |
Goal "[| (#0::int) <= z; #0 <= z' |] ==> nat (z mod z') = nat z mod nat z'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
201 |
by (zdiv_undefined_case_tac "z' = #0" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
202 |
by (simp_tac (simpset() addsimps [numeral_0_eq_0, DIVISION_BY_ZERO_MOD]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
203 |
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset())); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
204 |
by (rename_tac "m m'" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
205 |
by (subgoal_tac "#0 <= int m mod int m'" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
206 |
by (asm_full_simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
207 |
(simpset() addsimps [nat_less_iff, numeral_0_eq_0, pos_mod_sign]) 2); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
208 |
by (rtac (inj_int RS injD) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
209 |
by (Asm_simp_tac 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
210 |
by (res_inst_tac [("q", "int (m div m')")] quorem_mod 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
211 |
by (Force_tac 2); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
212 |
by (asm_full_simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
213 |
(simpset() addsimps [nat_less_iff RS sym, quorem_def, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
214 |
numeral_0_eq_0, zadd_int, zmult_int]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
215 |
by (rtac (mod_div_equality RS sym RS trans) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
216 |
by (asm_simp_tac (simpset() addsimps add_ac@mult_ac) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
217 |
qed "nat_mod_distrib"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
218 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
219 |
Goal "(number_of v :: nat) mod number_of v' = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
220 |
\ (if neg (number_of v) then #0 \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
221 |
\ else if neg (number_of v') then number_of v \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
222 |
\ else nat (number_of v mod number_of v'))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
223 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
224 |
(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
|
225 |
neg_nat, nat_0, DIVISION_BY_ZERO_MOD, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
226 |
nat_mod_distrib RS sym]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
227 |
qed "mod_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
228 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
229 |
Addsimps [mod_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
230 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
231 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
232 |
(*** Comparisons ***) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
233 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
234 |
(** Equals (=) **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
235 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
236 |
Goal "[| (#0::int) <= z; #0 <= z' |] ==> (nat z = nat z') = (z=z')"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
237 |
by (auto_tac (claset() addSEs [nonneg_eq_int], simpset())); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
238 |
qed "eq_nat_nat_iff"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
239 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
240 |
(*"neg" is used in rewrite rules for binary comparisons*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
241 |
Goal "((number_of v :: nat) = number_of v') = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
242 |
\ (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
|
243 |
\ 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
|
244 |
\ else iszero (number_of (bin_add v (bin_minus v'))))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
245 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
246 |
(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
|
247 |
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
|
248 |
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
|
249 |
iszero_def]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
250 |
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
|
251 |
qed "eq_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
252 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
253 |
Addsimps [eq_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
254 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
255 |
(** Less-than (<) **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
256 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
257 |
(*"neg" is used in rewrite rules for binary comparisons*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
258 |
Goal "((number_of v :: nat) < number_of v') = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
259 |
\ (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
|
260 |
\ else neg (number_of (bin_add v (bin_minus v'))))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
261 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
262 |
(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
|
263 |
nat_less_eq_zless, less_number_of_eq_neg, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
264 |
nat_0]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
265 |
by (simp_tac (simpset_of Int.thy addsimps [neg_eq_less_int0, zminus_zless, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
266 |
number_of_minus, zless_nat_eq_int_zless]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
267 |
qed "less_nat_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
268 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
269 |
Addsimps [less_nat_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
270 |
|
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 |
(** Less-than-or-equals (<=) **) |
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 |
Goal "(number_of x <= (number_of y::nat)) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
275 |
\ (~ number_of y < (number_of x::nat))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
276 |
by (rtac (linorder_not_less RS sym) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
277 |
qed "le_nat_number_of_eq_not_less"; |
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 |
Addsimps [le_nat_number_of_eq_not_less]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
280 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
281 |
(*** New versions of existing theorems involving 0, 1, 2 ***) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
282 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
283 |
(*Maps n to #n for n = 0, 1, 2*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
284 |
val numeral_sym_ss = |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
285 |
HOL_ss addsimps [numeral_0_eq_0 RS sym, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
286 |
numeral_1_eq_1 RS sym, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
287 |
numeral_2_eq_2 RS sym, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
288 |
Suc_numeral_1_eq_2, Suc_numeral_0_eq_1]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
289 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
290 |
fun rename_numerals th = simplify numeral_sym_ss (Thm.transfer (the_context ()) th); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
291 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
292 |
(*Maps #n to n for n = 0, 1, 2*) |
11018 | 293 |
bind_thms ("numerals", [numeral_0_eq_0, numeral_1_eq_1, numeral_2_eq_2]); |
294 |
val numeral_ss = simpset() addsimps numerals; |
|
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
295 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
296 |
(** Nat **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
297 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
298 |
Goal "#0 < n ==> n = Suc(n - #1)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
299 |
by (asm_full_simp_tac numeral_ss 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
300 |
qed "Suc_pred'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
301 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
302 |
(*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
|
303 |
NOT suitable for rewriting because n recurs in the condition.*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
304 |
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
|
305 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
306 |
(** NatDef & Nat **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
307 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
308 |
Addsimps (map rename_numerals [min_0L, min_0R, max_0L, max_0R]); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
309 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
310 |
AddIffs (map rename_numerals |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
311 |
[Suc_not_Zero, Zero_not_Suc, zero_less_Suc, not_less0, less_one, |
10710
0c8d58332658
tidying, removing obsolete lemmas about 0=... and 1=...
paulson
parents:
10693
diff
changeset
|
312 |
le0, le_0_eq, neq0_conv, not_gr0]); |
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
313 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
314 |
(** Arith **) |
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 |
(*Identity laws for + - * *) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
317 |
val basic_renamed_arith_simps = |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
318 |
map rename_numerals |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
319 |
[diff_0, diff_0_eq_0, add_0, add_0_right, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
320 |
mult_0, mult_0_right, mult_1, mult_1_right]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
321 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
322 |
(*Non-trivial simplifications*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
323 |
val other_renamed_arith_simps = |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
324 |
map rename_numerals |
10710
0c8d58332658
tidying, removing obsolete lemmas about 0=... and 1=...
paulson
parents:
10693
diff
changeset
|
325 |
[diff_is_0_eq, zero_less_diff, |
0c8d58332658
tidying, removing obsolete lemmas about 0=... and 1=...
paulson
parents:
10693
diff
changeset
|
326 |
mult_is_0, zero_less_mult_iff, mult_eq_1_iff]; |
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
327 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
328 |
Addsimps (basic_renamed_arith_simps @ other_renamed_arith_simps); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
329 |
|
10710
0c8d58332658
tidying, removing obsolete lemmas about 0=... and 1=...
paulson
parents:
10693
diff
changeset
|
330 |
AddIffs (map rename_numerals [add_is_0, add_gr_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 "Suc n = n + #1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
333 |
by (asm_simp_tac numeral_ss 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
334 |
qed "Suc_eq_add_numeral_1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
335 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
336 |
(* These two can be useful when m = number_of... *) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
337 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
338 |
Goal "(m::nat) + n = (if m=#0 then n else Suc ((m - #1) + n))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
339 |
by (case_tac "m" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
340 |
by (ALLGOALS (asm_simp_tac numeral_ss)); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
341 |
qed "add_eq_if"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
342 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
343 |
Goal "(m::nat) * n = (if m=#0 then #0 else n + ((m - #1) * n))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
344 |
by (case_tac "m" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
345 |
by (ALLGOALS (asm_simp_tac numeral_ss)); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
346 |
qed "mult_eq_if"; |
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 |
Goal "(p ^ m :: nat) = (if m=#0 then #1 else p * (p ^ (m - #1)))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
349 |
by (case_tac "m" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
350 |
by (ALLGOALS (asm_simp_tac numeral_ss)); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
351 |
qed "power_eq_if"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
352 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
353 |
Goal "[| #0<n; #0<m |] ==> m - n < (m::nat)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
354 |
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
|
355 |
qed "diff_less'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
356 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
357 |
Addsimps [inst "n" "number_of ?v" diff_less']; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
358 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
359 |
(*various theorems that aren't in the default simpset*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
360 |
bind_thm ("add_is_one'", rename_numerals add_is_1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
361 |
bind_thm ("zero_induct'", rename_numerals zero_induct); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
362 |
bind_thm ("diff_self_eq_0'", rename_numerals diff_self_eq_0); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
363 |
bind_thm ("mult_eq_self_implies_10'", rename_numerals mult_eq_self_implies_10); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
364 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
365 |
(** Divides **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
366 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
367 |
Addsimps (map rename_numerals [mod_1, mod_0, div_1, div_0]); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
368 |
AddIffs (map rename_numerals [dvd_1_left, dvd_0_right]); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
369 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
370 |
(*useful?*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
371 |
bind_thm ("mod_self'", rename_numerals mod_self); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
372 |
bind_thm ("div_self'", rename_numerals div_self); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
373 |
bind_thm ("div_less'", rename_numerals div_less); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
374 |
bind_thm ("mod_mult_self_is_zero'", rename_numerals mod_mult_self_is_0); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
375 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
376 |
(** Power **) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
377 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
378 |
Goal "(p::nat) ^ #0 = #1"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
379 |
by (simp_tac numeral_ss 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
380 |
qed "power_zero"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
381 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
382 |
Goal "(p::nat) ^ #1 = p"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
383 |
by (simp_tac numeral_ss 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
384 |
qed "power_one"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
385 |
Addsimps [power_zero, power_one]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
386 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
387 |
Goal "(p::nat) ^ #2 = p*p"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
388 |
by (simp_tac numeral_ss 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
389 |
qed "power_two"; |
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 "#0 < (i::nat) ==> #0 < i^n"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
392 |
by (asm_simp_tac numeral_ss 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
393 |
qed "zero_less_power'"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
394 |
Addsimps [zero_less_power']; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
395 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
396 |
bind_thm ("binomial_zero", rename_numerals binomial_0); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
397 |
bind_thm ("binomial_Suc'", rename_numerals binomial_Suc); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
398 |
bind_thm ("binomial_n_n'", rename_numerals binomial_n_n); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
399 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
400 |
(*binomial_0_Suc doesn't work well on numerals*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
401 |
Addsimps (map rename_numerals [binomial_n_0, binomial_zero, binomial_1]); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
402 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
403 |
Addsimps [rename_numerals card_Pow]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
404 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
405 |
(*** Comparisons involving (0::nat) ***) |
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 |
Goal "(number_of v = (0::nat)) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
408 |
\ (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
|
409 |
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
|
410 |
qed "eq_number_of_0"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
411 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
412 |
Goal "((0::nat) = number_of v) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
413 |
\ (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
|
414 |
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
|
415 |
qed "eq_0_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
416 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
417 |
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
|
418 |
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
|
419 |
qed "less_0_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
420 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
421 |
(*Simplification already handles n<0, n<=0 and 0<=n.*) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
422 |
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
|
423 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
424 |
Goal "neg (number_of v) ==> number_of v = (0::nat)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
425 |
by (asm_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
|
426 |
qed "neg_imp_number_of_eq_0"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
427 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
428 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
429 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
430 |
(*** Comparisons involving Suc ***) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
431 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
432 |
Goal "(number_of v = Suc n) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
433 |
\ (let pv = number_of (bin_pred v) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
434 |
\ if neg pv then False else nat pv = n)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
435 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
436 |
(simpset_of Int.thy addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
437 |
[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
|
438 |
nat_number_of_def, zadd_0] @ zadd_ac) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
439 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
440 |
by (auto_tac (claset(), simpset() addsimps [nat_eq_iff])); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
441 |
qed "eq_number_of_Suc"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
442 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
443 |
Goal "(Suc n = number_of v) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
444 |
\ (let pv = number_of (bin_pred v) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
445 |
\ if neg pv then False else nat pv = n)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
446 |
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
|
447 |
qed "Suc_eq_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
448 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
449 |
Goal "(number_of v < Suc n) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
450 |
\ (let pv = number_of (bin_pred v) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
451 |
\ if neg pv then True else nat pv < n)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
452 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
453 |
(simpset_of Int.thy addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
454 |
[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
|
455 |
nat_number_of_def, zadd_0] @ zadd_ac) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
456 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
457 |
by (auto_tac (claset(), simpset() addsimps [nat_less_iff])); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
458 |
qed "less_number_of_Suc"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
459 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
460 |
Goal "(Suc n < number_of v) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
461 |
\ (let pv = number_of (bin_pred v) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
462 |
\ if neg pv then False else n < nat pv)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
463 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
464 |
(simpset_of Int.thy addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
465 |
[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
|
466 |
nat_number_of_def, zadd_0] @ zadd_ac) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
467 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
468 |
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
|
469 |
qed "less_Suc_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
470 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
471 |
Goal "(number_of v <= Suc n) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
472 |
\ (let pv = number_of (bin_pred v) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
473 |
\ if neg pv then True else nat pv <= n)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
474 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
475 |
(simpset () addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
476 |
[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
|
477 |
qed "le_number_of_Suc"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
478 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
479 |
Goal "(Suc n <= number_of v) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
480 |
\ (let pv = number_of (bin_pred v) in \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
481 |
\ if neg pv then False else n <= nat pv)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
482 |
by (simp_tac |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
483 |
(simpset () addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
484 |
[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
|
485 |
qed "le_Suc_number_of"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
486 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
487 |
Addsimps [eq_number_of_Suc, Suc_eq_number_of, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
488 |
less_number_of_Suc, less_Suc_number_of, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
489 |
le_number_of_Suc, le_Suc_number_of]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
490 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
491 |
(* Push int(.) inwards: *) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
492 |
Addsimps [int_Suc,zadd_int RS sym]; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
493 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
494 |
Goal "(m+m = n+n) = (m = (n::int))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
495 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
496 |
val lemma1 = result(); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
497 |
|
11464 | 498 |
Goal "m+m ~= int 1' + n + n"; |
10574
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
499 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
500 |
by (dres_inst_tac [("f", "%x. x mod #2")] arg_cong 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
501 |
by (full_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
502 |
val lemma2 = result(); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
503 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
504 |
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
|
505 |
\ (x=y & (((number_of v) ::int) = number_of w))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
506 |
by (simp_tac (simpset_of Int.thy addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
507 |
[number_of_BIT, lemma1, lemma2, eq_commute]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
508 |
qed "eq_number_of_BIT_BIT"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
509 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
510 |
Goal "((number_of (v BIT x) ::int) = number_of Pls) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
511 |
\ (x=False & (((number_of v) ::int) = number_of Pls))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
512 |
by (simp_tac (simpset_of Int.thy addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
513 |
[number_of_BIT, number_of_Pls, eq_commute]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
514 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
515 |
by Safe_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
516 |
by (ALLGOALS Full_simp_tac); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
517 |
by (dres_inst_tac [("f", "%x. x mod #2")] arg_cong 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
518 |
by (full_simp_tac (simpset() addsimps [zmod_zadd1_eq]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
519 |
qed "eq_number_of_BIT_Pls"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
520 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
521 |
Goal "((number_of (v BIT x) ::int) = number_of Min) = \ |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
522 |
\ (x=True & (((number_of v) ::int) = number_of Min))"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
523 |
by (simp_tac (simpset_of Int.thy addsimps |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
524 |
[number_of_BIT, number_of_Min, eq_commute]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
525 |
by (res_inst_tac [("x", "number_of v")] spec 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
526 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
527 |
by (dres_inst_tac [("f", "%x. x mod #2")] arg_cong 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
528 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
529 |
qed "eq_number_of_BIT_Min"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
530 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
531 |
Goal "(number_of Pls ::int) ~= number_of Min"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
532 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
533 |
qed "eq_number_of_Pls_Min"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
534 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
535 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
536 |
(*** Further lemmas about "nat" ***) |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
537 |
|
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
538 |
Goal "nat (abs (w * z)) = nat (abs w) * nat (abs z)"; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
539 |
by (case_tac "z=#0 | w=#0" 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
540 |
by Auto_tac; |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
541 |
by (simp_tac (simpset() addsimps [zabs_def, nat_mult_distrib RS sym, |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
542 |
nat_mult_distrib_neg RS sym, zmult_less_0_iff]) 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
543 |
by (arith_tac 1); |
8f98f0301d67
Linear arithmetic now copes with mixed nat/int formulae.
nipkow
parents:
diff
changeset
|
544 |
qed "nat_abs_mult_distrib"; |
10754
9bc30e51144c
now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents:
10710
diff
changeset
|
545 |
|
9bc30e51144c
now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents:
10710
diff
changeset
|
546 |
(*Distributive laws for literals*) |
9bc30e51144c
now #16*(x+y) distributes for nat just as for other numeric types
paulson
parents:
10710
diff
changeset
|
547 |
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
|
548 |
[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
|
549 |
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
|
550 |