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