10213
|
1 |
(* Title: HOL/Product_Type.ML
|
|
2 |
ID: $Id$
|
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory
|
|
4 |
Copyright 1991 University of Cambridge
|
|
5 |
|
|
6 |
Ordered Pairs, the Cartesian product type, the unit type
|
|
7 |
*)
|
|
8 |
|
|
9 |
(** unit **)
|
|
10 |
|
|
11 |
Goalw [Unity_def]
|
|
12 |
"u = ()";
|
|
13 |
by (stac (rewrite_rule [unit_def] Rep_unit RS singletonD RS sym) 1);
|
|
14 |
by (rtac (Rep_unit_inverse RS sym) 1);
|
|
15 |
qed "unit_eq";
|
|
16 |
|
|
17 |
(*simplification procedure for unit_eq.
|
|
18 |
Cannot use this rule directly -- it loops!*)
|
|
19 |
local
|
|
20 |
val unit_pat = Thm.cterm_of (Theory.sign_of (the_context ())) (Free ("x", HOLogic.unitT));
|
|
21 |
val unit_meta_eq = standard (mk_meta_eq unit_eq);
|
|
22 |
fun proc _ _ t =
|
|
23 |
if HOLogic.is_unit t then None
|
|
24 |
else Some unit_meta_eq;
|
|
25 |
in
|
|
26 |
val unit_eq_proc = Simplifier.mk_simproc "unit_eq" [unit_pat] proc;
|
|
27 |
end;
|
|
28 |
|
|
29 |
Addsimprocs [unit_eq_proc];
|
|
30 |
|
|
31 |
Goal "(!!x::unit. PROP P x) == PROP P ()";
|
|
32 |
by (Simp_tac 1);
|
|
33 |
qed "unit_all_eq1";
|
|
34 |
|
|
35 |
Goal "(!!x::unit. PROP P) == PROP P";
|
|
36 |
by (rtac triv_forall_equality 1);
|
|
37 |
qed "unit_all_eq2";
|
|
38 |
|
|
39 |
Goal "P () ==> P x";
|
|
40 |
by (Simp_tac 1);
|
|
41 |
qed "unit_induct";
|
|
42 |
|
|
43 |
(*This rewrite counters the effect of unit_eq_proc on (%u::unit. f u),
|
|
44 |
replacing it by f rather than by %u.f(). *)
|
|
45 |
Goal "(%u::unit. f()) = f";
|
|
46 |
by (rtac ext 1);
|
|
47 |
by (Simp_tac 1);
|
|
48 |
qed "unit_abs_eta_conv";
|
|
49 |
Addsimps [unit_abs_eta_conv];
|
|
50 |
|
|
51 |
|
|
52 |
(** prod **)
|
|
53 |
|
|
54 |
Goalw [Prod_def] "Pair_Rep a b : Prod";
|
|
55 |
by (EVERY1 [rtac CollectI, rtac exI, rtac exI, rtac refl]);
|
|
56 |
qed "ProdI";
|
|
57 |
|
|
58 |
Goalw [Pair_Rep_def] "Pair_Rep a b = Pair_Rep a' b' ==> a=a' & b=b'";
|
|
59 |
by (dtac (fun_cong RS fun_cong) 1);
|
|
60 |
by (Blast_tac 1);
|
|
61 |
qed "Pair_Rep_inject";
|
|
62 |
|
|
63 |
Goal "inj_on Abs_Prod Prod";
|
|
64 |
by (rtac inj_on_inverseI 1);
|
|
65 |
by (etac Abs_Prod_inverse 1);
|
|
66 |
qed "inj_on_Abs_Prod";
|
|
67 |
|
|
68 |
val prems = Goalw [Pair_def]
|
|
69 |
"[| (a, b) = (a',b'); [| a=a'; b=b' |] ==> R |] ==> R";
|
|
70 |
by (rtac (inj_on_Abs_Prod RS inj_onD RS Pair_Rep_inject RS conjE) 1);
|
|
71 |
by (REPEAT (ares_tac (prems@[ProdI]) 1));
|
|
72 |
qed "Pair_inject";
|
|
73 |
|
|
74 |
Goal "((a,b) = (a',b')) = (a=a' & b=b')";
|
|
75 |
by (blast_tac (claset() addSEs [Pair_inject]) 1);
|
|
76 |
qed "Pair_eq";
|
|
77 |
AddIffs [Pair_eq];
|
|
78 |
|
|
79 |
Goalw [fst_def] "fst (a,b) = a";
|
|
80 |
by (Blast_tac 1);
|
|
81 |
qed "fst_conv";
|
|
82 |
Goalw [snd_def] "snd (a,b) = b";
|
|
83 |
by (Blast_tac 1);
|
|
84 |
qed "snd_conv";
|
|
85 |
Addsimps [fst_conv, snd_conv];
|
|
86 |
|
|
87 |
Goal "fst (x, y) = a ==> x = a";
|
|
88 |
by (Asm_full_simp_tac 1);
|
|
89 |
qed "fst_eqD";
|
|
90 |
Goal "snd (x, y) = a ==> y = a";
|
|
91 |
by (Asm_full_simp_tac 1);
|
|
92 |
qed "snd_eqD";
|
|
93 |
|
|
94 |
Goalw [Pair_def] "? x y. p = (x,y)";
|
|
95 |
by (rtac (rewrite_rule [Prod_def] Rep_Prod RS CollectE) 1);
|
|
96 |
by (EVERY1[etac exE, etac exE, rtac exI, rtac exI,
|
|
97 |
rtac (Rep_Prod_inverse RS sym RS trans), etac arg_cong]);
|
|
98 |
qed "PairE_lemma";
|
|
99 |
|
|
100 |
val [prem] = Goal "[| !!x y. p = (x,y) ==> Q |] ==> Q";
|
|
101 |
by (rtac (PairE_lemma RS exE) 1);
|
|
102 |
by (REPEAT (eresolve_tac [prem,exE] 1));
|
|
103 |
qed "PairE";
|
|
104 |
|
|
105 |
fun pair_tac s = EVERY' [res_inst_tac [("p",s)] PairE, hyp_subst_tac,
|
|
106 |
K prune_params_tac];
|
|
107 |
|
|
108 |
(* Do not add as rewrite rule: invalidates some proofs in IMP *)
|
|
109 |
Goal "p = (fst(p),snd(p))";
|
|
110 |
by (pair_tac "p" 1);
|
|
111 |
by (Asm_simp_tac 1);
|
|
112 |
qed "surjective_pairing";
|
|
113 |
Addsimps [surjective_pairing RS sym];
|
|
114 |
|
|
115 |
Goal "? x y. z = (x, y)";
|
|
116 |
by (rtac exI 1);
|
|
117 |
by (rtac exI 1);
|
|
118 |
by (rtac surjective_pairing 1);
|
|
119 |
qed "surj_pair";
|
|
120 |
Addsimps [surj_pair];
|
|
121 |
|
|
122 |
|
|
123 |
bind_thm ("split_paired_all",
|
|
124 |
SplitPairedAll.rule (standard (surjective_pairing RS eq_reflection)));
|
|
125 |
bind_thms ("split_tupled_all", [split_paired_all, unit_all_eq2]);
|
|
126 |
|
|
127 |
(*
|
|
128 |
Addsimps [split_paired_all] does not work with simplifier
|
|
129 |
because it also affects premises in congrence rules,
|
|
130 |
where is can lead to premises of the form !!a b. ... = ?P(a,b)
|
|
131 |
which cannot be solved by reflexivity.
|
|
132 |
*)
|
|
133 |
|
|
134 |
(* replace parameters of product type by individual component parameters *)
|
|
135 |
local
|
10813
|
136 |
fun exists_paired_all (Const ("all", _) $ Abs (_, T, t)) =
|
|
137 |
can HOLogic.dest_prodT T orelse exists_paired_all t
|
|
138 |
| exists_paired_all (t $ u) = exists_paired_all t orelse exists_paired_all u
|
|
139 |
| exists_paired_all (Abs (_, _, t)) = exists_paired_all t
|
|
140 |
| exists_paired_all _ = false;
|
10829
|
141 |
val ss = HOL_basic_ss
|
|
142 |
addsimps [split_paired_all, unit_all_eq2, unit_abs_eta_conv]
|
|
143 |
addsimprocs [unit_eq_proc];
|
10213
|
144 |
in
|
10813
|
145 |
val split_all_tac = SUBGOAL (fn (t, i) =>
|
10829
|
146 |
if exists_paired_all t then full_simp_tac ss i else no_tac);
|
|
147 |
fun split_all th =
|
|
148 |
if exists_paired_all (#prop (Thm.rep_thm th)) then full_simplify ss th else th;
|
10213
|
149 |
end;
|
|
150 |
|
|
151 |
claset_ref() := claset()
|
|
152 |
addSWrapper ("split_all_tac", fn tac2 => split_all_tac ORELSE' tac2);
|
|
153 |
|
|
154 |
Goal "(!x. P x) = (!a b. P(a,b))";
|
|
155 |
by (Fast_tac 1);
|
|
156 |
qed "split_paired_All";
|
|
157 |
Addsimps [split_paired_All];
|
|
158 |
(* AddIffs is not a good idea because it makes Blast_tac loop *)
|
|
159 |
|
|
160 |
bind_thm ("prod_induct",
|
|
161 |
allI RS (allI RS (split_paired_All RS iffD2)) RS spec);
|
|
162 |
|
|
163 |
Goal "(? x. P x) = (? a b. P(a,b))";
|
|
164 |
by (Fast_tac 1);
|
|
165 |
qed "split_paired_Ex";
|
|
166 |
Addsimps [split_paired_Ex];
|
|
167 |
|
|
168 |
Goalw [split_def] "split c (a,b) = c a b";
|
|
169 |
by (Simp_tac 1);
|
|
170 |
qed "split";
|
|
171 |
Addsimps [split];
|
|
172 |
|
|
173 |
(*Subsumes the old split_Pair when f is the identity function*)
|
|
174 |
Goal "split (%x y. f(x,y)) = f";
|
|
175 |
by (rtac ext 1);
|
|
176 |
by (pair_tac "x" 1);
|
|
177 |
by (Simp_tac 1);
|
|
178 |
qed "split_Pair_apply";
|
|
179 |
|
|
180 |
(*Can't be added to simpset: loops!*)
|
|
181 |
Goal "(SOME x. P x) = (SOME (a,b). P(a,b))";
|
|
182 |
by (simp_tac (simpset() addsimps [split_Pair_apply]) 1);
|
|
183 |
qed "split_paired_Eps";
|
|
184 |
|
|
185 |
Goal "!!s t. (s=t) = (fst(s)=fst(t) & snd(s)=snd(t))";
|
|
186 |
by (split_all_tac 1);
|
|
187 |
by (Asm_simp_tac 1);
|
|
188 |
qed "Pair_fst_snd_eq";
|
|
189 |
|
|
190 |
Goal "fst p = fst q ==> snd p = snd q ==> p = q";
|
|
191 |
by (asm_simp_tac (simpset() addsimps [Pair_fst_snd_eq]) 1);
|
|
192 |
qed "prod_eqI";
|
|
193 |
AddXIs [prod_eqI];
|
|
194 |
|
|
195 |
(*Prevents simplification of c: much faster*)
|
|
196 |
Goal "p=q ==> split c p = split c q";
|
|
197 |
by (etac arg_cong 1);
|
|
198 |
qed "split_weak_cong";
|
|
199 |
|
|
200 |
Goal "(%(x,y). f(x,y)) = f";
|
|
201 |
by (rtac ext 1);
|
|
202 |
by (split_all_tac 1);
|
|
203 |
by (rtac split 1);
|
|
204 |
qed "split_eta";
|
|
205 |
|
|
206 |
val prems = Goal "(!!x y. f x y = g(x,y)) ==> (%(x,y). f x y) = g";
|
|
207 |
by (asm_simp_tac (simpset() addsimps prems@[split_eta]) 1);
|
|
208 |
qed "cond_split_eta";
|
|
209 |
|
|
210 |
(*simplification procedure for cond_split_eta.
|
|
211 |
using split_eta a rewrite rule is not general enough, and using
|
|
212 |
cond_split_eta directly would render some existing proofs very inefficient.
|
|
213 |
similarly for split_beta. *)
|
|
214 |
local
|
|
215 |
fun Pair_pat k 0 (Bound m) = (m = k)
|
|
216 |
| Pair_pat k i (Const ("Pair", _) $ Bound m $ t) = i > 0 andalso
|
|
217 |
m = k+i andalso Pair_pat k (i-1) t
|
|
218 |
| Pair_pat _ _ _ = false;
|
|
219 |
fun no_args k i (Abs (_, _, t)) = no_args (k+1) i t
|
|
220 |
| no_args k i (t $ u) = no_args k i t andalso no_args k i u
|
|
221 |
| no_args k i (Bound m) = m < k orelse m > k+i
|
|
222 |
| no_args _ _ _ = true;
|
|
223 |
fun split_pat tp i (Abs (_,_,t)) = if tp 0 i t then Some (i,t) else None
|
|
224 |
| split_pat tp i (Const ("split", _) $ Abs (_, _, t)) = split_pat tp (i+1) t
|
|
225 |
| split_pat tp i _ = None;
|
|
226 |
fun metaeq sg lhs rhs = mk_meta_eq (prove_goalw_cterm []
|
|
227 |
(cterm_of sg (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs,rhs))))
|
|
228 |
(K [simp_tac (HOL_basic_ss addsimps [cond_split_eta]) 1]));
|
|
229 |
val sign = sign_of (the_context ());
|
|
230 |
fun simproc name patstr = Simplifier.mk_simproc name
|
|
231 |
[Thm.read_cterm sign (patstr, HOLogic.termT)];
|
|
232 |
|
|
233 |
val beta_patstr = "split f z";
|
|
234 |
val eta_patstr = "split f";
|
|
235 |
fun beta_term_pat k i (Abs (_, _, t)) = beta_term_pat (k+1) i t
|
|
236 |
| beta_term_pat k i (t $ u) = Pair_pat k i (t $ u) orelse
|
|
237 |
(beta_term_pat k i t andalso beta_term_pat k i u)
|
|
238 |
| beta_term_pat k i t = no_args k i t;
|
|
239 |
fun eta_term_pat k i (f $ arg) = no_args k i f andalso Pair_pat k i arg
|
|
240 |
| eta_term_pat _ _ _ = false;
|
|
241 |
fun subst arg k i (Abs (x, T, t)) = Abs (x, T, subst arg (k+1) i t)
|
|
242 |
| subst arg k i (t $ u) = if Pair_pat k i (t $ u) then incr_boundvars k arg
|
|
243 |
else (subst arg k i t $ subst arg k i u)
|
|
244 |
| subst arg k i t = t;
|
|
245 |
fun beta_proc sg _ (s as Const ("split", _) $ Abs (_, _, t) $ arg) =
|
|
246 |
(case split_pat beta_term_pat 1 t of
|
|
247 |
Some (i,f) => Some (metaeq sg s (subst arg 0 i f))
|
|
248 |
| None => None)
|
|
249 |
| beta_proc _ _ _ = None;
|
|
250 |
fun eta_proc sg _ (s as Const ("split", _) $ Abs (_, _, t)) =
|
|
251 |
(case split_pat eta_term_pat 1 t of
|
|
252 |
Some (_,ft) => Some (metaeq sg s (let val (f $ arg) = ft in f end))
|
|
253 |
| None => None)
|
|
254 |
| eta_proc _ _ _ = None;
|
|
255 |
in
|
|
256 |
val split_beta_proc = simproc "split_beta" beta_patstr beta_proc;
|
|
257 |
val split_eta_proc = simproc "split_eta" eta_patstr eta_proc;
|
|
258 |
end;
|
|
259 |
|
|
260 |
Addsimprocs [split_beta_proc,split_eta_proc];
|
|
261 |
|
|
262 |
Goal "(%(x,y). P x y) z = P (fst z) (snd z)";
|
|
263 |
by (stac surjective_pairing 1 THEN rtac split 1);
|
|
264 |
qed "split_beta";
|
|
265 |
|
|
266 |
(*For use with split_tac and the simplifier*)
|
|
267 |
Goal "R (split c p) = (! x y. p = (x,y) --> R (c x y))";
|
|
268 |
by (stac surjective_pairing 1);
|
|
269 |
by (stac split 1);
|
|
270 |
by (Blast_tac 1);
|
|
271 |
qed "split_split";
|
|
272 |
|
|
273 |
(* could be done after split_tac has been speeded up significantly:
|
|
274 |
simpset_ref() := simpset() addsplits [split_split];
|
|
275 |
precompute the constants involved and don't do anything unless
|
|
276 |
the current goal contains one of those constants
|
|
277 |
*)
|
|
278 |
|
|
279 |
Goal "R (split c p) = (~(? x y. p = (x,y) & (~R (c x y))))";
|
|
280 |
by (stac split_split 1);
|
|
281 |
by (Simp_tac 1);
|
10540
|
282 |
qed "split_split_asm";
|
10213
|
283 |
|
|
284 |
(** split used as a logical connective or set former **)
|
|
285 |
|
|
286 |
(*These rules are for use with blast_tac.
|
|
287 |
Could instead call simp_tac/asm_full_simp_tac using split as rewrite.*)
|
|
288 |
|
|
289 |
Goal "!!p. [| !!a b. p=(a,b) ==> c a b |] ==> split c p";
|
|
290 |
by (split_all_tac 1);
|
|
291 |
by (Asm_simp_tac 1);
|
|
292 |
qed "splitI2";
|
|
293 |
|
|
294 |
Goal "!!p. [| !!a b. (a,b)=p ==> c a b x |] ==> split c p x";
|
|
295 |
by (split_all_tac 1);
|
|
296 |
by (Asm_simp_tac 1);
|
|
297 |
qed "splitI2'";
|
|
298 |
|
|
299 |
Goal "c a b ==> split c (a,b)";
|
|
300 |
by (Asm_simp_tac 1);
|
|
301 |
qed "splitI";
|
|
302 |
|
|
303 |
val prems = Goalw [split_def]
|
|
304 |
"[| split c p; !!x y. [| p = (x,y); c x y |] ==> Q |] ==> Q";
|
|
305 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
|
|
306 |
qed "splitE";
|
|
307 |
|
|
308 |
val prems = Goalw [split_def]
|
|
309 |
"[| split c p z; !!x y. [| p = (x,y); c x y z |] ==> Q |] ==> Q";
|
|
310 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
|
|
311 |
qed "splitE'";
|
|
312 |
|
|
313 |
val major::prems = Goal
|
|
314 |
"[| Q (split P z); !!x y. [|z = (x, y); Q (P x y)|] ==> R \
|
|
315 |
\ |] ==> R";
|
|
316 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
|
|
317 |
by (rtac (split_beta RS subst) 1 THEN rtac major 1);
|
|
318 |
qed "splitE2";
|
|
319 |
|
|
320 |
Goal "split R (a,b) ==> R a b";
|
|
321 |
by (etac (split RS iffD1) 1);
|
|
322 |
qed "splitD";
|
|
323 |
|
|
324 |
Goal "z: c a b ==> z: split c (a,b)";
|
|
325 |
by (Asm_simp_tac 1);
|
|
326 |
qed "mem_splitI";
|
|
327 |
|
|
328 |
Goal "!!p. [| !!a b. p=(a,b) ==> z: c a b |] ==> z: split c p";
|
|
329 |
by (split_all_tac 1);
|
|
330 |
by (Asm_simp_tac 1);
|
|
331 |
qed "mem_splitI2";
|
|
332 |
|
|
333 |
val prems = Goalw [split_def]
|
|
334 |
"[| z: split c p; !!x y. [| p = (x,y); z: c x y |] ==> Q |] ==> Q";
|
|
335 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1));
|
|
336 |
qed "mem_splitE";
|
|
337 |
|
|
338 |
AddSIs [splitI, splitI2, splitI2', mem_splitI, mem_splitI2];
|
|
339 |
AddSEs [splitE, splitE', mem_splitE];
|
|
340 |
|
|
341 |
Goal "(%u. ? x y. u = (x, y) & P (x, y)) = P";
|
|
342 |
by (rtac ext 1);
|
|
343 |
by (Fast_tac 1);
|
|
344 |
qed "split_eta_SetCompr";
|
|
345 |
Addsimps [split_eta_SetCompr];
|
|
346 |
|
|
347 |
Goal "(%u. ? x y. u = (x, y) & P x y) = split P";
|
|
348 |
br ext 1;
|
|
349 |
by (Fast_tac 1);
|
|
350 |
qed "split_eta_SetCompr2";
|
|
351 |
Addsimps [split_eta_SetCompr2];
|
|
352 |
|
|
353 |
(* allows simplifications of nested splits in case of independent predicates *)
|
|
354 |
Goal "(%(a,b). P & Q a b) = (%ab. P & split Q ab)";
|
|
355 |
by (rtac ext 1);
|
|
356 |
by (Blast_tac 1);
|
|
357 |
qed "split_part";
|
|
358 |
Addsimps [split_part];
|
|
359 |
|
|
360 |
Goal "(@(x',y'). x = x' & y = y') = (x,y)";
|
|
361 |
by (Blast_tac 1);
|
|
362 |
qed "Eps_split_eq";
|
|
363 |
Addsimps [Eps_split_eq];
|
|
364 |
(*
|
|
365 |
the following would be slightly more general,
|
|
366 |
but cannot be used as rewrite rule:
|
|
367 |
### Cannot add premise as rewrite rule because it contains (type) unknowns:
|
|
368 |
### ?y = .x
|
|
369 |
Goal "[| P y; !!x. P x ==> x = y |] ==> (@(x',y). x = x' & P y) = (x,y)";
|
|
370 |
by (rtac some_equality 1);
|
|
371 |
by ( Simp_tac 1);
|
|
372 |
by (split_all_tac 1);
|
|
373 |
by (Asm_full_simp_tac 1);
|
|
374 |
qed "Eps_split_eq";
|
|
375 |
*)
|
|
376 |
|
|
377 |
(*** prod_fun -- action of the product functor upon functions ***)
|
|
378 |
|
|
379 |
Goalw [prod_fun_def] "prod_fun f g (a,b) = (f(a),g(b))";
|
|
380 |
by (rtac split 1);
|
|
381 |
qed "prod_fun";
|
|
382 |
Addsimps [prod_fun];
|
|
383 |
|
|
384 |
Goal "prod_fun (f1 o f2) (g1 o g2) = ((prod_fun f1 g1) o (prod_fun f2 g2))";
|
|
385 |
by (rtac ext 1);
|
|
386 |
by (pair_tac "x" 1);
|
|
387 |
by (Asm_simp_tac 1);
|
|
388 |
qed "prod_fun_compose";
|
|
389 |
|
|
390 |
Goal "prod_fun (%x. x) (%y. y) = (%z. z)";
|
|
391 |
by (rtac ext 1);
|
|
392 |
by (pair_tac "z" 1);
|
|
393 |
by (Asm_simp_tac 1);
|
|
394 |
qed "prod_fun_ident";
|
|
395 |
Addsimps [prod_fun_ident];
|
|
396 |
|
10832
|
397 |
Goal "(a,b):r ==> (f(a),g(b)) : (prod_fun f g)`r";
|
10213
|
398 |
by (rtac image_eqI 1);
|
|
399 |
by (rtac (prod_fun RS sym) 1);
|
|
400 |
by (assume_tac 1);
|
|
401 |
qed "prod_fun_imageI";
|
|
402 |
|
|
403 |
val major::prems = Goal
|
10832
|
404 |
"[| c: (prod_fun f g)`r; !!x y. [| c=(f(x),g(y)); (x,y):r |] ==> P \
|
10213
|
405 |
\ |] ==> P";
|
|
406 |
by (rtac (major RS imageE) 1);
|
|
407 |
by (res_inst_tac [("p","x")] PairE 1);
|
|
408 |
by (resolve_tac prems 1);
|
|
409 |
by (Blast_tac 2);
|
|
410 |
by (blast_tac (claset() addIs [prod_fun]) 1);
|
|
411 |
qed "prod_fun_imageE";
|
|
412 |
|
|
413 |
AddIs [prod_fun_imageI];
|
|
414 |
AddSEs [prod_fun_imageE];
|
|
415 |
|
|
416 |
|
|
417 |
(*** Disjoint union of a family of sets - Sigma ***)
|
|
418 |
|
|
419 |
Goalw [Sigma_def] "[| a:A; b:B(a) |] ==> (a,b) : Sigma A B";
|
|
420 |
by (REPEAT (ares_tac [singletonI,UN_I] 1));
|
|
421 |
qed "SigmaI";
|
|
422 |
|
|
423 |
AddSIs [SigmaI];
|
|
424 |
|
|
425 |
(*The general elimination rule*)
|
|
426 |
val major::prems = Goalw [Sigma_def]
|
|
427 |
"[| c: Sigma A B; \
|
|
428 |
\ !!x y.[| x:A; y:B(x); c=(x,y) |] ==> P \
|
|
429 |
\ |] ==> P";
|
|
430 |
by (cut_facts_tac [major] 1);
|
|
431 |
by (REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ;
|
|
432 |
qed "SigmaE";
|
|
433 |
|
|
434 |
(** Elimination of (a,b):A*B -- introduces no eigenvariables **)
|
|
435 |
|
|
436 |
Goal "(a,b) : Sigma A B ==> a : A";
|
|
437 |
by (etac SigmaE 1);
|
|
438 |
by (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ;
|
|
439 |
qed "SigmaD1";
|
|
440 |
|
|
441 |
Goal "(a,b) : Sigma A B ==> b : B(a)";
|
|
442 |
by (etac SigmaE 1);
|
|
443 |
by (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ;
|
|
444 |
qed "SigmaD2";
|
|
445 |
|
|
446 |
val [major,minor]= Goal
|
|
447 |
"[| (a,b) : Sigma A B; \
|
|
448 |
\ [| a:A; b:B(a) |] ==> P \
|
|
449 |
\ |] ==> P";
|
|
450 |
by (rtac minor 1);
|
|
451 |
by (rtac (major RS SigmaD1) 1);
|
|
452 |
by (rtac (major RS SigmaD2) 1) ;
|
|
453 |
qed "SigmaE2";
|
|
454 |
|
|
455 |
AddSEs [SigmaE2, SigmaE];
|
|
456 |
|
|
457 |
val prems = Goal
|
|
458 |
"[| A<=C; !!x. x:A ==> B x <= D x |] ==> Sigma A B <= Sigma C D";
|
|
459 |
by (cut_facts_tac prems 1);
|
|
460 |
by (blast_tac (claset() addIs (prems RL [subsetD])) 1);
|
|
461 |
qed "Sigma_mono";
|
|
462 |
|
|
463 |
Goal "Sigma {} B = {}";
|
|
464 |
by (Blast_tac 1) ;
|
|
465 |
qed "Sigma_empty1";
|
|
466 |
|
|
467 |
Goal "A <*> {} = {}";
|
|
468 |
by (Blast_tac 1) ;
|
|
469 |
qed "Sigma_empty2";
|
|
470 |
|
|
471 |
Addsimps [Sigma_empty1,Sigma_empty2];
|
|
472 |
|
|
473 |
Goal "UNIV <*> UNIV = UNIV";
|
|
474 |
by Auto_tac;
|
|
475 |
qed "UNIV_Times_UNIV";
|
|
476 |
Addsimps [UNIV_Times_UNIV];
|
|
477 |
|
|
478 |
Goal "- (UNIV <*> A) = UNIV <*> (-A)";
|
|
479 |
by Auto_tac;
|
|
480 |
qed "Compl_Times_UNIV1";
|
|
481 |
|
|
482 |
Goal "- (A <*> UNIV) = (-A) <*> UNIV";
|
|
483 |
by Auto_tac;
|
|
484 |
qed "Compl_Times_UNIV2";
|
|
485 |
|
|
486 |
Addsimps [Compl_Times_UNIV1, Compl_Times_UNIV2];
|
|
487 |
|
|
488 |
Goal "((a,b): Sigma A B) = (a:A & b:B(a))";
|
|
489 |
by (Blast_tac 1);
|
|
490 |
qed "mem_Sigma_iff";
|
|
491 |
AddIffs [mem_Sigma_iff];
|
|
492 |
|
|
493 |
Goal "x:C ==> (A <*> C <= B <*> C) = (A <= B)";
|
|
494 |
by (Blast_tac 1);
|
|
495 |
qed "Times_subset_cancel2";
|
|
496 |
|
|
497 |
Goal "x:C ==> (A <*> C = B <*> C) = (A = B)";
|
|
498 |
by (blast_tac (claset() addEs [equalityE]) 1);
|
|
499 |
qed "Times_eq_cancel2";
|
|
500 |
|
|
501 |
Goal "Collect (split (%x y. P x & Q x y)) = (SIGMA x:Collect P. Collect (Q x))";
|
|
502 |
by (Fast_tac 1);
|
|
503 |
qed "SetCompr_Sigma_eq";
|
|
504 |
|
|
505 |
(*** Complex rules for Sigma ***)
|
|
506 |
|
|
507 |
Goal "{(a,b). P a & Q b} = Collect P <*> Collect Q";
|
|
508 |
by (Blast_tac 1);
|
|
509 |
qed "Collect_split";
|
|
510 |
|
|
511 |
Addsimps [Collect_split];
|
|
512 |
|
|
513 |
(*Suggested by Pierre Chartier*)
|
|
514 |
Goal "(UN (a,b):(A <*> B). E a <*> F b) = (UNION A E) <*> (UNION B F)";
|
|
515 |
by (Blast_tac 1);
|
|
516 |
qed "UN_Times_distrib";
|
|
517 |
|
|
518 |
Goal "(ALL z: Sigma A B. P z) = (ALL x:A. ALL y: B x. P(x,y))";
|
|
519 |
by (Fast_tac 1);
|
|
520 |
qed "split_paired_Ball_Sigma";
|
|
521 |
Addsimps [split_paired_Ball_Sigma];
|
|
522 |
|
|
523 |
Goal "(EX z: Sigma A B. P z) = (EX x:A. EX y: B x. P(x,y))";
|
|
524 |
by (Fast_tac 1);
|
|
525 |
qed "split_paired_Bex_Sigma";
|
|
526 |
Addsimps [split_paired_Bex_Sigma];
|
|
527 |
|
|
528 |
Goal "(SIGMA i:I Un J. C(i)) = (SIGMA i:I. C(i)) Un (SIGMA j:J. C(j))";
|
|
529 |
by (Blast_tac 1);
|
|
530 |
qed "Sigma_Un_distrib1";
|
|
531 |
|
|
532 |
Goal "(SIGMA i:I. A(i) Un B(i)) = (SIGMA i:I. A(i)) Un (SIGMA i:I. B(i))";
|
|
533 |
by (Blast_tac 1);
|
|
534 |
qed "Sigma_Un_distrib2";
|
|
535 |
|
|
536 |
Goal "(SIGMA i:I Int J. C(i)) = (SIGMA i:I. C(i)) Int (SIGMA j:J. C(j))";
|
|
537 |
by (Blast_tac 1);
|
|
538 |
qed "Sigma_Int_distrib1";
|
|
539 |
|
|
540 |
Goal "(SIGMA i:I. A(i) Int B(i)) = (SIGMA i:I. A(i)) Int (SIGMA i:I. B(i))";
|
|
541 |
by (Blast_tac 1);
|
|
542 |
qed "Sigma_Int_distrib2";
|
|
543 |
|
|
544 |
Goal "(SIGMA i:I - J. C(i)) = (SIGMA i:I. C(i)) - (SIGMA j:J. C(j))";
|
|
545 |
by (Blast_tac 1);
|
|
546 |
qed "Sigma_Diff_distrib1";
|
|
547 |
|
|
548 |
Goal "(SIGMA i:I. A(i) - B(i)) = (SIGMA i:I. A(i)) - (SIGMA i:I. B(i))";
|
|
549 |
by (Blast_tac 1);
|
|
550 |
qed "Sigma_Diff_distrib2";
|
|
551 |
|
|
552 |
Goal "Sigma (Union X) B = (UN A:X. Sigma A B)";
|
|
553 |
by (Blast_tac 1);
|
|
554 |
qed "Sigma_Union";
|
|
555 |
|
|
556 |
(*Non-dependent versions are needed to avoid the need for higher-order
|
|
557 |
matching, especially when the rules are re-oriented*)
|
|
558 |
Goal "(A Un B) <*> C = (A <*> C) Un (B <*> C)";
|
|
559 |
by (Blast_tac 1);
|
|
560 |
qed "Times_Un_distrib1";
|
|
561 |
|
|
562 |
Goal "(A Int B) <*> C = (A <*> C) Int (B <*> C)";
|
|
563 |
by (Blast_tac 1);
|
|
564 |
qed "Times_Int_distrib1";
|
|
565 |
|
|
566 |
Goal "(A - B) <*> C = (A <*> C) - (B <*> C)";
|
|
567 |
by (Blast_tac 1);
|
|
568 |
qed "Times_Diff_distrib1";
|
|
569 |
|
|
570 |
|
|
571 |
(*Attempts to remove occurrences of split, and pair-valued parameters*)
|
10829
|
572 |
val remove_split = rewrite_rule [split RS eq_reflection] o split_all;
|
10213
|
573 |
|
|
574 |
local
|
|
575 |
|
|
576 |
(*In ap_split S T u, term u expects separate arguments for the factors of S,
|
|
577 |
with result type T. The call creates a new term expecting one argument
|
|
578 |
of type S.*)
|
|
579 |
fun ap_split (Type ("*", [T1, T2])) T3 u =
|
|
580 |
HOLogic.split_const (T1, T2, T3) $
|
|
581 |
Abs("v", T1,
|
|
582 |
ap_split T2 T3
|
|
583 |
((ap_split T1 (HOLogic.prodT_factors T2 ---> T3) (incr_boundvars 1 u)) $
|
|
584 |
Bound 0))
|
|
585 |
| ap_split T T3 u = u;
|
|
586 |
|
|
587 |
(*Curries any Var of function type in the rule*)
|
|
588 |
fun split_rule_var' (t as Var (v, Type ("fun", [T1, T2])), rl) =
|
|
589 |
let val T' = HOLogic.prodT_factors T1 ---> T2
|
|
590 |
val newt = ap_split T1 T2 (Var (v, T'))
|
|
591 |
val cterm = Thm.cterm_of (#sign (rep_thm rl))
|
|
592 |
in
|
|
593 |
instantiate ([], [(cterm t, cterm newt)]) rl
|
|
594 |
end
|
|
595 |
| split_rule_var' (t, rl) = rl;
|
|
596 |
|
|
597 |
in
|
|
598 |
|
|
599 |
val split_rule_var = standard o remove_split o split_rule_var';
|
|
600 |
|
|
601 |
(*Curries ALL function variables occurring in a rule's conclusion*)
|
10829
|
602 |
fun split_rule rl = standard (remove_split (foldr split_rule_var' (term_vars (concl_of rl), rl)));
|
10213
|
603 |
|
|
604 |
end;
|