author | clasohm |
Sun, 24 Apr 1994 11:27:38 +0200 | |
changeset 70 | 9459592608e2 |
parent 31 | 04f43a28c97a |
child 73 | 8129641e90ab |
permissions | -rw-r--r-- |
0 | 1 |
(* Title: HOL/prod |
2 |
ID: $Id$ |
|
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1991 University of Cambridge |
|
5 |
||
6 |
For prod.thy. Ordered Pairs, the Cartesian product type, the unit type |
|
7 |
*) |
|
8 |
||
9 |
open Prod; |
|
10 |
||
11 |
(*This counts as a non-emptiness result for admitting 'a * 'b as a type*) |
|
12 |
goalw Prod.thy [Prod_def] "Pair_Rep(a,b) : Prod"; |
|
13 |
by (EVERY1 [rtac CollectI, rtac exI, rtac exI, rtac refl]); |
|
14 |
val ProdI = result(); |
|
15 |
||
16 |
val [major] = goalw Prod.thy [Pair_Rep_def] |
|
17 |
"Pair_Rep(a, b) = Pair_Rep(a',b') ==> a=a' & b=b'"; |
|
18 |
by (EVERY1 [rtac (major RS fun_cong RS fun_cong RS subst), |
|
19 |
rtac conjI, rtac refl, rtac refl]); |
|
20 |
val Pair_Rep_inject = result(); |
|
21 |
||
22 |
goal Prod.thy "inj_onto(Abs_Prod,Prod)"; |
|
23 |
by (rtac inj_onto_inverseI 1); |
|
24 |
by (etac Abs_Prod_inverse 1); |
|
25 |
val inj_onto_Abs_Prod = result(); |
|
26 |
||
27 |
val prems = goalw Prod.thy [Pair_def] |
|
28 |
"[| <a, b> = <a',b'>; [| a=a'; b=b' |] ==> R |] ==> R"; |
|
29 |
by (rtac (inj_onto_Abs_Prod RS inj_ontoD RS Pair_Rep_inject RS conjE) 1); |
|
30 |
by (REPEAT (ares_tac (prems@[ProdI]) 1)); |
|
31 |
val Pair_inject = result(); |
|
32 |
||
33 |
goal Prod.thy "(<a,b> = <a',b'>) = (a=a' & b=b')"; |
|
34 |
by (fast_tac (set_cs addIs [Pair_inject]) 1); |
|
35 |
val Pair_eq = result(); |
|
36 |
||
37 |
goalw Prod.thy [fst_def] "fst(<a,b>) = a"; |
|
38 |
by (fast_tac (set_cs addIs [select_equality] addSEs [Pair_inject]) 1); |
|
39 |
val fst_conv = result(); |
|
40 |
||
41 |
goalw Prod.thy [snd_def] "snd(<a,b>) = b"; |
|
42 |
by (fast_tac (set_cs addIs [select_equality] addSEs [Pair_inject]) 1); |
|
43 |
val snd_conv = result(); |
|
44 |
||
45 |
goalw Prod.thy [Pair_def] "? x y. p = <x,y>"; |
|
46 |
by (rtac (rewrite_rule [Prod_def] Rep_Prod RS CollectE) 1); |
|
47 |
by (EVERY1[etac exE, etac exE, rtac exI, rtac exI, |
|
48 |
rtac (Rep_Prod_inverse RS sym RS trans), etac arg_cong]); |
|
49 |
val PairE_lemma = result(); |
|
50 |
||
51 |
val [prem] = goal Prod.thy "[| !!x y. p = <x,y> ==> Q |] ==> Q"; |
|
52 |
by (rtac (PairE_lemma RS exE) 1); |
|
53 |
by (REPEAT (eresolve_tac [prem,exE] 1)); |
|
54 |
val PairE = result(); |
|
55 |
||
56 |
goalw Prod.thy [split_def] "split(<a,b>, c) = c(a,b)"; |
|
57 |
by (sstac [fst_conv, snd_conv] 1); |
|
58 |
by (rtac refl 1); |
|
59 |
val split = result(); |
|
60 |
||
26 | 61 |
val pair_ss = set_ss addsimps [fst_conv, snd_conv, split, Pair_eq]; |
0 | 62 |
|
31 | 63 |
goal Prod.thy "(s=t) = (fst(s)=fst(t) & snd(s)=snd(t))"; |
64 |
by(res_inst_tac[("p","s")]PairE 1); |
|
65 |
by(res_inst_tac[("p","t")]PairE 1); |
|
66 |
by(asm_simp_tac pair_ss 1); |
|
67 |
val pair_eq = result(); |
|
68 |
||
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
69 |
(*Prevents simplification of c: much faster*) |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
70 |
val split_weak_cong = prove_goal Prod.thy |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
71 |
"p=q ==> split(p,c) = split(q,c)" |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
72 |
(fn [prem] => [rtac (prem RS arg_cong) 1]); |
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
73 |
|
0 | 74 |
goal Prod.thy "p = <fst(p),snd(p)>"; |
75 |
by (res_inst_tac [("p","p")] PairE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
76 |
by (asm_simp_tac pair_ss 1); |
0 | 77 |
val surjective_pairing = result(); |
78 |
||
79 |
goal Prod.thy "p = split(p, %x y.<x,y>)"; |
|
80 |
by (res_inst_tac [("p","p")] PairE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
81 |
by (asm_simp_tac pair_ss 1); |
0 | 82 |
val surjective_pairing2 = result(); |
83 |
||
84 |
(** split used as a logical connective, with result type bool **) |
|
85 |
||
86 |
val prems = goal Prod.thy "c(a,b) ==> split(<a,b>, c)"; |
|
87 |
by (stac split 1); |
|
88 |
by (resolve_tac prems 1); |
|
89 |
val splitI = result(); |
|
90 |
||
91 |
val prems = goalw Prod.thy [split_def] |
|
92 |
"[| split(p,c); !!x y. [| p = <x,y>; c(x,y) |] ==> Q |] ==> Q"; |
|
93 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1)); |
|
94 |
val splitE = result(); |
|
95 |
||
96 |
goal Prod.thy "R(split(p,c)) = (! x y. p = <x,y> --> R(c(x,y)))"; |
|
97 |
by (stac surjective_pairing 1); |
|
98 |
by (stac split 1); |
|
99 |
by (fast_tac (HOL_cs addSEs [Pair_inject]) 1); |
|
100 |
val expand_split = result(); |
|
101 |
||
102 |
(*** prod_fun -- action of the product functor upon functions ***) |
|
103 |
||
104 |
goalw Prod.thy [prod_fun_def] "prod_fun(f,g,<a,b>) = <f(a),g(b)>"; |
|
105 |
by (rtac split 1); |
|
106 |
val prod_fun = result(); |
|
107 |
||
108 |
goal Prod.thy |
|
109 |
"prod_fun(f1 o f2, g1 o g2) = (prod_fun(f1,g1) o prod_fun(f2,g2))"; |
|
110 |
by (rtac ext 1); |
|
111 |
by (res_inst_tac [("p","x")] PairE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
112 |
by (asm_simp_tac (pair_ss addsimps [prod_fun,o_def]) 1); |
0 | 113 |
val prod_fun_compose = result(); |
114 |
||
115 |
goal Prod.thy "prod_fun(%x.x, %y.y) = (%z.z)"; |
|
116 |
by (rtac ext 1); |
|
117 |
by (res_inst_tac [("p","z")] PairE 1); |
|
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
118 |
by (asm_simp_tac (pair_ss addsimps [prod_fun]) 1); |
0 | 119 |
val prod_fun_ident = result(); |
120 |
||
121 |
val prems = goal Prod.thy "<a,b>:r ==> <f(a),g(b)> : prod_fun(f,g)``r"; |
|
122 |
by (rtac image_eqI 1); |
|
123 |
by (rtac (prod_fun RS sym) 1); |
|
124 |
by (resolve_tac prems 1); |
|
125 |
val prod_fun_imageI = result(); |
|
126 |
||
127 |
val major::prems = goal Prod.thy |
|
128 |
"[| c: prod_fun(f,g)``r; !!x y. [| c=<f(x),g(y)>; <x,y>:r |] ==> P \ |
|
129 |
\ |] ==> P"; |
|
130 |
by (rtac (major RS imageE) 1); |
|
131 |
by (res_inst_tac [("p","x")] PairE 1); |
|
132 |
by (resolve_tac prems 1); |
|
133 |
by (fast_tac HOL_cs 2); |
|
134 |
by (fast_tac (HOL_cs addIs [prod_fun]) 1); |
|
135 |
val prod_fun_imageE = result(); |
|
136 |
||
137 |
(*** Disjoint union of a family of sets - Sigma ***) |
|
138 |
||
139 |
val SigmaI = prove_goalw Prod.thy [Sigma_def] |
|
140 |
"[| a:A; b:B(a) |] ==> <a,b> : Sigma(A,B)" |
|
141 |
(fn prems=> [ (REPEAT (resolve_tac (prems@[singletonI,UN_I]) 1)) ]); |
|
142 |
||
143 |
(*The general elimination rule*) |
|
144 |
val SigmaE = prove_goalw Prod.thy [Sigma_def] |
|
145 |
"[| c: Sigma(A,B); \ |
|
146 |
\ !!x y.[| x:A; y:B(x); c=<x,y> |] ==> P \ |
|
147 |
\ |] ==> P" |
|
148 |
(fn major::prems=> |
|
149 |
[ (cut_facts_tac [major] 1), |
|
150 |
(REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ]); |
|
151 |
||
152 |
(** Elimination of <a,b>:A*B -- introduces no eigenvariables **) |
|
153 |
val SigmaD1 = prove_goal Prod.thy "<a,b> : Sigma(A,B) ==> a : A" |
|
154 |
(fn [major]=> |
|
155 |
[ (rtac (major RS SigmaE) 1), |
|
156 |
(REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]); |
|
157 |
||
158 |
val SigmaD2 = prove_goal Prod.thy "<a,b> : Sigma(A,B) ==> b : B(a)" |
|
159 |
(fn [major]=> |
|
160 |
[ (rtac (major RS SigmaE) 1), |
|
161 |
(REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]); |
|
162 |
||
163 |
val SigmaE2 = prove_goal Prod.thy |
|
164 |
"[| <a,b> : Sigma(A,B); \ |
|
165 |
\ [| a:A; b:B(a) |] ==> P \ |
|
166 |
\ |] ==> P" |
|
167 |
(fn [major,minor]=> |
|
168 |
[ (rtac minor 1), |
|
169 |
(rtac (major RS SigmaD1) 1), |
|
170 |
(rtac (major RS SigmaD2) 1) ]); |
|
171 |
||
172 |
(*** Domain of a relation ***) |
|
173 |
||
174 |
val prems = goalw Prod.thy [image_def] "<a,b> : r ==> a : fst``r"; |
|
175 |
by (rtac CollectI 1); |
|
176 |
by (rtac bexI 1); |
|
177 |
by (rtac (fst_conv RS sym) 1); |
|
178 |
by (resolve_tac prems 1); |
|
179 |
val fst_imageI = result(); |
|
180 |
||
181 |
val major::prems = goal Prod.thy |
|
182 |
"[| a : fst``r; !!y.[| <a,y> : r |] ==> P |] ==> P"; |
|
183 |
by (rtac (major RS imageE) 1); |
|
184 |
by (resolve_tac prems 1); |
|
185 |
by (etac ssubst 1); |
|
186 |
by (rtac (surjective_pairing RS subst) 1); |
|
187 |
by (assume_tac 1); |
|
188 |
val fst_imageE = result(); |
|
189 |
||
190 |
(*** Range of a relation ***) |
|
191 |
||
192 |
val prems = goalw Prod.thy [image_def] "<a,b> : r ==> b : snd``r"; |
|
193 |
by (rtac CollectI 1); |
|
194 |
by (rtac bexI 1); |
|
195 |
by (rtac (snd_conv RS sym) 1); |
|
196 |
by (resolve_tac prems 1); |
|
197 |
val snd_imageI = result(); |
|
198 |
||
199 |
val major::prems = goal Prod.thy |
|
200 |
"[| a : snd``r; !!y.[| <y,a> : r |] ==> P |] ==> P"; |
|
201 |
by (rtac (major RS imageE) 1); |
|
202 |
by (resolve_tac prems 1); |
|
203 |
by (etac ssubst 1); |
|
204 |
by (rtac (surjective_pairing RS subst) 1); |
|
205 |
by (assume_tac 1); |
|
206 |
val snd_imageE = result(); |
|
207 |
||
208 |
(** Exhaustion rule for unit -- a degenerate form of induction **) |
|
209 |
||
210 |
goalw Prod.thy [Unity_def] |
|
211 |
"u = Unity"; |
|
212 |
by (stac (rewrite_rule [Unit_def] Rep_Unit RS CollectD RS sym) 1); |
|
213 |
by (rtac (Rep_Unit_inverse RS sym) 1); |
|
214 |
val unit_eq = result(); |