1478
|
1 |
(* Title: Residuals.thy
|
1048
|
2 |
ID: $Id$
|
1478
|
3 |
Author: Ole Rasmussen
|
1048
|
4 |
Copyright 1995 University of Cambridge
|
|
5 |
Logic Image: ZF
|
|
6 |
|
|
7 |
*)
|
|
8 |
|
12593
|
9 |
theory Residuals = Substitution:
|
1048
|
10 |
|
|
11 |
consts
|
12593
|
12 |
Sres :: "i"
|
|
13 |
residuals :: "[i,i,i]=>i"
|
|
14 |
"|>" :: "[i,i]=>i" (infixl 70)
|
|
15 |
|
1048
|
16 |
translations
|
12593
|
17 |
"residuals(u,v,w)" == "<u,v,w> \<in> Sres"
|
1048
|
18 |
|
|
19 |
inductive
|
|
20 |
domains "Sres" <= "redexes*redexes*redexes"
|
12593
|
21 |
intros
|
|
22 |
Res_Var: "n \<in> nat ==> residuals(Var(n),Var(n),Var(n))"
|
|
23 |
Res_Fun: "[|residuals(u,v,w)|]==>
|
1478
|
24 |
residuals(Fun(u),Fun(v),Fun(w))"
|
12593
|
25 |
Res_App: "[|residuals(u1,v1,w1);
|
|
26 |
residuals(u2,v2,w2); b \<in> bool|]==>
|
1478
|
27 |
residuals(App(b,u1,u2),App(0,v1,v2),App(b,w1,w2))"
|
12593
|
28 |
Res_redex: "[|residuals(u1,v1,w1);
|
|
29 |
residuals(u2,v2,w2); b \<in> bool|]==>
|
1478
|
30 |
residuals(App(b,Fun(u1),u2),App(1,Fun(v1),v2),w2/w1)"
|
12593
|
31 |
type_intros subst_type nat_typechecks redexes.intros bool_typechecks
|
|
32 |
|
|
33 |
defs
|
|
34 |
res_func_def: "u |> v == THE w. residuals(u,v,w)"
|
|
35 |
|
|
36 |
|
|
37 |
(* ------------------------------------------------------------------------- *)
|
|
38 |
(* Setting up rule lists *)
|
|
39 |
(* ------------------------------------------------------------------------- *)
|
|
40 |
|
|
41 |
declare Sres.intros [intro]
|
|
42 |
declare Sreg.intros [intro]
|
|
43 |
declare subst_type [intro]
|
|
44 |
|
|
45 |
inductive_cases [elim!]: "residuals(Var(n),Var(n),v)"
|
|
46 |
inductive_cases [elim!]: "residuals(Fun(t),Fun(u),v)"
|
|
47 |
inductive_cases [elim!]: "residuals(App(b, u1, u2), App(0, v1, v2),v)"
|
|
48 |
inductive_cases [elim!]: "residuals(App(b, u1, u2), App(1, Fun(v1), v2),v)"
|
|
49 |
inductive_cases [elim!]: "residuals(Var(n),u,v)"
|
|
50 |
inductive_cases [elim!]: "residuals(Fun(t),u,v)"
|
|
51 |
inductive_cases [elim!]: "residuals(App(b, u1, u2), w,v)"
|
|
52 |
inductive_cases [elim!]: "residuals(u,Var(n),v)"
|
|
53 |
inductive_cases [elim!]: "residuals(u,Fun(t),v)"
|
|
54 |
inductive_cases [elim!]: "residuals(w,App(b, u1, u2),v)"
|
|
55 |
|
|
56 |
|
|
57 |
inductive_cases [elim!]: "Var(n) <== u"
|
|
58 |
inductive_cases [elim!]: "Fun(n) <== u"
|
|
59 |
inductive_cases [elim!]: "u <== Fun(n)"
|
|
60 |
inductive_cases [elim!]: "App(1,Fun(t),a) <== u"
|
|
61 |
inductive_cases [elim!]: "App(0,t,a) <== u"
|
|
62 |
|
|
63 |
inductive_cases [elim!]: "Fun(t):redexes"
|
|
64 |
|
|
65 |
declare Sres.intros [simp]
|
|
66 |
|
|
67 |
|
|
68 |
(* ------------------------------------------------------------------------- *)
|
|
69 |
(* residuals is a partial function *)
|
|
70 |
(* ------------------------------------------------------------------------- *)
|
|
71 |
|
|
72 |
lemma residuals_function [rule_format]:
|
|
73 |
"residuals(u,v,w) ==> \<forall>w1. residuals(u,v,w1) --> w1 = w"
|
|
74 |
by (erule Sres.induct, force+)
|
|
75 |
|
|
76 |
lemma residuals_intro [rule_format]:
|
|
77 |
"u~v ==> regular(v) --> (\<exists>w. residuals(u,v,w))"
|
|
78 |
by (erule Scomp.induct, force+)
|
|
79 |
|
|
80 |
lemma comp_resfuncD:
|
|
81 |
"[| u~v; regular(v) |] ==> residuals(u, v, THE w. residuals(u, v, w))"
|
|
82 |
apply (frule residuals_intro, assumption)
|
|
83 |
apply clarify
|
|
84 |
apply (subst the_equality)
|
|
85 |
apply (blast intro: residuals_function)+
|
|
86 |
done
|
|
87 |
|
|
88 |
|
|
89 |
(* ------------------------------------------------------------------------- *)
|
|
90 |
(* Residual function *)
|
|
91 |
(* ------------------------------------------------------------------------- *)
|
|
92 |
|
|
93 |
lemma res_Var [simp]: "n \<in> nat ==> Var(n) |> Var(n) = Var(n)"
|
|
94 |
by (unfold res_func_def, blast)
|
|
95 |
|
|
96 |
lemma res_Fun [simp]:
|
|
97 |
"[|s~t; regular(t)|]==> Fun(s) |> Fun(t) = Fun(s |> t)"
|
|
98 |
apply (unfold res_func_def)
|
|
99 |
apply (blast intro: comp_resfuncD residuals_function)
|
|
100 |
done
|
|
101 |
|
|
102 |
lemma res_App [simp]:
|
|
103 |
"[|s~u; regular(u); t~v; regular(v); b \<in> bool|]
|
|
104 |
==> App(b,s,t) |> App(0,u,v) = App(b, s |> u, t |> v)"
|
|
105 |
apply (unfold res_func_def)
|
|
106 |
apply (blast dest!: comp_resfuncD intro: residuals_function)
|
|
107 |
done
|
|
108 |
|
|
109 |
lemma res_redex [simp]:
|
|
110 |
"[|s~u; regular(u); t~v; regular(v); b \<in> bool|]
|
|
111 |
==> App(b,Fun(s),t) |> App(1,Fun(u),v) = (t |> v)/ (s |> u)"
|
|
112 |
apply (unfold res_func_def)
|
|
113 |
apply (blast elim!: redexes.free_elims dest!: comp_resfuncD
|
|
114 |
intro: residuals_function)
|
|
115 |
done
|
|
116 |
|
|
117 |
lemma resfunc_type [simp]:
|
|
118 |
"[|s~t; regular(t)|]==> regular(t) --> s |> t \<in> redexes"
|
|
119 |
apply (erule Scomp.induct)
|
|
120 |
apply auto
|
|
121 |
apply (drule_tac psi = "Fun (?u) |> ?v \<in> redexes" in asm_rl)
|
|
122 |
apply auto
|
|
123 |
done
|
|
124 |
|
|
125 |
(* ------------------------------------------------------------------------- *)
|
|
126 |
(* Commutation theorem *)
|
|
127 |
(* ------------------------------------------------------------------------- *)
|
|
128 |
|
|
129 |
lemma sub_comp [simp]: "u<==v ==> u~v"
|
|
130 |
by (erule Ssub.induct, simp_all)
|
|
131 |
|
|
132 |
lemma sub_preserve_reg [rule_format, simp]:
|
|
133 |
"u<==v ==> regular(v) --> regular(u)"
|
|
134 |
by (erule Ssub.induct, auto)
|
1048
|
135 |
|
12593
|
136 |
lemma residuals_lift_rec: "[|u~v; k \<in> nat|]==> regular(v)--> (\<forall>n \<in> nat.
|
|
137 |
lift_rec(u,n) |> lift_rec(v,n) = lift_rec(u |> v,n))"
|
|
138 |
apply (erule Scomp.induct)
|
|
139 |
apply safe
|
|
140 |
apply (simp_all add: lift_rec_Var subst_Var lift_subst)
|
|
141 |
apply (rotate_tac -2)
|
|
142 |
apply simp
|
|
143 |
done
|
|
144 |
|
|
145 |
lemma residuals_subst_rec:
|
|
146 |
"u1~u2 ==> \<forall>v1 v2. v1~v2 --> regular(v2) --> regular(u2) -->
|
|
147 |
(\<forall>n \<in> nat. subst_rec(v1,u1,n) |> subst_rec(v2,u2,n) =
|
|
148 |
subst_rec(v1 |> v2, u1 |> u2,n))"
|
|
149 |
apply (erule Scomp.induct)
|
|
150 |
apply safe
|
|
151 |
apply (simp_all add: lift_rec_Var subst_Var residuals_lift_rec)
|
|
152 |
apply (drule_tac psi = "\<forall>x.?P (x) " in asm_rl)
|
|
153 |
apply (simp add: substitution)
|
|
154 |
done
|
|
155 |
|
|
156 |
|
|
157 |
lemma commutation [simp]:
|
|
158 |
"[|u1~u2; v1~v2; regular(u2); regular(v2)|]
|
|
159 |
==> (v1/u1) |> (v2/u2) = (v1 |> v2)/(u1 |> u2)"
|
|
160 |
by (simp add: residuals_subst_rec)
|
|
161 |
|
|
162 |
|
|
163 |
(* ------------------------------------------------------------------------- *)
|
|
164 |
(* Residuals are comp and regular *)
|
|
165 |
(* ------------------------------------------------------------------------- *)
|
|
166 |
|
|
167 |
lemma residuals_preserve_comp [rule_format, simp]:
|
|
168 |
"u~v ==> \<forall>w. u~w --> v~w --> regular(w) --> (u|>w) ~ (v|>w)"
|
|
169 |
by (erule Scomp.induct, force+)
|
|
170 |
|
|
171 |
lemma residuals_preserve_reg [rule_format, simp]:
|
|
172 |
"u~v ==> regular(u) --> regular(v) --> regular(u|>v)"
|
|
173 |
apply (erule Scomp.induct)
|
|
174 |
apply auto
|
|
175 |
apply (drule_tac psi = "regular (Fun (?u) |> ?v)" in asm_rl, force)+
|
|
176 |
done
|
|
177 |
|
|
178 |
(* ------------------------------------------------------------------------- *)
|
|
179 |
(* Preservation lemma *)
|
|
180 |
(* ------------------------------------------------------------------------- *)
|
|
181 |
|
|
182 |
lemma union_preserve_comp: "u~v ==> v ~ (u un v)"
|
|
183 |
by (erule Scomp.induct, simp_all)
|
|
184 |
|
|
185 |
lemma preservation [rule_format]:
|
|
186 |
"u ~ v ==> regular(v) --> u|>v = (u un v)|>v"
|
|
187 |
apply (erule Scomp.induct)
|
|
188 |
apply safe
|
|
189 |
apply (drule_tac [3] psi = "Fun (?u) |> ?v = ?w" in asm_rl)
|
|
190 |
apply (auto simp add: union_preserve_comp comp_sym_iff)
|
|
191 |
done
|
|
192 |
|
|
193 |
|
|
194 |
(**** And now the Cube ***)
|
|
195 |
|
|
196 |
declare sub_comp [THEN comp_sym, simp]
|
|
197 |
|
|
198 |
(* ------------------------------------------------------------------------- *)
|
|
199 |
(* Prism theorem *)
|
|
200 |
(* ============= *)
|
|
201 |
(* ------------------------------------------------------------------------- *)
|
|
202 |
|
|
203 |
(* Having more assumptions than needed -- removed below *)
|
|
204 |
lemma prism_l [rule_format]:
|
|
205 |
"v<==u ==>
|
|
206 |
regular(u) --> (\<forall>w. w~v --> w~u -->
|
|
207 |
w |> u = (w|>v) |> (u|>v))"
|
|
208 |
apply (erule Ssub.induct)
|
|
209 |
apply force+
|
|
210 |
done
|
|
211 |
|
|
212 |
lemma prism:
|
|
213 |
"[|v <== u; regular(u); w~v|] ==> w |> u = (w|>v) |> (u|>v)"
|
|
214 |
apply (rule prism_l)
|
|
215 |
apply (rule_tac [4] comp_trans)
|
|
216 |
apply auto
|
|
217 |
done
|
|
218 |
|
|
219 |
|
|
220 |
(* ------------------------------------------------------------------------- *)
|
|
221 |
(* Levy's Cube Lemma *)
|
|
222 |
(* ------------------------------------------------------------------------- *)
|
|
223 |
|
|
224 |
lemma cube: "[|u~v; regular(v); regular(u); w~u|]==>
|
|
225 |
(w|>u) |> (v|>u) = (w|>v) |> (u|>v)"
|
|
226 |
apply (subst preservation , assumption , assumption)
|
|
227 |
apply (subst preservation , erule comp_sym , assumption)
|
|
228 |
apply (subst prism [symmetric])
|
|
229 |
apply (simp add: union_r comp_sym_iff)
|
|
230 |
apply (simp add: union_preserve_regular comp_sym_iff)
|
|
231 |
apply (erule comp_trans)
|
|
232 |
apply assumption
|
|
233 |
apply (simp add: prism [symmetric] union_l union_preserve_regular
|
|
234 |
comp_sym_iff union_sym)
|
|
235 |
done
|
|
236 |
|
|
237 |
|
|
238 |
(* ------------------------------------------------------------------------- *)
|
|
239 |
(* paving theorem *)
|
|
240 |
(* ------------------------------------------------------------------------- *)
|
|
241 |
|
|
242 |
lemma paving: "[|w~u; w~v; regular(u); regular(v)|]==>
|
|
243 |
\<exists>uv vu. (w|>u) |> vu = (w|>v) |> uv & (w|>u)~vu &
|
|
244 |
regular(vu) & (w|>v)~uv & regular(uv) "
|
|
245 |
apply (subgoal_tac "u~v")
|
|
246 |
apply (safe intro!: exI)
|
|
247 |
apply (rule cube)
|
|
248 |
apply (simp_all add: comp_sym_iff)
|
|
249 |
apply (blast intro: residuals_preserve_comp comp_trans comp_sym)+
|
|
250 |
done
|
|
251 |
|
|
252 |
|
1048
|
253 |
end
|
|
254 |
|