25 subsection {* Set up transfer from nat to int *} |
25 subsection {* Set up transfer from nat to int *} |
26 |
26 |
27 text {* set up transfer direction *} |
27 text {* set up transfer direction *} |
28 |
28 |
29 lemma transfer_morphism_nat_int: "transfer_morphism nat (op <= (0::int))" |
29 lemma transfer_morphism_nat_int: "transfer_morphism nat (op <= (0::int))" |
30 by (simp add: transfer_morphism_def) |
30 by (fact transfer_morphismI) |
31 |
31 |
32 declare transfer_morphism_nat_int [transfer |
32 declare transfer_morphism_nat_int [transfer add |
33 add mode: manual |
33 mode: manual |
34 return: nat_0_le |
34 return: nat_0_le |
35 labels: natint |
35 labels: nat_int |
36 ] |
36 ] |
37 |
37 |
38 text {* basic functions and relations *} |
38 text {* basic functions and relations *} |
39 |
39 |
40 lemma transfer_nat_int_numerals: |
40 lemma transfer_nat_int_numerals [transfer key: transfer_morphism_nat_int]: |
41 "(0::nat) = nat 0" |
41 "(0::nat) = nat 0" |
42 "(1::nat) = nat 1" |
42 "(1::nat) = nat 1" |
43 "(2::nat) = nat 2" |
43 "(2::nat) = nat 2" |
44 "(3::nat) = nat 3" |
44 "(3::nat) = nat 3" |
45 by auto |
45 by auto |
50 "tsub x y = (if x >= y then x - y else 0)" |
50 "tsub x y = (if x >= y then x - y else 0)" |
51 |
51 |
52 lemma tsub_eq: "x >= y \<Longrightarrow> tsub x y = x - y" |
52 lemma tsub_eq: "x >= y \<Longrightarrow> tsub x y = x - y" |
53 by (simp add: tsub_def) |
53 by (simp add: tsub_def) |
54 |
54 |
55 |
55 lemma transfer_nat_int_functions [transfer key: transfer_morphism_nat_int]: |
56 lemma transfer_nat_int_functions: |
|
57 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> (nat x) + (nat y) = nat (x + y)" |
56 "(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)" |
57 "(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)" |
58 "(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)" |
59 "(x::int) >= 0 \<Longrightarrow> (nat x)^n = nat (x^n)" |
61 by (auto simp add: eq_nat_nat_iff nat_mult_distrib |
60 by (auto simp add: eq_nat_nat_iff nat_mult_distrib |
62 nat_power_eq tsub_def) |
61 nat_power_eq tsub_def) |
63 |
62 |
64 lemma transfer_nat_int_function_closures: |
63 lemma transfer_nat_int_function_closures [transfer key: transfer_morphism_nat_int]: |
65 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x + y >= 0" |
64 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x + y >= 0" |
66 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x * y >= 0" |
65 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> x * y >= 0" |
67 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> tsub x y >= 0" |
66 "(x::int) >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> tsub x y >= 0" |
68 "(x::int) >= 0 \<Longrightarrow> x^n >= 0" |
67 "(x::int) >= 0 \<Longrightarrow> x^n >= 0" |
69 "(0::int) >= 0" |
68 "(0::int) >= 0" |
71 "(2::int) >= 0" |
70 "(2::int) >= 0" |
72 "(3::int) >= 0" |
71 "(3::int) >= 0" |
73 "int z >= 0" |
72 "int z >= 0" |
74 by (auto simp add: zero_le_mult_iff tsub_def) |
73 by (auto simp add: zero_le_mult_iff tsub_def) |
75 |
74 |
76 lemma transfer_nat_int_relations: |
75 lemma transfer_nat_int_relations [transfer key: transfer_morphism_nat_int]: |
77 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
76 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
78 (nat (x::int) = nat y) = (x = y)" |
77 (nat (x::int) = nat y) = (x = y)" |
79 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
78 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
80 (nat (x::int) < nat y) = (x < y)" |
79 (nat (x::int) < nat y) = (x < y)" |
81 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
80 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
82 (nat (x::int) <= nat y) = (x <= y)" |
81 (nat (x::int) <= nat y) = (x <= y)" |
83 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
82 "x >= 0 \<Longrightarrow> y >= 0 \<Longrightarrow> |
84 (nat (x::int) dvd nat y) = (x dvd y)" |
83 (nat (x::int) dvd nat y) = (x dvd y)" |
85 by (auto simp add: zdvd_int) |
84 by (auto simp add: zdvd_int) |
86 |
|
87 declare transfer_morphism_nat_int [transfer add return: |
|
88 transfer_nat_int_numerals |
|
89 transfer_nat_int_functions |
|
90 transfer_nat_int_function_closures |
|
91 transfer_nat_int_relations |
|
92 ] |
|
93 |
85 |
94 |
86 |
95 text {* first-order quantifiers *} |
87 text {* first-order quantifiers *} |
96 |
88 |
97 lemma all_nat: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x\<ge>0. P (nat x))" |
89 lemma all_nat: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x\<ge>0. P (nat x))" |
106 next |
98 next |
107 assume "\<exists>x\<ge>0. P (nat x)" |
99 assume "\<exists>x\<ge>0. P (nat x)" |
108 then show "\<exists>x. P x" by auto |
100 then show "\<exists>x. P x" by auto |
109 qed |
101 qed |
110 |
102 |
111 lemma transfer_nat_int_quantifiers: |
103 lemma transfer_nat_int_quantifiers [transfer key: transfer_morphism_nat_int]: |
112 "(ALL (x::nat). P x) = (ALL (x::int). x >= 0 \<longrightarrow> P (nat x))" |
104 "(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))" |
105 "(EX (x::nat). P x) = (EX (x::int). x >= 0 & P (nat x))" |
114 by (rule all_nat, rule ex_nat) |
106 by (rule all_nat, rule ex_nat) |
115 |
107 |
116 (* should we restrict these? *) |
108 (* should we restrict these? *) |
121 lemma ex_cong: "(\<And>x. Q x \<Longrightarrow> P x = P' x) \<Longrightarrow> |
113 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)" |
114 (EX x. Q x \<and> P x) = (EX x. Q x \<and> P' x)" |
123 by auto |
115 by auto |
124 |
116 |
125 declare transfer_morphism_nat_int [transfer add |
117 declare transfer_morphism_nat_int [transfer add |
126 return: transfer_nat_int_quantifiers |
|
127 cong: all_cong ex_cong] |
118 cong: all_cong ex_cong] |
128 |
119 |
129 |
120 |
130 text {* if *} |
121 text {* if *} |
131 |
122 |
132 lemma nat_if_cong: "(if P then (nat x) else (nat y)) = |
123 lemma nat_if_cong [transfer key: transfer_morphism_nat_int]: |
133 nat (if P then x else y)" |
124 "(if P then (nat x) else (nat y)) = nat (if P then x else y)" |
134 by auto |
125 by auto |
135 |
|
136 declare transfer_morphism_nat_int [transfer add return: nat_if_cong] |
|
137 |
126 |
138 |
127 |
139 text {* operations with sets *} |
128 text {* operations with sets *} |
140 |
129 |
141 definition |
130 definition |
274 |
263 |
275 subsection {* Set up transfer from int to nat *} |
264 subsection {* Set up transfer from int to nat *} |
276 |
265 |
277 text {* set up transfer direction *} |
266 text {* set up transfer direction *} |
278 |
267 |
279 lemma transfer_morphism_int_nat: "transfer_morphism int (UNIV :: nat set)" |
268 lemma transfer_morphism_int_nat: "transfer_morphism int (\<lambda>n. True)" |
280 by (simp add: transfer_morphism_def) |
269 by (fact transfer_morphismI) |
281 |
270 |
282 declare transfer_morphism_int_nat [transfer add |
271 declare transfer_morphism_int_nat [transfer add |
283 mode: manual |
272 mode: manual |
284 (* labels: int-nat *) |
|
285 return: nat_int |
273 return: nat_int |
|
274 labels: int_nat |
286 ] |
275 ] |
287 |
276 |
288 |
277 |
289 text {* basic functions and relations *} |
278 text {* basic functions and relations *} |
290 |
|
291 lemma UNIV_apply: |
|
292 "UNIV x = True" |
|
293 by (simp add: top_fun_eq top_bool_eq) |
|
294 |
279 |
295 definition |
280 definition |
296 is_nat :: "int \<Rightarrow> bool" |
281 is_nat :: "int \<Rightarrow> bool" |
297 where |
282 where |
298 "is_nat x = (x >= 0)" |
283 "is_nat x = (x >= 0)" |
333 declare transfer_morphism_int_nat [transfer add return: |
318 declare transfer_morphism_int_nat [transfer add return: |
334 transfer_int_nat_numerals |
319 transfer_int_nat_numerals |
335 transfer_int_nat_functions |
320 transfer_int_nat_functions |
336 transfer_int_nat_function_closures |
321 transfer_int_nat_function_closures |
337 transfer_int_nat_relations |
322 transfer_int_nat_relations |
338 UNIV_apply |
|
339 ] |
323 ] |
340 |
324 |
341 |
325 |
342 text {* first-order quantifiers *} |
326 text {* first-order quantifiers *} |
343 |
327 |