24333
|
1 |
(*
|
|
2 |
ID: $Id$
|
|
3 |
Author: Jeremy Dawson and Gerwin Klein, NICTA
|
|
4 |
|
|
5 |
consequences of type definition theorems,
|
|
6 |
and of extended type definition theorems
|
|
7 |
*)
|
24350
|
8 |
|
|
9 |
header {* Type Definition Theorems *}
|
|
10 |
|
24333
|
11 |
theory TdThs imports Main begin
|
|
12 |
|
|
13 |
lemma
|
|
14 |
tdD1: "type_definition Rep Abs A \<Longrightarrow> \<forall>x. Rep x \<in> A" and
|
|
15 |
tdD2: "type_definition Rep Abs A \<Longrightarrow> \<forall>x. Abs (Rep x) = x" and
|
|
16 |
tdD3: "type_definition Rep Abs A \<Longrightarrow> \<forall>y. y \<in> A \<longrightarrow> Rep (Abs y) = y"
|
|
17 |
by (auto simp: type_definition_def)
|
|
18 |
|
|
19 |
lemma td_nat_int:
|
|
20 |
"type_definition int nat (Collect (op <= 0))"
|
|
21 |
unfolding type_definition_def by auto
|
|
22 |
|
|
23 |
context type_definition
|
|
24 |
begin
|
|
25 |
|
|
26 |
lemmas Rep' [iff] = Rep [simplified] (* if A is given as Collect .. *)
|
|
27 |
|
|
28 |
declare Rep_inverse [simp] Rep_inject [simp]
|
|
29 |
|
|
30 |
lemma Abs_eqD: "Abs x = Abs y ==> x \<in> A ==> y \<in> A ==> x = y"
|
|
31 |
by (simp add: Abs_inject)
|
|
32 |
|
|
33 |
lemma Abs_inverse':
|
|
34 |
"r : A ==> Abs r = a ==> Rep a = r"
|
|
35 |
by (safe elim!: Abs_inverse)
|
|
36 |
|
|
37 |
lemma Rep_comp_inverse:
|
|
38 |
"Rep o f = g ==> Abs o g = f"
|
|
39 |
using Rep_inverse by (auto intro: ext)
|
|
40 |
|
|
41 |
lemma Rep_eqD [elim!]: "Rep x = Rep y ==> x = y"
|
|
42 |
by simp
|
|
43 |
|
|
44 |
lemma Rep_inverse': "Rep a = r ==> Abs r = a"
|
|
45 |
by (safe intro!: Rep_inverse)
|
|
46 |
|
|
47 |
lemma comp_Abs_inverse:
|
|
48 |
"f o Abs = g ==> g o Rep = f"
|
|
49 |
using Rep_inverse by (auto intro: ext)
|
|
50 |
|
|
51 |
lemma set_Rep:
|
|
52 |
"A = range Rep"
|
|
53 |
proof (rule set_ext)
|
|
54 |
fix x
|
|
55 |
show "(x \<in> A) = (x \<in> range Rep)"
|
|
56 |
by (auto dest: Abs_inverse [of x, symmetric])
|
|
57 |
qed
|
|
58 |
|
|
59 |
lemma set_Rep_Abs: "A = range (Rep o Abs)"
|
|
60 |
proof (rule set_ext)
|
|
61 |
fix x
|
|
62 |
show "(x \<in> A) = (x \<in> range (Rep o Abs))"
|
|
63 |
by (auto dest: Abs_inverse [of x, symmetric])
|
|
64 |
qed
|
|
65 |
|
|
66 |
lemma Abs_inj_on: "inj_on Abs A"
|
|
67 |
unfolding inj_on_def
|
|
68 |
by (auto dest: Abs_inject [THEN iffD1])
|
|
69 |
|
|
70 |
lemma image: "Abs ` A = UNIV"
|
|
71 |
by (auto intro!: image_eqI)
|
|
72 |
|
|
73 |
lemmas td_thm = type_definition_axioms
|
|
74 |
|
|
75 |
lemma fns1:
|
|
76 |
"Rep o fa = fr o Rep | fa o Abs = Abs o fr ==> Abs o fr o Rep = fa"
|
|
77 |
by (auto dest: Rep_comp_inverse elim: comp_Abs_inverse simp: o_assoc)
|
|
78 |
|
|
79 |
lemmas fns1a = disjI1 [THEN fns1]
|
|
80 |
lemmas fns1b = disjI2 [THEN fns1]
|
|
81 |
|
|
82 |
lemma fns4:
|
|
83 |
"Rep o fa o Abs = fr ==>
|
|
84 |
Rep o fa = fr o Rep & fa o Abs = Abs o fr"
|
|
85 |
by (auto intro!: ext)
|
|
86 |
|
|
87 |
end
|
|
88 |
|
|
89 |
interpretation nat_int: type_definition [int nat "Collect (op <= 0)"]
|
|
90 |
by (rule td_nat_int)
|
|
91 |
|
|
92 |
-- "resetting to the default nat induct and cases rules"
|
|
93 |
declare Nat.induct [case_names 0 Suc, induct type]
|
|
94 |
declare Nat.exhaust [case_names 0 Suc, cases type]
|
|
95 |
|
|
96 |
|
24350
|
97 |
subsection "Extended form of type definition predicate"
|
24333
|
98 |
|
|
99 |
lemma td_conds:
|
|
100 |
"norm o norm = norm ==> (fr o norm = norm o fr) =
|
|
101 |
(norm o fr o norm = fr o norm & norm o fr o norm = norm o fr)"
|
|
102 |
apply safe
|
|
103 |
apply (simp_all add: o_assoc [symmetric])
|
|
104 |
apply (simp_all add: o_assoc)
|
|
105 |
done
|
|
106 |
|
|
107 |
lemma fn_comm_power:
|
|
108 |
"fa o tr = tr o fr ==> fa ^ n o tr = tr o fr ^ n"
|
|
109 |
apply (rule ext)
|
|
110 |
apply (induct n)
|
|
111 |
apply (auto dest: fun_cong)
|
|
112 |
done
|
|
113 |
|
|
114 |
lemmas fn_comm_power' =
|
|
115 |
ext [THEN fn_comm_power, THEN fun_cong, unfolded o_def, standard]
|
|
116 |
|
|
117 |
|
|
118 |
locale td_ext = type_definition +
|
|
119 |
fixes norm
|
|
120 |
assumes eq_norm: "\<And>x. Rep (Abs x) = norm x"
|
|
121 |
begin
|
|
122 |
|
|
123 |
lemma Abs_norm [simp]:
|
|
124 |
"Abs (norm x) = Abs x"
|
|
125 |
using eq_norm [of x] by (auto elim: Rep_inverse')
|
|
126 |
|
|
127 |
lemma td_th:
|
|
128 |
"g o Abs = f ==> f (Rep x) = g x"
|
|
129 |
by (drule comp_Abs_inverse [symmetric]) simp
|
|
130 |
|
|
131 |
lemma eq_norm': "Rep o Abs = norm"
|
|
132 |
by (auto simp: eq_norm intro!: ext)
|
|
133 |
|
|
134 |
lemma norm_Rep [simp]: "norm (Rep x) = Rep x"
|
|
135 |
by (auto simp: eq_norm' intro: td_th)
|
|
136 |
|
|
137 |
lemmas td = td_thm
|
|
138 |
|
|
139 |
lemma set_iff_norm: "w : A <-> w = norm w"
|
|
140 |
by (auto simp: set_Rep_Abs eq_norm' eq_norm [symmetric])
|
|
141 |
|
|
142 |
lemma inverse_norm:
|
|
143 |
"(Abs n = w) = (Rep w = norm n)"
|
|
144 |
apply (rule iffI)
|
|
145 |
apply (clarsimp simp add: eq_norm)
|
|
146 |
apply (simp add: eq_norm' [symmetric])
|
|
147 |
done
|
|
148 |
|
|
149 |
lemma norm_eq_iff:
|
|
150 |
"(norm x = norm y) = (Abs x = Abs y)"
|
|
151 |
by (simp add: eq_norm' [symmetric])
|
|
152 |
|
|
153 |
lemma norm_comps:
|
|
154 |
"Abs o norm = Abs"
|
|
155 |
"norm o Rep = Rep"
|
|
156 |
"norm o norm = norm"
|
|
157 |
by (auto simp: eq_norm' [symmetric] o_def)
|
|
158 |
|
|
159 |
lemmas norm_norm [simp] = norm_comps
|
|
160 |
|
|
161 |
lemma fns5:
|
|
162 |
"Rep o fa o Abs = fr ==>
|
|
163 |
fr o norm = fr & norm o fr = fr"
|
|
164 |
by (fold eq_norm') (auto intro!: ext)
|
|
165 |
|
|
166 |
(* following give conditions for converses to td_fns1
|
|
167 |
the condition (norm o fr o norm = fr o norm) says that
|
|
168 |
fr takes normalised arguments to normalised results,
|
|
169 |
(norm o fr o norm = norm o fr) says that fr
|
|
170 |
takes norm-equivalent arguments to norm-equivalent results,
|
|
171 |
(fr o norm = fr) says that fr
|
|
172 |
takes norm-equivalent arguments to the same result, and
|
|
173 |
(norm o fr = fr) says that fr takes any argument to a normalised result
|
|
174 |
*)
|
|
175 |
lemma fns2:
|
|
176 |
"Abs o fr o Rep = fa ==>
|
|
177 |
(norm o fr o norm = fr o norm) = (Rep o fa = fr o Rep)"
|
|
178 |
apply (fold eq_norm')
|
|
179 |
apply safe
|
|
180 |
prefer 2
|
|
181 |
apply (simp add: o_assoc)
|
|
182 |
apply (rule ext)
|
|
183 |
apply (drule_tac x="Rep x" in fun_cong)
|
|
184 |
apply auto
|
|
185 |
done
|
|
186 |
|
|
187 |
lemma fns3:
|
|
188 |
"Abs o fr o Rep = fa ==>
|
|
189 |
(norm o fr o norm = norm o fr) = (fa o Abs = Abs o fr)"
|
|
190 |
apply (fold eq_norm')
|
|
191 |
apply safe
|
|
192 |
prefer 2
|
|
193 |
apply (simp add: o_assoc [symmetric])
|
|
194 |
apply (rule ext)
|
|
195 |
apply (drule fun_cong)
|
|
196 |
apply simp
|
|
197 |
done
|
|
198 |
|
|
199 |
lemma fns:
|
|
200 |
"fr o norm = norm o fr ==>
|
|
201 |
(fa o Abs = Abs o fr) = (Rep o fa = fr o Rep)"
|
|
202 |
apply safe
|
|
203 |
apply (frule fns1b)
|
|
204 |
prefer 2
|
|
205 |
apply (frule fns1a)
|
|
206 |
apply (rule fns3 [THEN iffD1])
|
|
207 |
prefer 3
|
|
208 |
apply (rule fns2 [THEN iffD1])
|
|
209 |
apply (simp_all add: o_assoc [symmetric])
|
|
210 |
apply (simp_all add: o_assoc)
|
|
211 |
done
|
|
212 |
|
|
213 |
lemma range_norm:
|
|
214 |
"range (Rep o Abs) = A"
|
|
215 |
by (simp add: set_Rep_Abs)
|
|
216 |
|
|
217 |
end
|
|
218 |
|
|
219 |
lemmas td_ext_def' =
|
|
220 |
td_ext_def [unfolded type_definition_def td_ext_axioms_def]
|
|
221 |
|
|
222 |
end
|
|
223 |
|