author | haftmann |
Mon, 08 Mar 2010 09:38:58 +0100 | |
changeset 35644 | d20cf282342e |
parent 35551 | 85aada96578b |
child 35683 | 70ace653fe77 |
permissions | -rw-r--r-- |
31708 | 1 |
|
32554 | 2 |
(* Authors: Jeremy Avigad and Amine Chaieb *) |
31708 | 3 |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
4 |
header {* Generic transfer machinery; specific transfer from nats to ints and back. *} |
31708 | 5 |
|
32558 | 6 |
theory Nat_Transfer |
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
7 |
imports Nat_Numeral |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
8 |
uses ("Tools/transfer.ML") |
31708 | 9 |
begin |
10 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
11 |
subsection {* Generic transfer machinery *} |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
12 |
|
35644 | 13 |
definition transfer_morphism:: "('b \<Rightarrow> 'a) \<Rightarrow> 'b set \<Rightarrow> bool" |
14 |
where "transfer_morphism f A \<longleftrightarrow> True" |
|
15 |
||
16 |
lemma transfer_morphismI: |
|
17 |
"transfer_morphism f A" |
|
18 |
by (simp add: transfer_morphism_def) |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
19 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
20 |
use "Tools/transfer.ML" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
21 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
22 |
setup Transfer.setup |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
23 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
24 |
|
31708 | 25 |
subsection {* Set up transfer from nat to int *} |
26 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
27 |
text {* set up transfer direction *} |
31708 | 28 |
|
35644 | 29 |
lemma transfer_morphism_nat_int: "transfer_morphism nat (op <= (0::int))" |
30 |
by (simp add: transfer_morphism_def) |
|
31708 | 31 |
|
35644 | 32 |
declare transfer_morphism_nat_int [transfer |
31708 | 33 |
add mode: manual |
34 |
return: nat_0_le |
|
35 |
labels: natint |
|
36 |
] |
|
37 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
38 |
text {* basic functions and relations *} |
31708 | 39 |
|
40 |
lemma transfer_nat_int_numerals: |
|
41 |
"(0::nat) = nat 0" |
|
42 |
"(1::nat) = nat 1" |
|
43 |
"(2::nat) = nat 2" |
|
44 |
"(3::nat) = nat 3" |
|
45 |
by auto |
|
46 |
||
47 |
definition |
|
48 |
tsub :: "int \<Rightarrow> int \<Rightarrow> int" |
|
49 |
where |
|
50 |
"tsub x y = (if x >= y then x - y else 0)" |
|
51 |
||
52 |
lemma tsub_eq: "x >= y \<Longrightarrow> tsub x y = x - y" |
|
53 |
by (simp add: tsub_def) |
|
54 |
||
55 |
||
56 |
lemma transfer_nat_int_functions: |
|
57 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) + (nat y) = nat (x + y)" |
|
58 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) * (nat y) = nat (x * y)" |
|
59 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) - (nat y) = nat (tsub x y)" |
|
60 |
"(x::int) >= 0 \<Longrightarrow> (nat x)^n = nat (x^n)" |
|
61 |
by (auto simp add: eq_nat_nat_iff nat_mult_distrib |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
62 |
nat_power_eq tsub_def) |
31708 | 63 |
|
64 |
lemma transfer_nat_int_function_closures: |
|
65 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x + y >= 0" |
|
66 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x * y >= 0" |
|
67 |
"(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> tsub x y >= 0" |
|
68 |
"(x::int) >= 0 \<Longrightarrow> x^n >= 0" |
|
69 |
"(0::int) >= 0" |
|
70 |
"(1::int) >= 0" |
|
71 |
"(2::int) >= 0" |
|
72 |
"(3::int) >= 0" |
|
73 |
"int z >= 0" |
|
33340
a165b97f3658
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
33318
diff
changeset
|
74 |
by (auto simp add: zero_le_mult_iff tsub_def) |
31708 | 75 |
|
76 |
lemma transfer_nat_int_relations: |
|
77 |
"x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
|
78 |
(nat (x::int) = nat y) = (x = y)" |
|
79 |
"x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
|
80 |
(nat (x::int) < nat y) = (x < y)" |
|
81 |
"x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
|
82 |
(nat (x::int) <= nat y) = (x <= y)" |
|
83 |
"x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
|
84 |
(nat (x::int) dvd nat y) = (x dvd y)" |
|
32558 | 85 |
by (auto simp add: zdvd_int) |
31708 | 86 |
|
35644 | 87 |
declare transfer_morphism_nat_int [transfer add return: |
31708 | 88 |
transfer_nat_int_numerals |
89 |
transfer_nat_int_functions |
|
90 |
transfer_nat_int_function_closures |
|
91 |
transfer_nat_int_relations |
|
92 |
] |
|
93 |
||
94 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
95 |
text {* first-order quantifiers *} |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
96 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
97 |
lemma all_nat: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x\<ge>0. P (nat x))" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
98 |
by (simp split add: split_nat) |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
99 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
100 |
lemma ex_nat: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>x. 0 \<le> x \<and> P (nat x))" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
101 |
proof |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
102 |
assume "\<exists>x. P x" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
103 |
then obtain x where "P x" .. |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
104 |
then have "int x \<ge> 0 \<and> P (nat (int x))" by simp |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
105 |
then show "\<exists>x\<ge>0. P (nat x)" .. |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
106 |
next |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
107 |
assume "\<exists>x\<ge>0. P (nat x)" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
108 |
then show "\<exists>x. P x" by auto |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
109 |
qed |
31708 | 110 |
|
111 |
lemma transfer_nat_int_quantifiers: |
|
112 |
"(ALL (x::nat). P x) = (ALL (x::int). x >= 0 \<longrightarrow> P (nat x))" |
|
113 |
"(EX (x::nat). P x) = (EX (x::int). x >= 0 & P (nat x))" |
|
114 |
by (rule all_nat, rule ex_nat) |
|
115 |
||
116 |
(* should we restrict these? *) |
|
117 |
lemma all_cong: "(\<And>x. Q x \<Longrightarrow> P x = P' x) \<Longrightarrow> |
|
118 |
(ALL x. Q x \<longrightarrow> P x) = (ALL x. Q x \<longrightarrow> P' x)" |
|
119 |
by auto |
|
120 |
||
121 |
lemma ex_cong: "(\<And>x. Q x \<Longrightarrow> P x = P' x) \<Longrightarrow> |
|
122 |
(EX x. Q x \<and> P x) = (EX x. Q x \<and> P' x)" |
|
123 |
by auto |
|
124 |
||
35644 | 125 |
declare transfer_morphism_nat_int [transfer add |
31708 | 126 |
return: transfer_nat_int_quantifiers |
127 |
cong: all_cong ex_cong] |
|
128 |
||
129 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
130 |
text {* if *} |
31708 | 131 |
|
132 |
lemma nat_if_cong: "(if P then (nat x) else (nat y)) = |
|
133 |
nat (if P then x else y)" |
|
134 |
by auto |
|
135 |
||
35644 | 136 |
declare transfer_morphism_nat_int [transfer add return: nat_if_cong] |
31708 | 137 |
|
138 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
139 |
text {* operations with sets *} |
31708 | 140 |
|
141 |
definition |
|
142 |
nat_set :: "int set \<Rightarrow> bool" |
|
143 |
where |
|
144 |
"nat_set S = (ALL x:S. x >= 0)" |
|
145 |
||
146 |
lemma transfer_nat_int_set_functions: |
|
147 |
"card A = card (int ` A)" |
|
148 |
"{} = nat ` ({}::int set)" |
|
149 |
"A Un B = nat ` (int ` A Un int ` B)" |
|
150 |
"A Int B = nat ` (int ` A Int int ` B)" |
|
151 |
"{x. P x} = nat ` {x. x >= 0 & P(nat x)}" |
|
152 |
apply (rule card_image [symmetric]) |
|
153 |
apply (auto simp add: inj_on_def image_def) |
|
154 |
apply (rule_tac x = "int x" in bexI) |
|
155 |
apply auto |
|
156 |
apply (rule_tac x = "int x" in bexI) |
|
157 |
apply auto |
|
158 |
apply (rule_tac x = "int x" in bexI) |
|
159 |
apply auto |
|
160 |
apply (rule_tac x = "int x" in exI) |
|
161 |
apply auto |
|
162 |
done |
|
163 |
||
164 |
lemma transfer_nat_int_set_function_closures: |
|
165 |
"nat_set {}" |
|
166 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Un B)" |
|
167 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Int B)" |
|
168 |
"nat_set {x. x >= 0 & P x}" |
|
169 |
"nat_set (int ` C)" |
|
170 |
"nat_set A \<Longrightarrow> x : A \<Longrightarrow> x >= 0" (* does it hurt to turn this on? *) |
|
171 |
unfolding nat_set_def apply auto |
|
172 |
done |
|
173 |
||
174 |
lemma transfer_nat_int_set_relations: |
|
175 |
"(finite A) = (finite (int ` A))" |
|
176 |
"(x : A) = (int x : int ` A)" |
|
177 |
"(A = B) = (int ` A = int ` B)" |
|
178 |
"(A < B) = (int ` A < int ` B)" |
|
179 |
"(A <= B) = (int ` A <= int ` B)" |
|
180 |
apply (rule iffI) |
|
181 |
apply (erule finite_imageI) |
|
182 |
apply (erule finite_imageD) |
|
183 |
apply (auto simp add: image_def expand_set_eq inj_on_def) |
|
184 |
apply (drule_tac x = "int x" in spec, auto) |
|
185 |
apply (drule_tac x = "int x" in spec, auto) |
|
186 |
apply (drule_tac x = "int x" in spec, auto) |
|
187 |
done |
|
188 |
||
189 |
lemma transfer_nat_int_set_return_embed: "nat_set A \<Longrightarrow> |
|
190 |
(int ` nat ` A = A)" |
|
191 |
by (auto simp add: nat_set_def image_def) |
|
192 |
||
193 |
lemma transfer_nat_int_set_cong: "(!!x. x >= 0 \<Longrightarrow> P x = P' x) \<Longrightarrow> |
|
194 |
{(x::int). x >= 0 & P x} = {x. x >= 0 & P' x}" |
|
195 |
by auto |
|
196 |
||
35644 | 197 |
declare transfer_morphism_nat_int [transfer add |
31708 | 198 |
return: transfer_nat_int_set_functions |
199 |
transfer_nat_int_set_function_closures |
|
200 |
transfer_nat_int_set_relations |
|
201 |
transfer_nat_int_set_return_embed |
|
202 |
cong: transfer_nat_int_set_cong |
|
203 |
] |
|
204 |
||
205 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
206 |
text {* setsum and setprod *} |
31708 | 207 |
|
208 |
(* this handles the case where the *domain* of f is nat *) |
|
209 |
lemma transfer_nat_int_sum_prod: |
|
210 |
"setsum f A = setsum (%x. f (nat x)) (int ` A)" |
|
211 |
"setprod f A = setprod (%x. f (nat x)) (int ` A)" |
|
212 |
apply (subst setsum_reindex) |
|
213 |
apply (unfold inj_on_def, auto) |
|
214 |
apply (subst setprod_reindex) |
|
215 |
apply (unfold inj_on_def o_def, auto) |
|
216 |
done |
|
217 |
||
218 |
(* this handles the case where the *range* of f is nat *) |
|
219 |
lemma transfer_nat_int_sum_prod2: |
|
220 |
"setsum f A = nat(setsum (%x. int (f x)) A)" |
|
221 |
"setprod f A = nat(setprod (%x. int (f x)) A)" |
|
222 |
apply (subst int_setsum [symmetric]) |
|
223 |
apply auto |
|
224 |
apply (subst int_setprod [symmetric]) |
|
225 |
apply auto |
|
226 |
done |
|
227 |
||
228 |
lemma transfer_nat_int_sum_prod_closure: |
|
229 |
"nat_set A \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x >= (0::int)) \<Longrightarrow> setsum f A >= 0" |
|
230 |
"nat_set A \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x >= (0::int)) \<Longrightarrow> setprod f A >= 0" |
|
231 |
unfolding nat_set_def |
|
232 |
apply (rule setsum_nonneg) |
|
233 |
apply auto |
|
234 |
apply (rule setprod_nonneg) |
|
235 |
apply auto |
|
236 |
done |
|
237 |
||
238 |
(* this version doesn't work, even with nat_set A \<Longrightarrow> |
|
239 |
x : A \<Longrightarrow> x >= 0 turned on. Why not? |
|
240 |
||
241 |
also: what does =simp=> do? |
|
242 |
||
243 |
lemma transfer_nat_int_sum_prod_closure: |
|
244 |
"(!!x. x : A ==> f x >= (0::int)) \<Longrightarrow> setsum f A >= 0" |
|
245 |
"(!!x. x : A ==> f x >= (0::int)) \<Longrightarrow> setprod f A >= 0" |
|
246 |
unfolding nat_set_def simp_implies_def |
|
247 |
apply (rule setsum_nonneg) |
|
248 |
apply auto |
|
249 |
apply (rule setprod_nonneg) |
|
250 |
apply auto |
|
251 |
done |
|
252 |
*) |
|
253 |
||
254 |
(* Making A = B in this lemma doesn't work. Why not? |
|
255 |
Also, why aren't setsum_cong and setprod_cong enough, |
|
256 |
with the previously mentioned rule turned on? *) |
|
257 |
||
258 |
lemma transfer_nat_int_sum_prod_cong: |
|
259 |
"A = B \<Longrightarrow> nat_set B \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x = g x) \<Longrightarrow> |
|
260 |
setsum f A = setsum g B" |
|
261 |
"A = B \<Longrightarrow> nat_set B \<Longrightarrow> (!!x. x >= 0 \<Longrightarrow> f x = g x) \<Longrightarrow> |
|
262 |
setprod f A = setprod g B" |
|
263 |
unfolding nat_set_def |
|
264 |
apply (subst setsum_cong, assumption) |
|
265 |
apply auto [2] |
|
266 |
apply (subst setprod_cong, assumption, auto) |
|
267 |
done |
|
268 |
||
35644 | 269 |
declare transfer_morphism_nat_int [transfer add |
31708 | 270 |
return: transfer_nat_int_sum_prod transfer_nat_int_sum_prod2 |
271 |
transfer_nat_int_sum_prod_closure |
|
272 |
cong: transfer_nat_int_sum_prod_cong] |
|
273 |
||
274 |
||
275 |
subsection {* Set up transfer from int to nat *} |
|
276 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
277 |
text {* set up transfer direction *} |
31708 | 278 |
|
35644 | 279 |
lemma transfer_morphism_int_nat: "transfer_morphism int (UNIV :: nat set)" |
280 |
by (simp add: transfer_morphism_def) |
|
31708 | 281 |
|
35644 | 282 |
declare transfer_morphism_int_nat [transfer add |
31708 | 283 |
mode: manual |
284 |
(* labels: int-nat *) |
|
285 |
return: nat_int |
|
286 |
] |
|
287 |
||
288 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
289 |
text {* basic functions and relations *} |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
290 |
|
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
291 |
lemma UNIV_apply: |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
292 |
"UNIV x = True" |
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
293 |
by (simp add: top_fun_eq top_bool_eq) |
31708 | 294 |
|
295 |
definition |
|
296 |
is_nat :: "int \<Rightarrow> bool" |
|
297 |
where |
|
298 |
"is_nat x = (x >= 0)" |
|
299 |
||
300 |
lemma transfer_int_nat_numerals: |
|
301 |
"0 = int 0" |
|
302 |
"1 = int 1" |
|
303 |
"2 = int 2" |
|
304 |
"3 = int 3" |
|
305 |
by auto |
|
306 |
||
307 |
lemma transfer_int_nat_functions: |
|
308 |
"(int x) + (int y) = int (x + y)" |
|
309 |
"(int x) * (int y) = int (x * y)" |
|
310 |
"tsub (int x) (int y) = int (x - y)" |
|
311 |
"(int x)^n = int (x^n)" |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
312 |
by (auto simp add: int_mult tsub_def int_power) |
31708 | 313 |
|
314 |
lemma transfer_int_nat_function_closures: |
|
315 |
"is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (x + y)" |
|
316 |
"is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (x * y)" |
|
317 |
"is_nat x \<Longrightarrow> is_nat y \<Longrightarrow> is_nat (tsub x y)" |
|
318 |
"is_nat x \<Longrightarrow> is_nat (x^n)" |
|
319 |
"is_nat 0" |
|
320 |
"is_nat 1" |
|
321 |
"is_nat 2" |
|
322 |
"is_nat 3" |
|
323 |
"is_nat (int z)" |
|
324 |
by (simp_all only: is_nat_def transfer_nat_int_function_closures) |
|
325 |
||
326 |
lemma transfer_int_nat_relations: |
|
327 |
"(int x = int y) = (x = y)" |
|
328 |
"(int x < int y) = (x < y)" |
|
329 |
"(int x <= int y) = (x <= y)" |
|
330 |
"(int x dvd int y) = (x dvd y)" |
|
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
331 |
by (auto simp add: zdvd_int) |
32121 | 332 |
|
35644 | 333 |
declare transfer_morphism_int_nat [transfer add return: |
31708 | 334 |
transfer_int_nat_numerals |
335 |
transfer_int_nat_functions |
|
336 |
transfer_int_nat_function_closures |
|
337 |
transfer_int_nat_relations |
|
32121 | 338 |
UNIV_apply |
31708 | 339 |
] |
340 |
||
341 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
342 |
text {* first-order quantifiers *} |
31708 | 343 |
|
344 |
lemma transfer_int_nat_quantifiers: |
|
345 |
"(ALL (x::int) >= 0. P x) = (ALL (x::nat). P (int x))" |
|
346 |
"(EX (x::int) >= 0. P x) = (EX (x::nat). P (int x))" |
|
347 |
apply (subst all_nat) |
|
348 |
apply auto [1] |
|
349 |
apply (subst ex_nat) |
|
350 |
apply auto |
|
351 |
done |
|
352 |
||
35644 | 353 |
declare transfer_morphism_int_nat [transfer add |
31708 | 354 |
return: transfer_int_nat_quantifiers] |
355 |
||
356 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
357 |
text {* if *} |
31708 | 358 |
|
359 |
lemma int_if_cong: "(if P then (int x) else (int y)) = |
|
360 |
int (if P then x else y)" |
|
361 |
by auto |
|
362 |
||
35644 | 363 |
declare transfer_morphism_int_nat [transfer add return: int_if_cong] |
31708 | 364 |
|
365 |
||
366 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
367 |
text {* operations with sets *} |
31708 | 368 |
|
369 |
lemma transfer_int_nat_set_functions: |
|
370 |
"nat_set A \<Longrightarrow> card A = card (nat ` A)" |
|
371 |
"{} = int ` ({}::nat set)" |
|
372 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> A Un B = int ` (nat ` A Un nat ` B)" |
|
373 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> A Int B = int ` (nat ` A Int nat ` B)" |
|
374 |
"{x. x >= 0 & P x} = int ` {x. P(int x)}" |
|
375 |
(* need all variants of these! *) |
|
376 |
by (simp_all only: is_nat_def transfer_nat_int_set_functions |
|
377 |
transfer_nat_int_set_function_closures |
|
378 |
transfer_nat_int_set_return_embed nat_0_le |
|
379 |
cong: transfer_nat_int_set_cong) |
|
380 |
||
381 |
lemma transfer_int_nat_set_function_closures: |
|
382 |
"nat_set {}" |
|
383 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Un B)" |
|
384 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> nat_set (A Int B)" |
|
385 |
"nat_set {x. x >= 0 & P x}" |
|
386 |
"nat_set (int ` C)" |
|
387 |
"nat_set A \<Longrightarrow> x : A \<Longrightarrow> is_nat x" |
|
388 |
by (simp_all only: transfer_nat_int_set_function_closures is_nat_def) |
|
389 |
||
390 |
lemma transfer_int_nat_set_relations: |
|
391 |
"nat_set A \<Longrightarrow> finite A = finite (nat ` A)" |
|
392 |
"is_nat x \<Longrightarrow> nat_set A \<Longrightarrow> (x : A) = (nat x : nat ` A)" |
|
393 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> (A = B) = (nat ` A = nat ` B)" |
|
394 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> (A < B) = (nat ` A < nat ` B)" |
|
395 |
"nat_set A \<Longrightarrow> nat_set B \<Longrightarrow> (A <= B) = (nat ` A <= nat ` B)" |
|
396 |
by (simp_all only: is_nat_def transfer_nat_int_set_relations |
|
397 |
transfer_nat_int_set_return_embed nat_0_le) |
|
398 |
||
399 |
lemma transfer_int_nat_set_return_embed: "nat ` int ` A = A" |
|
400 |
by (simp only: transfer_nat_int_set_relations |
|
401 |
transfer_nat_int_set_function_closures |
|
402 |
transfer_nat_int_set_return_embed nat_0_le) |
|
403 |
||
404 |
lemma transfer_int_nat_set_cong: "(!!x. P x = P' x) \<Longrightarrow> |
|
405 |
{(x::nat). P x} = {x. P' x}" |
|
406 |
by auto |
|
407 |
||
35644 | 408 |
declare transfer_morphism_int_nat [transfer add |
31708 | 409 |
return: transfer_int_nat_set_functions |
410 |
transfer_int_nat_set_function_closures |
|
411 |
transfer_int_nat_set_relations |
|
412 |
transfer_int_nat_set_return_embed |
|
413 |
cong: transfer_int_nat_set_cong |
|
414 |
] |
|
415 |
||
416 |
||
33318
ddd97d9dfbfb
moved Nat_Transfer before Divides; distributed Nat_Transfer setup accordingly
haftmann
parents:
32558
diff
changeset
|
417 |
text {* setsum and setprod *} |
31708 | 418 |
|
419 |
(* this handles the case where the *domain* of f is int *) |
|
420 |
lemma transfer_int_nat_sum_prod: |
|
421 |
"nat_set A \<Longrightarrow> setsum f A = setsum (%x. f (int x)) (nat ` A)" |
|
422 |
"nat_set A \<Longrightarrow> setprod f A = setprod (%x. f (int x)) (nat ` A)" |
|
423 |
apply (subst setsum_reindex) |
|
424 |
apply (unfold inj_on_def nat_set_def, auto simp add: eq_nat_nat_iff) |
|
425 |
apply (subst setprod_reindex) |
|
426 |
apply (unfold inj_on_def nat_set_def o_def, auto simp add: eq_nat_nat_iff |
|
427 |
cong: setprod_cong) |
|
428 |
done |
|
429 |
||
430 |
(* this handles the case where the *range* of f is int *) |
|
431 |
lemma transfer_int_nat_sum_prod2: |
|
432 |
"(!!x. x:A \<Longrightarrow> is_nat (f x)) \<Longrightarrow> setsum f A = int(setsum (%x. nat (f x)) A)" |
|
433 |
"(!!x. x:A \<Longrightarrow> is_nat (f x)) \<Longrightarrow> |
|
434 |
setprod f A = int(setprod (%x. nat (f x)) A)" |
|
435 |
unfolding is_nat_def |
|
436 |
apply (subst int_setsum, auto) |
|
437 |
apply (subst int_setprod, auto simp add: cong: setprod_cong) |
|
438 |
done |
|
439 |
||
35644 | 440 |
declare transfer_morphism_int_nat [transfer add |
31708 | 441 |
return: transfer_int_nat_sum_prod transfer_int_nat_sum_prod2 |
442 |
cong: setsum_cong setprod_cong] |
|
443 |
||
444 |
end |