author | chaieb |
Sun, 05 Apr 2009 19:21:51 +0100 | |
changeset 30868 | 1040425c86a2 |
parent 28952 | 15a4b2cf8c34 |
permissions | -rw-r--r-- |
27410
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
1 |
(* Title: HOLCF/NatIso.thy |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
2 |
Author: Brian Huffman |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
3 |
*) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
4 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
5 |
header {* Isomorphisms of the Natural Numbers *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
6 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
7 |
theory NatIso |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
8 |
imports Parity |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
9 |
begin |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
10 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
11 |
subsection {* Isomorphism between naturals and sums of naturals *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
12 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
13 |
primrec |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
14 |
sum2nat :: "nat + nat \<Rightarrow> nat" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
15 |
where |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
16 |
"sum2nat (Inl a) = a + a" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
17 |
| "sum2nat (Inr b) = Suc (b + b)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
18 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
19 |
primrec |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
20 |
nat2sum :: "nat \<Rightarrow> nat + nat" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
21 |
where |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
22 |
"nat2sum 0 = Inl 0" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
23 |
| "nat2sum (Suc n) = (case nat2sum n of |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
24 |
Inl a \<Rightarrow> Inr a | Inr b \<Rightarrow> Inl (Suc b))" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
25 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
26 |
lemma nat2sum_sum2nat [simp]: "nat2sum (sum2nat x) = x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
27 |
by (induct x, rule_tac [!] nat.induct, simp_all) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
28 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
29 |
lemma sum2nat_nat2sum [simp]: "sum2nat (nat2sum n) = n" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
30 |
by (induct n, auto split: sum.split) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
31 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
32 |
lemma inj_sum2nat: "inj sum2nat" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
33 |
by (rule inj_on_inverseI, rule nat2sum_sum2nat) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
34 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
35 |
lemma sum2nat_eq_iff [simp]: "sum2nat x = sum2nat y \<longleftrightarrow> x = y" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
36 |
by (rule inj_sum2nat [THEN inj_eq]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
37 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
38 |
lemma inj_nat2sum: "inj nat2sum" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
39 |
by (rule inj_on_inverseI, rule sum2nat_nat2sum) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
40 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
41 |
lemma nat2sum_eq_iff [simp]: "nat2sum x = nat2sum y \<longleftrightarrow> x = y" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
42 |
by (rule inj_nat2sum [THEN inj_eq]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
43 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
44 |
declare sum2nat.simps [simp del] |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
45 |
declare nat2sum.simps [simp del] |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
46 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
47 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
48 |
subsection {* Isomorphism between naturals and pairs of naturals *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
49 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
50 |
function |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
51 |
prod2nat :: "nat \<times> nat \<Rightarrow> nat" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
52 |
where |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
53 |
"prod2nat (0, 0) = 0" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
54 |
| "prod2nat (0, Suc n) = Suc (prod2nat (n, 0))" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
55 |
| "prod2nat (Suc m, n) = Suc (prod2nat (m, Suc n))" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
56 |
by pat_completeness auto |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
57 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
58 |
termination by (relation |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
59 |
"inv_image (measure id <*lex*> measure id) (\<lambda>(x, y). (x+y, x))") auto |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
60 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
61 |
primrec |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
62 |
nat2prod :: "nat \<Rightarrow> nat \<times> nat" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
63 |
where |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
64 |
"nat2prod 0 = (0, 0)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
65 |
| "nat2prod (Suc x) = |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
66 |
(case nat2prod x of (m, n) \<Rightarrow> |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
67 |
(case n of 0 \<Rightarrow> (0, Suc m) | Suc n \<Rightarrow> (Suc m, n)))" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
68 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
69 |
lemma nat2prod_prod2nat [simp]: "nat2prod (prod2nat x) = x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
70 |
by (induct x, rule prod2nat.induct, simp_all) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
71 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
72 |
lemma prod2nat_nat2prod [simp]: "prod2nat (nat2prod n) = n" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
73 |
by (induct n, auto split: prod.split nat.split) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
74 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
75 |
lemma inj_prod2nat: "inj prod2nat" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
76 |
by (rule inj_on_inverseI, rule nat2prod_prod2nat) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
77 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
78 |
lemma prod2nat_eq_iff [simp]: "prod2nat x = prod2nat y \<longleftrightarrow> x = y" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
79 |
by (rule inj_prod2nat [THEN inj_eq]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
80 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
81 |
lemma inj_nat2prod: "inj nat2prod" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
82 |
by (rule inj_on_inverseI, rule prod2nat_nat2prod) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
83 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
84 |
lemma nat2prod_eq_iff [simp]: "nat2prod x = nat2prod y \<longleftrightarrow> x = y" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
85 |
by (rule inj_nat2prod [THEN inj_eq]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
86 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
87 |
subsubsection {* Ordering properties *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
88 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
89 |
lemma fst_snd_le_prod2nat: "fst x \<le> prod2nat x \<and> snd x \<le> prod2nat x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
90 |
by (induct x rule: prod2nat.induct) auto |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
91 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
92 |
lemma fst_le_prod2nat: "fst x \<le> prod2nat x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
93 |
by (rule fst_snd_le_prod2nat [THEN conjunct1]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
94 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
95 |
lemma snd_le_prod2nat: "snd x \<le> prod2nat x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
96 |
by (rule fst_snd_le_prod2nat [THEN conjunct2]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
97 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
98 |
lemma le_prod2nat_1: "a \<le> prod2nat (a, b)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
99 |
using fst_le_prod2nat [where x="(a, b)"] by simp |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
100 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
101 |
lemma le_prod2nat_2: "b \<le> prod2nat (a, b)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
102 |
using snd_le_prod2nat [where x="(a, b)"] by simp |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
103 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
104 |
declare prod2nat.simps [simp del] |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
105 |
declare nat2prod.simps [simp del] |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
106 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
107 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
108 |
subsection {* Isomorphism between naturals and finite sets of naturals *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
109 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
110 |
subsubsection {* Preliminaries *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
111 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
112 |
lemma finite_vimage_Suc_iff: "finite (Suc -` F) \<longleftrightarrow> finite F" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
113 |
apply (safe intro!: finite_vimageI inj_Suc) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
114 |
apply (rule finite_subset [where B="insert 0 (Suc ` Suc -` F)"]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
115 |
apply (rule subsetI, case_tac x, simp, simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
116 |
apply (rule finite_insert [THEN iffD2]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
117 |
apply (erule finite_imageI) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
118 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
119 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
120 |
lemma vimage_Suc_insert_0: "Suc -` insert 0 A = Suc -` A" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
121 |
by auto |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
122 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
123 |
lemma vimage_Suc_insert_Suc: |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
124 |
"Suc -` insert (Suc n) A = insert n (Suc -` A)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
125 |
by auto |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
126 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
127 |
lemma even_nat_Suc_div_2: "even x \<Longrightarrow> Suc x div 2 = x div 2" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
128 |
by (simp only: numeral_2_eq_2 even_nat_plus_one_div_two) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
129 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
130 |
lemma div2_even_ext_nat: |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
131 |
"\<lbrakk>x div 2 = y div 2; even x = even y\<rbrakk> \<Longrightarrow> (x::nat) = y" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
132 |
apply (rule mod_div_equality [of x 2, THEN subst]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
133 |
apply (rule mod_div_equality [of y 2, THEN subst]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
134 |
apply (case_tac "even x") |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
135 |
apply (simp add: numeral_2_eq_2 even_nat_equiv_def) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
136 |
apply (simp add: numeral_2_eq_2 odd_nat_equiv_def) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
137 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
138 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
139 |
subsubsection {* From sets to naturals *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
140 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
141 |
definition |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
142 |
set2nat :: "nat set \<Rightarrow> nat" where |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
143 |
"set2nat = setsum (op ^ 2)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
144 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
145 |
lemma set2nat_empty [simp]: "set2nat {} = 0" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
146 |
by (simp add: set2nat_def) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
147 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
148 |
lemma set2nat_insert [simp]: |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
149 |
"\<lbrakk>finite A; n \<notin> A\<rbrakk> \<Longrightarrow> set2nat (insert n A) = 2^n + set2nat A" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
150 |
by (simp add: set2nat_def) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
151 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
152 |
lemma even_set2nat_iff: "finite A \<Longrightarrow> even (set2nat A) = (0 \<notin> A)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
153 |
by (unfold set2nat_def, erule finite_induct, auto) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
154 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
155 |
lemma set2nat_vimage_Suc: "set2nat (Suc -` A) = set2nat A div 2" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
156 |
apply (case_tac "finite A") |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
157 |
apply (erule finite_induct, simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
158 |
apply (case_tac x) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
159 |
apply (simp add: even_nat_Suc_div_2 even_set2nat_iff vimage_Suc_insert_0) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
160 |
apply (simp add: finite_vimageI add_commute vimage_Suc_insert_Suc) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
161 |
apply (simp add: set2nat_def finite_vimage_Suc_iff) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
162 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
163 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
164 |
lemmas set2nat_div_2 = set2nat_vimage_Suc [symmetric] |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
165 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
166 |
subsubsection {* From naturals to sets *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
167 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
168 |
definition |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
169 |
nat2set :: "nat \<Rightarrow> nat set" where |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
170 |
"nat2set x = {n. odd (x div 2 ^ n)}" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
171 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
172 |
lemma nat2set_0 [simp]: "0 \<in> nat2set x \<longleftrightarrow> odd x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
173 |
by (simp add: nat2set_def) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
174 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
175 |
lemma nat2set_Suc [simp]: |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
176 |
"Suc n \<in> nat2set x \<longleftrightarrow> n \<in> nat2set (x div 2)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
177 |
by (simp add: nat2set_def div_mult2_eq) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
178 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
179 |
lemma nat2set_zero [simp]: "nat2set 0 = {}" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
180 |
by (simp add: nat2set_def) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
181 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
182 |
lemma nat2set_div_2: "nat2set (x div 2) = Suc -` nat2set x" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
183 |
by auto |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
184 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
185 |
lemma nat2set_plus_power_2: |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
186 |
"n \<notin> nat2set z \<Longrightarrow> nat2set (2 ^ n + z) = insert n (nat2set z)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
187 |
apply (induct n arbitrary: z, simp_all) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
188 |
apply (rule set_ext, induct_tac x, simp, simp add: even_nat_Suc_div_2) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
189 |
apply (rule set_ext, induct_tac x, simp, simp add: add_commute) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
190 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
191 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
192 |
lemma finite_nat2set [simp]: "finite (nat2set n)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
193 |
apply (induct n rule: nat_less_induct) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
194 |
apply (case_tac "n = 0", simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
195 |
apply (drule_tac x="n div 2" in spec, simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
196 |
apply (simp add: nat2set_div_2) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
197 |
apply (simp add: finite_vimage_Suc_iff) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
198 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
199 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
200 |
subsubsection {* Proof of isomorphism *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
201 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
202 |
lemma set2nat_nat2set [simp]: "set2nat (nat2set n) = n" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
203 |
apply (induct n rule: nat_less_induct) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
204 |
apply (case_tac "n = 0", simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
205 |
apply (drule_tac x="n div 2" in spec, simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
206 |
apply (simp add: nat2set_div_2 set2nat_vimage_Suc) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
207 |
apply (erule div2_even_ext_nat) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
208 |
apply (simp add: even_set2nat_iff) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
209 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
210 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
211 |
lemma nat2set_set2nat [simp]: "finite A \<Longrightarrow> nat2set (set2nat A) = A" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
212 |
apply (erule finite_induct, simp_all) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
213 |
apply (simp add: nat2set_plus_power_2) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
214 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
215 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
216 |
lemma inj_nat2set: "inj nat2set" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
217 |
by (rule inj_on_inverseI, rule set2nat_nat2set) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
218 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
219 |
lemma nat2set_eq_iff [simp]: "nat2set x = nat2set y \<longleftrightarrow> x = y" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
220 |
by (rule inj_eq [OF inj_nat2set]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
221 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
222 |
lemma inj_on_set2nat: "inj_on set2nat (Collect finite)" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
223 |
by (rule inj_on_inverseI [where g="nat2set"], simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
224 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
225 |
lemma set2nat_eq_iff [simp]: |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
226 |
"\<lbrakk>finite A; finite B\<rbrakk> \<Longrightarrow> set2nat A = set2nat B \<longleftrightarrow> A = B" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
227 |
by (rule iffI, simp add: inj_onD [OF inj_on_set2nat], simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
228 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
229 |
subsubsection {* Ordering properties *} |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
230 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
231 |
lemma nat_less_power2: "n < 2^n" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
232 |
by (induct n) simp_all |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
233 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
234 |
lemma less_set2nat: "\<lbrakk>finite A; x \<in> A\<rbrakk> \<Longrightarrow> x < set2nat A" |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
235 |
unfolding set2nat_def |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
236 |
apply (rule order_less_le_trans [where y="setsum (op ^ 2) {x}"]) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
237 |
apply (simp add: nat_less_power2) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
238 |
apply (erule setsum_mono2, simp, simp) |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
239 |
done |
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
240 |
|
22f75653163f
isomorphisms between naturals and sums, products, and finite sets
huffman
parents:
diff
changeset
|
241 |
end |