diff -r dfda74619509 -r ddd97d9dfbfb src/HOL/Nat_Transfer.thy --- a/src/HOL/Nat_Transfer.thy Thu Oct 29 08:14:39 2009 +0100 +++ b/src/HOL/Nat_Transfer.thy Thu Oct 29 11:41:36 2009 +0100 @@ -1,15 +1,26 @@ (* Authors: Jeremy Avigad and Amine Chaieb *) -header {* Sets up transfer from nats to ints and back. *} +header {* Generic transfer machinery; specific transfer from nats to ints and back. *} theory Nat_Transfer -imports Main Parity +imports Nat_Numeral +uses ("Tools/transfer.ML") begin +subsection {* Generic transfer machinery *} + +definition TransferMorphism:: "('b \ 'a) \ 'b set \ bool" + where "TransferMorphism a B \ True" + +use "Tools/transfer.ML" + +setup Transfer.setup + + subsection {* Set up transfer from nat to int *} -(* set up transfer direction *) +text {* set up transfer direction *} lemma TransferMorphism_nat_int: "TransferMorphism nat (op <= (0::int))" by (simp add: TransferMorphism_def) @@ -20,7 +31,7 @@ labels: natint ] -(* basic functions and relations *) +text {* basic functions and relations *} lemma transfer_nat_int_numerals: "(0::nat) = nat 0" @@ -43,31 +54,20 @@ "(x::int) >= 0 \ y >= 0 \ (nat x) * (nat y) = nat (x * y)" "(x::int) >= 0 \ y >= 0 \ (nat x) - (nat y) = nat (tsub x y)" "(x::int) >= 0 \ (nat x)^n = nat (x^n)" - "(x::int) >= 0 \ y >= 0 \ (nat x) div (nat y) = nat (x div y)" - "(x::int) >= 0 \ y >= 0 \ (nat x) mod (nat y) = nat (x mod y)" by (auto simp add: eq_nat_nat_iff nat_mult_distrib - nat_power_eq nat_div_distrib nat_mod_distrib tsub_def) + nat_power_eq tsub_def) lemma transfer_nat_int_function_closures: "(x::int) >= 0 \ y >= 0 \ x + y >= 0" "(x::int) >= 0 \ y >= 0 \ x * y >= 0" "(x::int) >= 0 \ y >= 0 \ tsub x y >= 0" "(x::int) >= 0 \ x^n >= 0" - "(x::int) >= 0 \ y >= 0 \ x div y >= 0" - "(x::int) >= 0 \ y >= 0 \ x mod y >= 0" "(0::int) >= 0" "(1::int) >= 0" "(2::int) >= 0" "(3::int) >= 0" "int z >= 0" apply (auto simp add: zero_le_mult_iff tsub_def) - apply (case_tac "y = 0") - apply auto - apply (subst pos_imp_zdiv_nonneg_iff, auto) - apply (case_tac "y = 0") - apply force - apply (rule pos_mod_sign) - apply arith done lemma transfer_nat_int_relations: @@ -89,7 +89,21 @@ ] -(* first-order quantifiers *) +text {* first-order quantifiers *} + +lemma all_nat: "(\x. P x) \ (\x\0. P (nat x))" + by (simp split add: split_nat) + +lemma ex_nat: "(\x. P x) \ (\x. 0 \ x \ P (nat x))" +proof + assume "\x. P x" + then obtain x where "P x" .. + then have "int x \ 0 \ P (nat (int x))" by simp + then show "\x\0. P (nat x)" .. +next + assume "\x\0. P (nat x)" + then show "\x. P x" by auto +qed lemma transfer_nat_int_quantifiers: "(ALL (x::nat). P x) = (ALL (x::int). x >= 0 \ P (nat x))" @@ -110,7 +124,7 @@ cong: all_cong ex_cong] -(* if *) +text {* if *} lemma nat_if_cong: "(if P then (nat x) else (nat y)) = nat (if P then x else y)" @@ -119,7 +133,7 @@ declare TransferMorphism_nat_int [transfer add return: nat_if_cong] -(* operations with sets *) +text {* operations with sets *} definition nat_set :: "int set \ bool" @@ -132,8 +146,6 @@ "A Un B = nat ` (int ` A Un int ` B)" "A Int B = nat ` (int ` A Int int ` B)" "{x. P x} = nat ` {x. x >= 0 & P(nat x)}" - "{..n} = nat ` {0..int n}" - "{m..n} = nat ` {int m..int n}" (* need all variants of these! *) apply (rule card_image [symmetric]) apply (auto simp add: inj_on_def image_def) apply (rule_tac x = "int x" in bexI) @@ -144,17 +156,12 @@ apply auto apply (rule_tac x = "int x" in exI) apply auto - apply (rule_tac x = "int x" in bexI) - apply auto - apply (rule_tac x = "int x" in bexI) - apply auto done lemma transfer_nat_int_set_function_closures: "nat_set {}" "nat_set A \ nat_set B \ nat_set (A Un B)" "nat_set A \ nat_set B \ nat_set (A Int B)" - "x >= 0 \ nat_set {x..y}" "nat_set {x. x >= 0 & P x}" "nat_set (int ` C)" "nat_set A \ x : A \ x >= 0" (* does it hurt to turn this on? *) @@ -167,7 +174,6 @@ "(A = B) = (int ` A = int ` B)" "(A < B) = (int ` A < int ` B)" "(A <= B) = (int ` A <= int ` B)" - apply (rule iffI) apply (erule finite_imageI) apply (erule finite_imageD) @@ -194,7 +200,7 @@ ] -(* setsum and setprod *) +text {* setsum and setprod *} (* this handles the case where the *domain* of f is nat *) lemma transfer_nat_int_sum_prod: @@ -262,52 +268,10 @@ transfer_nat_int_sum_prod_closure cong: transfer_nat_int_sum_prod_cong] -(* lists *) - -definition - embed_list :: "nat list \ int list" -where - "embed_list l = map int l"; - -definition - nat_list :: "int list \ bool" -where - "nat_list l = nat_set (set l)"; - -definition - return_list :: "int list \ nat list" -where - "return_list l = map nat l"; - -thm nat_0_le; - -lemma transfer_nat_int_list_return_embed: "nat_list l \ - embed_list (return_list l) = l"; - unfolding embed_list_def return_list_def nat_list_def nat_set_def - apply (induct l); - apply auto; -done; - -lemma transfer_nat_int_list_functions: - "l @ m = return_list (embed_list l @ embed_list m)" - "[] = return_list []"; - unfolding return_list_def embed_list_def; - apply auto; - apply (induct l, auto); - apply (induct m, auto); -done; - -(* -lemma transfer_nat_int_fold1: "fold f l x = - fold (%x. f (nat x)) (embed_list l) x"; -*) - - - subsection {* Set up transfer from int to nat *} -(* set up transfer direction *) +text {* set up transfer direction *} lemma TransferMorphism_int_nat: "TransferMorphism int (UNIV :: nat set)" by (simp add: TransferMorphism_def) @@ -319,7 +283,11 @@ ] -(* basic functions and relations *) +text {* basic functions and relations *} + +lemma UNIV_apply: + "UNIV x = True" + by (simp add: top_fun_eq top_bool_eq) definition is_nat :: "int \ bool" @@ -338,17 +306,13 @@ "(int x) * (int y) = int (x * y)" "tsub (int x) (int y) = int (x - y)" "(int x)^n = int (x^n)" - "(int x) div (int y) = int (x div y)" - "(int x) mod (int y) = int (x mod y)" - by (auto simp add: int_mult tsub_def int_power zdiv_int zmod_int) + by (auto simp add: int_mult tsub_def int_power) lemma transfer_int_nat_function_closures: "is_nat x \ is_nat y \ is_nat (x + y)" "is_nat x \ is_nat y \ is_nat (x * y)" "is_nat x \ is_nat y \ is_nat (tsub x y)" "is_nat x \ is_nat (x^n)" - "is_nat x \ is_nat y \ is_nat (x div y)" - "is_nat x \ is_nat y \ is_nat (x mod y)" "is_nat 0" "is_nat 1" "is_nat 2" @@ -361,12 +325,7 @@ "(int x < int y) = (x < y)" "(int x <= int y) = (x <= y)" "(int x dvd int y) = (x dvd y)" - "(even (int x)) = (even x)" - by (auto simp add: zdvd_int even_nat_def) - -lemma UNIV_apply: - "UNIV x = True" - by (simp add: top_fun_eq top_bool_eq) + by (auto simp add: zdvd_int) declare TransferMorphism_int_nat[transfer add return: transfer_int_nat_numerals @@ -377,7 +336,7 @@ ] -(* first-order quantifiers *) +text {* first-order quantifiers *} lemma transfer_int_nat_quantifiers: "(ALL (x::int) >= 0. P x) = (ALL (x::nat). P (int x))" @@ -392,7 +351,7 @@ return: transfer_int_nat_quantifiers] -(* if *) +text {* if *} lemma int_if_cong: "(if P then (int x) else (int y)) = int (if P then x else y)" @@ -402,7 +361,7 @@ -(* operations with sets *) +text {* operations with sets *} lemma transfer_int_nat_set_functions: "nat_set A \ card A = card (nat ` A)" @@ -410,7 +369,6 @@ "nat_set A \ nat_set B \ A Un B = int ` (nat ` A Un nat ` B)" "nat_set A \ nat_set B \ A Int B = int ` (nat ` A Int nat ` B)" "{x. x >= 0 & P x} = int ` {x. P(int x)}" - "is_nat m \ is_nat n \ {m..n} = int ` {nat m..nat n}" (* need all variants of these! *) by (simp_all only: is_nat_def transfer_nat_int_set_functions transfer_nat_int_set_function_closures @@ -421,7 +379,6 @@ "nat_set {}" "nat_set A \ nat_set B \ nat_set (A Un B)" "nat_set A \ nat_set B \ nat_set (A Int B)" - "is_nat x \ nat_set {x..y}" "nat_set {x. x >= 0 & P x}" "nat_set (int ` C)" "nat_set A \ x : A \ is_nat x" @@ -454,7 +411,7 @@ ] -(* setsum and setprod *) +text {* setsum and setprod *} (* this handles the case where the *domain* of f is int *) lemma transfer_int_nat_sum_prod: