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