author | wenzelm |
Thu, 25 Jun 1998 15:34:17 +0200 | |
changeset 5083 | beb21c000cb1 |
parent 5069 | 3ea049f7979d |
child 5088 | e4aa78d1312f |
permissions | -rw-r--r-- |
1465 | 1 |
(* Title: HOL/prod |
923 | 2 |
ID: $Id$ |
1465 | 3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
923 | 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*) |
|
5069 | 12 |
Goalw [Prod_def] "Pair_Rep a b : Prod"; |
923 | 13 |
by (EVERY1 [rtac CollectI, rtac exI, rtac exI, rtac refl]); |
14 |
qed "ProdI"; |
|
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), |
|
1465 | 19 |
rtac conjI, rtac refl, rtac refl]); |
923 | 20 |
qed "Pair_Rep_inject"; |
21 |
||
5069 | 22 |
Goal "inj_on Abs_Prod Prod"; |
4830 | 23 |
by (rtac inj_on_inverseI 1); |
923 | 24 |
by (etac Abs_Prod_inverse 1); |
4830 | 25 |
qed "inj_on_Abs_Prod"; |
923 | 26 |
|
27 |
val prems = goalw Prod.thy [Pair_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
28 |
"[| (a, b) = (a',b'); [| a=a'; b=b' |] ==> R |] ==> R"; |
4830 | 29 |
by (rtac (inj_on_Abs_Prod RS inj_onD RS Pair_Rep_inject RS conjE) 1); |
923 | 30 |
by (REPEAT (ares_tac (prems@[ProdI]) 1)); |
31 |
qed "Pair_inject"; |
|
32 |
||
5069 | 33 |
Goal "((a,b) = (a',b')) = (a=a' & b=b')"; |
4089 | 34 |
by (blast_tac (claset() addSEs [Pair_inject]) 1); |
923 | 35 |
qed "Pair_eq"; |
3429 | 36 |
AddIffs [Pair_eq]; |
923 | 37 |
|
5069 | 38 |
Goalw [fst_def] "fst((a,b)) = a"; |
4534 | 39 |
by (Blast_tac 1); |
923 | 40 |
qed "fst_conv"; |
5069 | 41 |
Goalw [snd_def] "snd((a,b)) = b"; |
4534 | 42 |
by (Blast_tac 1); |
923 | 43 |
qed "snd_conv"; |
4534 | 44 |
Addsimps [fst_conv, snd_conv]; |
923 | 45 |
|
5069 | 46 |
Goalw [Pair_def] "? x y. p = (x,y)"; |
923 | 47 |
by (rtac (rewrite_rule [Prod_def] Rep_Prod RS CollectE) 1); |
48 |
by (EVERY1[etac exE, etac exE, rtac exI, rtac exI, |
|
1465 | 49 |
rtac (Rep_Prod_inverse RS sym RS trans), etac arg_cong]); |
923 | 50 |
qed "PairE_lemma"; |
51 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
52 |
val [prem] = goal Prod.thy "[| !!x y. p = (x,y) ==> Q |] ==> Q"; |
923 | 53 |
by (rtac (PairE_lemma RS exE) 1); |
54 |
by (REPEAT (eresolve_tac [prem,exE] 1)); |
|
55 |
qed "PairE"; |
|
56 |
||
4819
ef2e8e2a10e1
improved pair_tac to call prune_params_tac afterwards
oheimb
parents:
4799
diff
changeset
|
57 |
fun pair_tac s = EVERY' [res_inst_tac [("p",s)] PairE, hyp_subst_tac, |
ef2e8e2a10e1
improved pair_tac to call prune_params_tac afterwards
oheimb
parents:
4799
diff
changeset
|
58 |
K prune_params_tac]; |
4134 | 59 |
|
4828 | 60 |
(* Do not add as rewrite rule: invalidates some proofs in IMP *) |
5069 | 61 |
Goal "p = (fst(p),snd(p))"; |
4828 | 62 |
by (pair_tac "p" 1); |
63 |
by (Asm_simp_tac 1); |
|
64 |
qed "surjective_pairing"; |
|
65 |
||
66 |
val surj_pair = prove_goal Prod.thy "? x y. z = (x, y)" (K [ |
|
67 |
rtac exI 1, rtac exI 1, rtac surjective_pairing 1]); |
|
68 |
Addsimps [surj_pair]; |
|
69 |
||
70 |
(* lemmas for splitting paired `!!' *) |
|
71 |
local |
|
72 |
val lemma1 = prove_goal Prod.thy "(!!x. PROP P x) ==> (!!a b. PROP P(a,b))" |
|
73 |
(fn prems => [resolve_tac prems 1]); |
|
74 |
||
75 |
val psig = sign_of Prod.thy; |
|
76 |
val pT = Sign.read_typ (psig, K None) "?'a*?'b=>prop"; |
|
77 |
val PeqP = reflexive(read_cterm psig ("P", pT)); |
|
78 |
val psplit = zero_var_indexes(read_instantiate [("p","x")] |
|
79 |
surjective_pairing RS eq_reflection); |
|
80 |
val adhoc = combination PeqP psplit; |
|
81 |
val lemma = prove_goal Prod.thy "(!!a b. PROP P(a,b)) ==> PROP P x" |
|
82 |
(fn prems => [rewtac adhoc, resolve_tac prems 1]); |
|
83 |
val lemma2 = prove_goal Prod.thy "(!!a b. PROP P(a,b)) ==> (!!x. PROP P x)" |
|
84 |
(fn prems => [rtac lemma 1, resolve_tac prems 1]); |
|
85 |
in |
|
86 |
val split_paired_all = equal_intr lemma1 lemma2 |
|
87 |
end; |
|
88 |
bind_thm("split_paired_all", split_paired_all); |
|
89 |
(* |
|
90 |
Addsimps [split_paired_all] does not work with simplifier |
|
91 |
because it also affects premises in congrence rules, |
|
92 |
where is can lead to premises of the form !!a b. ... = ?P(a,b) |
|
93 |
which cannot be solved by reflexivity. |
|
94 |
*) |
|
95 |
||
1301 | 96 |
(* replace parameters of product type by individual component parameters *) |
97 |
local |
|
4819
ef2e8e2a10e1
improved pair_tac to call prune_params_tac afterwards
oheimb
parents:
4799
diff
changeset
|
98 |
fun is_pair (_,Type("*",_)) = true |
ef2e8e2a10e1
improved pair_tac to call prune_params_tac afterwards
oheimb
parents:
4799
diff
changeset
|
99 |
| is_pair _ = false; |
4828 | 100 |
fun exists_paired_all prem = exists is_pair (Logic.strip_params prem); |
101 |
val split_tac = full_simp_tac (HOL_basic_ss addsimps [split_paired_all]); |
|
1301 | 102 |
in |
4828 | 103 |
val split_all_tac = SUBGOAL (fn (prem,i) => |
104 |
if exists_paired_all prem then split_tac i else no_tac); |
|
1301 | 105 |
end; |
106 |
||
4828 | 107 |
claset_ref() := claset() addSWrapper ("split_all_tac", |
108 |
fn tac2 => split_all_tac ORELSE' tac2); |
|
3568
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
109 |
|
5069 | 110 |
Goal "(!x. P x) = (!a b. P(a,b))"; |
4650 | 111 |
by (Fast_tac 1); |
1301 | 112 |
qed "split_paired_All"; |
3568
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
113 |
Addsimps [split_paired_All]; |
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
114 |
(* AddIffs is not a good idea because it makes Blast_tac loop *) |
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
115 |
|
5069 | 116 |
Goal "(? x. P x) = (? a b. P(a,b))"; |
4650 | 117 |
by (Fast_tac 1); |
3568
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
118 |
qed "split_paired_Ex"; |
4534 | 119 |
Addsimps [split_paired_Ex]; |
1301 | 120 |
|
5069 | 121 |
Goalw [split_def] "split c (a,b) = c a b"; |
4534 | 122 |
by (Simp_tac 1); |
923 | 123 |
qed "split"; |
4534 | 124 |
Addsimps [split]; |
923 | 125 |
|
5069 | 126 |
Goal "split Pair p = p"; |
4828 | 127 |
by (pair_tac "p" 1); |
128 |
by (Simp_tac 1); |
|
129 |
qed "split_Pair"; |
|
130 |
(*unused: val surjective_pairing2 = split_Pair RS sym;*) |
|
131 |
||
5069 | 132 |
Goal "!!s t. (s=t) = (fst(s)=fst(t) & snd(s)=snd(t))"; |
4828 | 133 |
by (split_all_tac 1); |
1264 | 134 |
by (Asm_simp_tac 1); |
923 | 135 |
qed "Pair_fst_snd_eq"; |
136 |
||
137 |
(*Prevents simplification of c: much faster*) |
|
138 |
qed_goal "split_weak_cong" Prod.thy |
|
139 |
"p=q ==> split c p = split c q" |
|
140 |
(fn [prem] => [rtac (prem RS arg_cong) 1]); |
|
141 |
||
1655 | 142 |
qed_goal "split_eta" Prod.thy "(%(x,y). f(x,y)) = f" |
4534 | 143 |
(K [rtac ext 1, split_all_tac 1, rtac split 1]); |
1655 | 144 |
|
4989 | 145 |
qed_goal "cond_split_eta" Prod.thy |
146 |
"!!f. (!!x y. f x y = g(x,y)) ==> (%(x,y). f x y) = g" |
|
147 |
(K [asm_simp_tac (simpset() addsimps [split_eta]) 1]); |
|
148 |
(*Addsimps [cond_split_eta]; with this version of split_eta, the simplifier |
|
149 |
can eta-contract arbitrarily tupled functions. |
|
150 |
Unfortunately, this renders some existing proofs very inefficient. |
|
151 |
stac split_eta does not work in general either. *) |
|
152 |
val split_etas = split_eta::map (fn s => prove_goal Prod.thy s |
|
153 |
(K [simp_tac (simpset() addsimps [cond_split_eta]) 1])) |
|
154 |
["(%(a,b,c ). f(a,b,c )) = f","(%(a,b,c,d ). f(a,b,c,d )) = f", |
|
155 |
"(%(a,b,c,d,e). f(a,b,c,d,e)) = f","(%(a,b,c,d,e,g). f(a,b,c,d,e,g)) = f"]; |
|
156 |
Addsimps split_etas; (* pragmatic solution *) |
|
157 |
||
158 |
Goal "(%(x,y,z).f(x,y,z)) = t"; |
|
159 |
by(simp_tac (simpset() addsimps [cond_split_eta]) 1); |
|
160 |
||
4819
ef2e8e2a10e1
improved pair_tac to call prune_params_tac afterwards
oheimb
parents:
4799
diff
changeset
|
161 |
qed_goal "split_beta" Prod.thy "(%(x,y). P x y) z = P (fst z) (snd z)" |
4534 | 162 |
(K [stac surjective_pairing 1, stac split 1, rtac refl 1]); |
4134 | 163 |
|
923 | 164 |
(*For use with split_tac and the simplifier*) |
5069 | 165 |
Goal "R (split c p) = (! x y. p = (x,y) --> R (c x y))"; |
923 | 166 |
by (stac surjective_pairing 1); |
167 |
by (stac split 1); |
|
2935 | 168 |
by (Blast_tac 1); |
4830 | 169 |
qed "split_split"; |
923 | 170 |
|
3568
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
171 |
(* could be done after split_tac has been speeded up significantly: |
4830 | 172 |
simpset_ref() := simpset() addsplits [split_split]; |
3568
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
173 |
precompute the constants involved and don't do anything unless |
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
174 |
the current goal contains one of those constants |
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
175 |
*) |
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
176 |
|
5069 | 177 |
Goal "R (split c p) = (~(? x y. p = (x,y) & (~R (c x y))))"; |
4830 | 178 |
by (stac split_split 1); |
4435 | 179 |
by (Simp_tac 1); |
180 |
qed "expand_split_asm"; |
|
181 |
||
923 | 182 |
(** split used as a logical connective or set former **) |
183 |
||
2935 | 184 |
(*These rules are for use with blast_tac. |
923 | 185 |
Could instead call simp_tac/asm_full_simp_tac using split as rewrite.*) |
186 |
||
5069 | 187 |
Goal "!!p. [| !!a b. p=(a,b) ==> c a b |] ==> split c p"; |
1552 | 188 |
by (split_all_tac 1); |
1454
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents:
1301
diff
changeset
|
189 |
by (Asm_simp_tac 1); |
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents:
1301
diff
changeset
|
190 |
qed "splitI2"; |
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents:
1301
diff
changeset
|
191 |
|
5069 | 192 |
Goal "!!a b c. c a b ==> split c (a,b)"; |
1264 | 193 |
by (Asm_simp_tac 1); |
923 | 194 |
qed "splitI"; |
195 |
||
196 |
val prems = goalw Prod.thy [split_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
197 |
"[| split c p; !!x y. [| p = (x,y); c x y |] ==> Q |] ==> Q"; |
923 | 198 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1)); |
199 |
qed "splitE"; |
|
200 |
||
4134 | 201 |
val splitE2 = prove_goal Prod.thy |
202 |
"[|Q (split P z); !!x y. [|z = (x, y); Q (P x y)|] ==> R|] ==> R" (fn prems => [ |
|
203 |
REPEAT (resolve_tac (prems@[surjective_pairing]) 1), |
|
204 |
rtac (split_beta RS subst) 1, |
|
205 |
rtac (hd prems) 1]); |
|
206 |
||
5069 | 207 |
Goal "!!R a b. split R (a,b) ==> R a b"; |
923 | 208 |
by (etac (split RS iffD1) 1); |
209 |
qed "splitD"; |
|
210 |
||
5069 | 211 |
Goal "!!a b c. z: c a b ==> z: split c (a,b)"; |
1264 | 212 |
by (Asm_simp_tac 1); |
923 | 213 |
qed "mem_splitI"; |
214 |
||
5069 | 215 |
Goal "!!p. [| !!a b. p=(a,b) ==> z: c a b |] ==> z: split c p"; |
1552 | 216 |
by (split_all_tac 1); |
1454
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents:
1301
diff
changeset
|
217 |
by (Asm_simp_tac 1); |
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents:
1301
diff
changeset
|
218 |
qed "mem_splitI2"; |
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
nipkow
parents:
1301
diff
changeset
|
219 |
|
923 | 220 |
val prems = goalw Prod.thy [split_def] |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
221 |
"[| z: split c p; !!x y. [| p = (x,y); z: c x y |] ==> Q |] ==> Q"; |
923 | 222 |
by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1)); |
223 |
qed "mem_splitE"; |
|
224 |
||
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
225 |
AddSIs [splitI, splitI2, mem_splitI, mem_splitI2]; |
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
226 |
AddSEs [splitE, mem_splitE]; |
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
227 |
|
4534 | 228 |
(* allows simplifications of nested splits in case of independent predicates *) |
5069 | 229 |
Goal "(%(a,b). P & Q a b) = (%ab. P & split Q ab)"; |
4534 | 230 |
by (rtac ext 1); |
231 |
by (Blast_tac 1); |
|
232 |
qed "split_part"; |
|
233 |
Addsimps [split_part]; |
|
234 |
||
5069 | 235 |
Goal "(@(x',y'). x = x' & y = y') = (x,y)"; |
4534 | 236 |
by (Blast_tac 1); |
237 |
qed "Eps_split_eq"; |
|
238 |
Addsimps [Eps_split_eq]; |
|
239 |
(* |
|
240 |
the following would be slightly more general, |
|
241 |
but cannot be used as rewrite rule: |
|
242 |
### Cannot add premise as rewrite rule because it contains (type) unknowns: |
|
243 |
### ?y = .x |
|
5069 | 244 |
Goal "!!P. [| P y; !!x. P x ==> x = y |] ==> (@(x',y). x = x' & P y) = (x,y)"; |
4534 | 245 |
by (rtac select_equality 1); |
246 |
by ( Simp_tac 1); |
|
247 |
by (split_all_tac 1); |
|
248 |
by (Asm_full_simp_tac 1); |
|
249 |
qed "Eps_split_eq"; |
|
250 |
*) |
|
251 |
||
923 | 252 |
(*** prod_fun -- action of the product functor upon functions ***) |
253 |
||
5069 | 254 |
Goalw [prod_fun_def] "prod_fun f g (a,b) = (f(a),g(b))"; |
923 | 255 |
by (rtac split 1); |
256 |
qed "prod_fun"; |
|
4521 | 257 |
Addsimps [prod_fun]; |
923 | 258 |
|
5069 | 259 |
Goal |
923 | 260 |
"prod_fun (f1 o f2) (g1 o g2) = ((prod_fun f1 g1) o (prod_fun f2 g2))"; |
261 |
by (rtac ext 1); |
|
4828 | 262 |
by (pair_tac "x" 1); |
4521 | 263 |
by (Asm_simp_tac 1); |
923 | 264 |
qed "prod_fun_compose"; |
265 |
||
5069 | 266 |
Goal "prod_fun (%x. x) (%y. y) = (%z. z)"; |
923 | 267 |
by (rtac ext 1); |
4828 | 268 |
by (pair_tac "z" 1); |
4521 | 269 |
by (Asm_simp_tac 1); |
923 | 270 |
qed "prod_fun_ident"; |
4521 | 271 |
Addsimps [prod_fun_ident]; |
923 | 272 |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
273 |
val prems = goal Prod.thy "(a,b):r ==> (f(a),g(b)) : (prod_fun f g)``r"; |
923 | 274 |
by (rtac image_eqI 1); |
275 |
by (rtac (prod_fun RS sym) 1); |
|
276 |
by (resolve_tac prems 1); |
|
277 |
qed "prod_fun_imageI"; |
|
278 |
||
279 |
val major::prems = goal Prod.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
280 |
"[| c: (prod_fun f g)``r; !!x y. [| c=(f(x),g(y)); (x,y):r |] ==> P \ |
923 | 281 |
\ |] ==> P"; |
282 |
by (rtac (major RS imageE) 1); |
|
283 |
by (res_inst_tac [("p","x")] PairE 1); |
|
284 |
by (resolve_tac prems 1); |
|
2935 | 285 |
by (Blast_tac 2); |
4089 | 286 |
by (blast_tac (claset() addIs [prod_fun]) 1); |
923 | 287 |
qed "prod_fun_imageE"; |
288 |
||
4521 | 289 |
|
923 | 290 |
(*** Disjoint union of a family of sets - Sigma ***) |
291 |
||
292 |
qed_goalw "SigmaI" Prod.thy [Sigma_def] |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
293 |
"[| a:A; b:B(a) |] ==> (a,b) : Sigma A B" |
923 | 294 |
(fn prems=> [ (REPEAT (resolve_tac (prems@[singletonI,UN_I]) 1)) ]); |
295 |
||
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
296 |
AddSIs [SigmaI]; |
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
297 |
|
923 | 298 |
(*The general elimination rule*) |
299 |
qed_goalw "SigmaE" Prod.thy [Sigma_def] |
|
300 |
"[| c: Sigma A B; \ |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
301 |
\ !!x y.[| x:A; y:B(x); c=(x,y) |] ==> P \ |
923 | 302 |
\ |] ==> P" |
303 |
(fn major::prems=> |
|
304 |
[ (cut_facts_tac [major] 1), |
|
305 |
(REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ]); |
|
306 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
307 |
(** Elimination of (a,b):A*B -- introduces no eigenvariables **) |
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
308 |
qed_goal "SigmaD1" Prod.thy "(a,b) : Sigma A B ==> a : A" |
923 | 309 |
(fn [major]=> |
310 |
[ (rtac (major RS SigmaE) 1), |
|
311 |
(REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]); |
|
312 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
313 |
qed_goal "SigmaD2" Prod.thy "(a,b) : Sigma A B ==> b : B(a)" |
923 | 314 |
(fn [major]=> |
315 |
[ (rtac (major RS SigmaE) 1), |
|
316 |
(REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]); |
|
317 |
||
318 |
qed_goal "SigmaE2" Prod.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
319 |
"[| (a,b) : Sigma A B; \ |
923 | 320 |
\ [| a:A; b:B(a) |] ==> P \ |
321 |
\ |] ==> P" |
|
322 |
(fn [major,minor]=> |
|
323 |
[ (rtac minor 1), |
|
324 |
(rtac (major RS SigmaD1) 1), |
|
325 |
(rtac (major RS SigmaD2) 1) ]); |
|
326 |
||
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
327 |
AddSEs [SigmaE2, SigmaE]; |
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
328 |
|
1515 | 329 |
val prems = goal Prod.thy |
1642 | 330 |
"[| A<=C; !!x. x:A ==> B x <= D x |] ==> Sigma A B <= Sigma C D"; |
1515 | 331 |
by (cut_facts_tac prems 1); |
4089 | 332 |
by (blast_tac (claset() addIs (prems RL [subsetD])) 1); |
1515 | 333 |
qed "Sigma_mono"; |
334 |
||
1618 | 335 |
qed_goal "Sigma_empty1" Prod.thy "Sigma {} B = {}" |
2935 | 336 |
(fn _ => [ (Blast_tac 1) ]); |
1618 | 337 |
|
1642 | 338 |
qed_goal "Sigma_empty2" Prod.thy "A Times {} = {}" |
2935 | 339 |
(fn _ => [ (Blast_tac 1) ]); |
1618 | 340 |
|
341 |
Addsimps [Sigma_empty1,Sigma_empty2]; |
|
342 |
||
5069 | 343 |
Goal "((a,b): Sigma A B) = (a:A & b:B(a))"; |
2935 | 344 |
by (Blast_tac 1); |
1618 | 345 |
qed "mem_Sigma_iff"; |
3568
36ff1ab12021
Prod.ML: Added split_paired_EX and lots of comments about failed attempts to
nipkow
parents:
3429
diff
changeset
|
346 |
AddIffs [mem_Sigma_iff]; |
1618 | 347 |
|
4534 | 348 |
val Collect_split = prove_goal Prod.thy |
4134 | 349 |
"{(a,b). P a & Q b} = Collect P Times Collect Q" (K [Blast_tac 1]); |
4534 | 350 |
Addsimps [Collect_split]; |
1515 | 351 |
|
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
352 |
(*Suggested by Pierre Chartier*) |
5069 | 353 |
Goal |
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
354 |
"(UN (a,b):(A Times B). E a Times F b) = (UNION A E) Times (UNION B F)"; |
2935 | 355 |
by (Blast_tac 1); |
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
356 |
qed "UNION_Times_distrib"; |
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
357 |
|
923 | 358 |
(*** Domain of a relation ***) |
359 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
360 |
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> a : fst``r"; |
923 | 361 |
by (rtac CollectI 1); |
362 |
by (rtac bexI 1); |
|
363 |
by (rtac (fst_conv RS sym) 1); |
|
364 |
by (resolve_tac prems 1); |
|
365 |
qed "fst_imageI"; |
|
366 |
||
367 |
val major::prems = goal Prod.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
368 |
"[| a : fst``r; !!y.[| (a,y) : r |] ==> P |] ==> P"; |
923 | 369 |
by (rtac (major RS imageE) 1); |
370 |
by (resolve_tac prems 1); |
|
371 |
by (etac ssubst 1); |
|
372 |
by (rtac (surjective_pairing RS subst) 1); |
|
373 |
by (assume_tac 1); |
|
374 |
qed "fst_imageE"; |
|
375 |
||
376 |
(*** Range of a relation ***) |
|
377 |
||
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
378 |
val prems = goalw Prod.thy [image_def] "(a,b) : r ==> b : snd``r"; |
923 | 379 |
by (rtac CollectI 1); |
380 |
by (rtac bexI 1); |
|
381 |
by (rtac (snd_conv RS sym) 1); |
|
382 |
by (resolve_tac prems 1); |
|
383 |
qed "snd_imageI"; |
|
384 |
||
385 |
val major::prems = goal Prod.thy |
|
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
386 |
"[| a : snd``r; !!y.[| (y,a) : r |] ==> P |] ==> P"; |
923 | 387 |
by (rtac (major RS imageE) 1); |
388 |
by (resolve_tac prems 1); |
|
389 |
by (etac ssubst 1); |
|
390 |
by (rtac (surjective_pairing RS subst) 1); |
|
391 |
by (assume_tac 1); |
|
392 |
qed "snd_imageE"; |
|
393 |
||
5083 | 394 |
|
923 | 395 |
(** Exhaustion rule for unit -- a degenerate form of induction **) |
396 |
||
5069 | 397 |
Goalw [Unity_def] |
972
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
clasohm
parents:
923
diff
changeset
|
398 |
"u = ()"; |
2886 | 399 |
by (stac (rewrite_rule [unit_def] Rep_unit RS singletonD RS sym) 1); |
2880 | 400 |
by (rtac (Rep_unit_inverse RS sym) 1); |
923 | 401 |
qed "unit_eq"; |
1754
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1746
diff
changeset
|
402 |
|
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
berghofe
parents:
1746
diff
changeset
|
403 |
AddIs [fst_imageI, snd_imageI, prod_fun_imageI]; |
2856
cdb908486a96
Reorganization of how classical rules are installed
paulson
parents:
2637
diff
changeset
|
404 |
AddSEs [fst_imageE, snd_imageE, prod_fun_imageE]; |
923 | 405 |
|
5083 | 406 |
|
407 |
(*simplification procedure for unit_eq; cannot use this rule directly -- loops!*) |
|
408 |
local |
|
409 |
val unit_pat = Thm.cterm_of (sign_of thy) (Free ("x", HOLogic.unitT)); |
|
410 |
val unit_meta_eq = standard (mk_meta_eq unit_eq); |
|
411 |
fun proc _ _ t = |
|
412 |
if HOLogic.is_unit t then None |
|
413 |
else Some unit_meta_eq; |
|
414 |
in |
|
415 |
val unit_eq_proc = Simplifier.mk_simproc "unit_eq" [unit_pat] proc; |
|
416 |
end; |
|
417 |
||
418 |
Addsimprocs [unit_eq_proc]; |
|
419 |
||
420 |
||
421 |
structure Prod_Syntax = (* FIXME eliminate (use HOLogic instead!) *) |
|
1746
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
422 |
struct |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
423 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
424 |
val unitT = Type("unit",[]); |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
425 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
426 |
fun mk_prod (T1,T2) = Type("*", [T1,T2]); |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
427 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
428 |
(*Maps the type T1*...*Tn to [T1,...,Tn], however nested*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
429 |
fun factors (Type("*", [T1,T2])) = factors T1 @ factors T2 |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
430 |
| factors T = [T]; |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
431 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
432 |
(*Make a correctly typed ordered pair*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
433 |
fun mk_Pair (t1,t2) = |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
434 |
let val T1 = fastype_of t1 |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
435 |
and T2 = fastype_of t2 |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
436 |
in Const("Pair", [T1, T2] ---> mk_prod(T1,T2)) $ t1 $ t2 end; |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
437 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
438 |
fun split_const(Ta,Tb,Tc) = |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
439 |
Const("split", [[Ta,Tb]--->Tc, mk_prod(Ta,Tb)] ---> Tc); |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
440 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
441 |
(*In ap_split S T u, term u expects separate arguments for the factors of S, |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
442 |
with result type T. The call creates a new term expecting one argument |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
443 |
of type S.*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
444 |
fun ap_split (Type("*", [T1,T2])) T3 u = |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
445 |
split_const(T1,T2,T3) $ |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
446 |
Abs("v", T1, |
2031 | 447 |
ap_split T2 T3 |
448 |
((ap_split T1 (factors T2 ---> T3) (incr_boundvars 1 u)) $ |
|
449 |
Bound 0)) |
|
1746
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
450 |
| ap_split T T3 u = u; |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
451 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
452 |
(*Makes a nested tuple from a list, following the product type structure*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
453 |
fun mk_tuple (Type("*", [T1,T2])) tms = |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
454 |
mk_Pair (mk_tuple T1 tms, |
2031 | 455 |
mk_tuple T2 (drop (length (factors T1), tms))) |
1746
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
456 |
| mk_tuple T (t::_) = t; |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
457 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
458 |
(*Attempts to remove occurrences of split, and pair-valued parameters*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
459 |
val remove_split = rewrite_rule [split RS eq_reflection] o |
4772
8c7e7eaffbdf
split_all_tac now fails if there is nothing to split
oheimb
parents:
4650
diff
changeset
|
460 |
rule_by_tactic (TRYALL split_all_tac); |
1746
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
461 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
462 |
(*Uncurries any Var of function type in the rule*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
463 |
fun split_rule_var (t as Var(v, Type("fun",[T1,T2])), rl) = |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
464 |
let val T' = factors T1 ---> T2 |
2031 | 465 |
val newt = ap_split T1 T2 (Var(v,T')) |
466 |
val cterm = Thm.cterm_of (#sign(rep_thm rl)) |
|
1746
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
467 |
in |
2031 | 468 |
remove_split (instantiate ([], [(cterm t, cterm newt)]) rl) |
1746
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
469 |
end |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
470 |
| split_rule_var (t,rl) = rl; |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
471 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
472 |
(*Uncurries ALL function variables occurring in a rule's conclusion*) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
473 |
fun split_rule rl = foldr split_rule_var (term_vars (concl_of rl), rl) |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
474 |
|> standard; |
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
475 |
|
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
nipkow
parents:
1727
diff
changeset
|
476 |
end; |