| author | paulson | 
| Mon, 23 Sep 1996 18:12:45 +0200 | |
| changeset 2009 | 9023e474d22a | 
| parent 1754 | 852093aeb0ab | 
| child 2031 | 03a843f0f447 | 
| 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*) | |
| 12 | goalw Prod.thy [Prod_def] "Pair_Rep a b : Prod"; | |
| 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 | ||
| 22 | goal Prod.thy "inj_onto Abs_Prod Prod"; | |
| 23 | by (rtac inj_onto_inverseI 1); | |
| 24 | by (etac Abs_Prod_inverse 1); | |
| 25 | qed "inj_onto_Abs_Prod"; | |
| 26 | ||
| 27 | val prems = goalw Prod.thy [Pair_def] | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 28 | "[| (a, b) = (a',b'); [| a=a'; b=b' |] ==> R |] ==> R"; | 
| 923 | 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 | qed "Pair_inject"; | |
| 32 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 33 | goal Prod.thy "((a,b) = (a',b')) = (a=a' & b=b')"; | 
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 34 | by (fast_tac (!claset addIs [Pair_inject]) 1); | 
| 923 | 35 | qed "Pair_eq"; | 
| 36 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 37 | goalw Prod.thy [fst_def] "fst((a,b)) = a"; | 
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 38 | by (fast_tac (!claset addIs [select_equality] addSEs [Pair_inject]) 1); | 
| 923 | 39 | qed "fst_conv"; | 
| 40 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 41 | goalw Prod.thy [snd_def] "snd((a,b)) = b"; | 
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 42 | by (fast_tac (!claset addIs [select_equality] addSEs [Pair_inject]) 1); | 
| 923 | 43 | qed "snd_conv"; | 
| 44 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 45 | goalw Prod.thy [Pair_def] "? x y. p = (x,y)"; | 
| 923 | 46 | by (rtac (rewrite_rule [Prod_def] Rep_Prod RS CollectE) 1); | 
| 47 | by (EVERY1[etac exE, etac exE, rtac exI, rtac exI, | |
| 1465 | 48 | rtac (Rep_Prod_inverse RS sym RS trans), etac arg_cong]); | 
| 923 | 49 | qed "PairE_lemma"; | 
| 50 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 51 | val [prem] = goal Prod.thy "[| !!x y. p = (x,y) ==> Q |] ==> Q"; | 
| 923 | 52 | by (rtac (PairE_lemma RS exE) 1); | 
| 53 | by (REPEAT (eresolve_tac [prem,exE] 1)); | |
| 54 | qed "PairE"; | |
| 55 | ||
| 1301 | 56 | (* replace parameters of product type by individual component parameters *) | 
| 57 | local | |
| 58 | fun is_pair (_,Type("*",_)) = true
 | |
| 59 | | is_pair _ = false; | |
| 60 | ||
| 1727 | 61 | fun find_pair_param prem = | 
| 62 | let val params = Logic.strip_params prem | |
| 1301 | 63 | in if exists is_pair params | 
| 1727 | 64 | then let val params = rev(rename_wrt_term prem params) | 
| 1301 | 65 | (*as they are printed*) | 
| 66 | in apsome fst (find_first is_pair params) end | |
| 67 | else None | |
| 68 | end; | |
| 69 | ||
| 70 | in | |
| 71 | ||
| 1727 | 72 | val split_all_tac = REPEAT o SUBGOAL (fn (prem,i) => | 
| 73 | case find_pair_param prem of | |
| 1301 | 74 | None => no_tac | 
| 1727 | 75 |   | Some x => EVERY[res_inst_tac[("p",x)] PairE i,
 | 
| 76 | REPEAT(hyp_subst_tac i), prune_params_tac]); | |
| 1301 | 77 | |
| 78 | end; | |
| 79 | ||
| 80 | goal Prod.thy "(!x. P x) = (!a b. P(a,b))"; | |
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 81 | by (fast_tac (!claset addbefore split_all_tac 1) 1); | 
| 1301 | 82 | qed "split_paired_All"; | 
| 83 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 84 | goalw Prod.thy [split_def] "split c (a,b) = c a b"; | 
| 1485 
240cc98b94a7
Added qed_spec_mp to avoid renaming of bound vars in 'th RS spec'
 nipkow parents: 
1465diff
changeset | 85 | by (EVERY1[stac fst_conv, stac snd_conv]); | 
| 923 | 86 | by (rtac refl 1); | 
| 87 | qed "split"; | |
| 88 | ||
| 1301 | 89 | Addsimps [fst_conv, snd_conv, split_paired_All, split, Pair_eq]; | 
| 923 | 90 | |
| 91 | goal Prod.thy "(s=t) = (fst(s)=fst(t) & snd(s)=snd(t))"; | |
| 92 | by (res_inst_tac[("p","s")] PairE 1);
 | |
| 93 | by (res_inst_tac[("p","t")] PairE 1);
 | |
| 1264 | 94 | by (Asm_simp_tac 1); | 
| 923 | 95 | qed "Pair_fst_snd_eq"; | 
| 96 | ||
| 97 | (*Prevents simplification of c: much faster*) | |
| 98 | qed_goal "split_weak_cong" Prod.thy | |
| 99 | "p=q ==> split c p = split c q" | |
| 100 | (fn [prem] => [rtac (prem RS arg_cong) 1]); | |
| 101 | ||
| 102 | (* Do not add as rewrite rule: invalidates some proofs in IMP *) | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 103 | goal Prod.thy "p = (fst(p),snd(p))"; | 
| 923 | 104 | by (res_inst_tac [("p","p")] PairE 1);
 | 
| 1264 | 105 | by (Asm_simp_tac 1); | 
| 923 | 106 | qed "surjective_pairing"; | 
| 107 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 108 | goal Prod.thy "p = split (%x y.(x,y)) p"; | 
| 923 | 109 | by (res_inst_tac [("p","p")] PairE 1);
 | 
| 1264 | 110 | by (Asm_simp_tac 1); | 
| 923 | 111 | qed "surjective_pairing2"; | 
| 112 | ||
| 1655 | 113 | qed_goal "split_eta" Prod.thy "(%(x,y). f(x,y)) = f" | 
| 114 | (fn _ => [rtac ext 1, split_all_tac 1, rtac split 1]); | |
| 115 | ||
| 923 | 116 | (*For use with split_tac and the simplifier*) | 
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 117 | goal Prod.thy "R(split c p) = (! x y. p = (x,y) --> R(c x y))"; | 
| 923 | 118 | by (stac surjective_pairing 1); | 
| 119 | by (stac split 1); | |
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 120 | by (fast_tac (!claset addSEs [Pair_inject]) 1); | 
| 923 | 121 | qed "expand_split"; | 
| 122 | ||
| 123 | (** split used as a logical connective or set former **) | |
| 124 | ||
| 125 | (*These rules are for use with fast_tac. | |
| 126 | Could instead call simp_tac/asm_full_simp_tac using split as rewrite.*) | |
| 127 | ||
| 1454 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 128 | goal Prod.thy "!!p. [| !!a b. p=(a,b) ==> c a b |] ==> split c p"; | 
| 1552 | 129 | by (split_all_tac 1); | 
| 1454 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 130 | by (Asm_simp_tac 1); | 
| 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 131 | qed "splitI2"; | 
| 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 132 | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 133 | goal Prod.thy "!!a b c. c a b ==> split c (a,b)"; | 
| 1264 | 134 | by (Asm_simp_tac 1); | 
| 923 | 135 | qed "splitI"; | 
| 136 | ||
| 137 | val prems = goalw Prod.thy [split_def] | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 138 | "[| split c p; !!x y. [| p = (x,y); c x y |] ==> Q |] ==> Q"; | 
| 923 | 139 | by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1)); | 
| 140 | qed "splitE"; | |
| 141 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 142 | goal Prod.thy "!!R a b. split R (a,b) ==> R a b"; | 
| 923 | 143 | by (etac (split RS iffD1) 1); | 
| 144 | qed "splitD"; | |
| 145 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 146 | goal Prod.thy "!!a b c. z: c a b ==> z: split c (a,b)"; | 
| 1264 | 147 | by (Asm_simp_tac 1); | 
| 923 | 148 | qed "mem_splitI"; | 
| 149 | ||
| 1454 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 150 | goal Prod.thy "!!p. [| !!a b. p=(a,b) ==> z: c a b |] ==> z: split c p"; | 
| 1552 | 151 | by (split_all_tac 1); | 
| 1454 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 152 | by (Asm_simp_tac 1); | 
| 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 153 | qed "mem_splitI2"; | 
| 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 154 | |
| 923 | 155 | val prems = goalw Prod.thy [split_def] | 
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 156 | "[| z: split c p; !!x y. [| p = (x,y); z: c x y |] ==> Q |] ==> Q"; | 
| 923 | 157 | by (REPEAT (resolve_tac (prems@[surjective_pairing]) 1)); | 
| 158 | qed "mem_splitE"; | |
| 159 | ||
| 160 | (*** prod_fun -- action of the product functor upon functions ***) | |
| 161 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 162 | goalw Prod.thy [prod_fun_def] "prod_fun f g (a,b) = (f(a),g(b))"; | 
| 923 | 163 | by (rtac split 1); | 
| 164 | qed "prod_fun"; | |
| 165 | ||
| 166 | goal Prod.thy | |
| 167 | "prod_fun (f1 o f2) (g1 o g2) = ((prod_fun f1 g1) o (prod_fun f2 g2))"; | |
| 168 | by (rtac ext 1); | |
| 169 | by (res_inst_tac [("p","x")] PairE 1);
 | |
| 1264 | 170 | by (asm_simp_tac (!simpset addsimps [prod_fun,o_def]) 1); | 
| 923 | 171 | qed "prod_fun_compose"; | 
| 172 | ||
| 173 | goal Prod.thy "prod_fun (%x.x) (%y.y) = (%z.z)"; | |
| 174 | by (rtac ext 1); | |
| 175 | by (res_inst_tac [("p","z")] PairE 1);
 | |
| 1264 | 176 | by (asm_simp_tac (!simpset addsimps [prod_fun]) 1); | 
| 923 | 177 | qed "prod_fun_ident"; | 
| 178 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 179 | val prems = goal Prod.thy "(a,b):r ==> (f(a),g(b)) : (prod_fun f g)``r"; | 
| 923 | 180 | by (rtac image_eqI 1); | 
| 181 | by (rtac (prod_fun RS sym) 1); | |
| 182 | by (resolve_tac prems 1); | |
| 183 | qed "prod_fun_imageI"; | |
| 184 | ||
| 185 | val major::prems = goal Prod.thy | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 186 | "[| c: (prod_fun f g)``r; !!x y. [| c=(f(x),g(y)); (x,y):r |] ==> P \ | 
| 923 | 187 | \ |] ==> P"; | 
| 188 | by (rtac (major RS imageE) 1); | |
| 189 | by (res_inst_tac [("p","x")] PairE 1);
 | |
| 190 | by (resolve_tac prems 1); | |
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 191 | by (Fast_tac 2); | 
| 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 192 | by (fast_tac (!claset addIs [prod_fun]) 1); | 
| 923 | 193 | qed "prod_fun_imageE"; | 
| 194 | ||
| 195 | (*** Disjoint union of a family of sets - Sigma ***) | |
| 196 | ||
| 197 | qed_goalw "SigmaI" Prod.thy [Sigma_def] | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 198 | "[| a:A; b:B(a) |] ==> (a,b) : Sigma A B" | 
| 923 | 199 | (fn prems=> [ (REPEAT (resolve_tac (prems@[singletonI,UN_I]) 1)) ]); | 
| 200 | ||
| 201 | (*The general elimination rule*) | |
| 202 | qed_goalw "SigmaE" Prod.thy [Sigma_def] | |
| 203 | "[| c: Sigma A B; \ | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 204 | \ !!x y.[| x:A; y:B(x); c=(x,y) |] ==> P \ | 
| 923 | 205 | \ |] ==> P" | 
| 206 | (fn major::prems=> | |
| 207 | [ (cut_facts_tac [major] 1), | |
| 208 | (REPEAT (eresolve_tac [UN_E, singletonE] 1 ORELSE ares_tac prems 1)) ]); | |
| 209 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 210 | (** Elimination of (a,b):A*B -- introduces no eigenvariables **) | 
| 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 211 | qed_goal "SigmaD1" Prod.thy "(a,b) : Sigma A B ==> a : A" | 
| 923 | 212 | (fn [major]=> | 
| 213 | [ (rtac (major RS SigmaE) 1), | |
| 214 | (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]); | |
| 215 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 216 | qed_goal "SigmaD2" Prod.thy "(a,b) : Sigma A B ==> b : B(a)" | 
| 923 | 217 | (fn [major]=> | 
| 218 | [ (rtac (major RS SigmaE) 1), | |
| 219 | (REPEAT (eresolve_tac [asm_rl,Pair_inject,ssubst] 1)) ]); | |
| 220 | ||
| 221 | qed_goal "SigmaE2" Prod.thy | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 222 | "[| (a,b) : Sigma A B; \ | 
| 923 | 223 | \ [| a:A; b:B(a) |] ==> P \ | 
| 224 | \ |] ==> P" | |
| 225 | (fn [major,minor]=> | |
| 226 | [ (rtac minor 1), | |
| 227 | (rtac (major RS SigmaD1) 1), | |
| 228 | (rtac (major RS SigmaD2) 1) ]); | |
| 229 | ||
| 1515 | 230 | val prems = goal Prod.thy | 
| 1642 | 231 | "[| A<=C; !!x. x:A ==> B x <= D x |] ==> Sigma A B <= Sigma C D"; | 
| 1515 | 232 | by (cut_facts_tac prems 1); | 
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 233 | by (fast_tac (!claset addIs (prems RL [subsetD]) | 
| 1515 | 234 | addSIs [SigmaI] | 
| 235 | addSEs [SigmaE]) 1); | |
| 236 | qed "Sigma_mono"; | |
| 237 | ||
| 1618 | 238 | qed_goal "Sigma_empty1" Prod.thy "Sigma {} B = {}"
 | 
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 239 | (fn _ => [ (fast_tac (!claset addSEs [SigmaE]) 1) ]); | 
| 1618 | 240 | |
| 1642 | 241 | qed_goal "Sigma_empty2" Prod.thy "A Times {} = {}"
 | 
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 242 | (fn _ => [ (fast_tac (!claset addSEs [SigmaE]) 1) ]); | 
| 1618 | 243 | |
| 244 | Addsimps [Sigma_empty1,Sigma_empty2]; | |
| 245 | ||
| 246 | goal Prod.thy "((a,b): Sigma A B) = (a:A & b:B(a))"; | |
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 247 | by (fast_tac (!claset addSIs [SigmaI] addSEs [SigmaE, Pair_inject]) 1); | 
| 1618 | 248 | qed "mem_Sigma_iff"; | 
| 249 | Addsimps [mem_Sigma_iff]; | |
| 250 | ||
| 1515 | 251 | |
| 923 | 252 | (*** Domain of a relation ***) | 
| 253 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 254 | val prems = goalw Prod.thy [image_def] "(a,b) : r ==> a : fst``r"; | 
| 923 | 255 | by (rtac CollectI 1); | 
| 256 | by (rtac bexI 1); | |
| 257 | by (rtac (fst_conv RS sym) 1); | |
| 258 | by (resolve_tac prems 1); | |
| 259 | qed "fst_imageI"; | |
| 260 | ||
| 261 | val major::prems = goal Prod.thy | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 262 | "[| a : fst``r; !!y.[| (a,y) : r |] ==> P |] ==> P"; | 
| 923 | 263 | by (rtac (major RS imageE) 1); | 
| 264 | by (resolve_tac prems 1); | |
| 265 | by (etac ssubst 1); | |
| 266 | by (rtac (surjective_pairing RS subst) 1); | |
| 267 | by (assume_tac 1); | |
| 268 | qed "fst_imageE"; | |
| 269 | ||
| 270 | (*** Range of a relation ***) | |
| 271 | ||
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 272 | val prems = goalw Prod.thy [image_def] "(a,b) : r ==> b : snd``r"; | 
| 923 | 273 | by (rtac CollectI 1); | 
| 274 | by (rtac bexI 1); | |
| 275 | by (rtac (snd_conv RS sym) 1); | |
| 276 | by (resolve_tac prems 1); | |
| 277 | qed "snd_imageI"; | |
| 278 | ||
| 279 | val major::prems = goal Prod.thy | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 280 | "[| a : snd``r; !!y.[| (y,a) : r |] ==> P |] ==> P"; | 
| 923 | 281 | by (rtac (major RS imageE) 1); | 
| 282 | by (resolve_tac prems 1); | |
| 283 | by (etac ssubst 1); | |
| 284 | by (rtac (surjective_pairing RS subst) 1); | |
| 285 | by (assume_tac 1); | |
| 286 | qed "snd_imageE"; | |
| 287 | ||
| 288 | (** Exhaustion rule for unit -- a degenerate form of induction **) | |
| 289 | ||
| 290 | goalw Prod.thy [Unity_def] | |
| 972 
e61b058d58d2
changed syntax of tuples from <..., ...> to (..., ...)
 clasohm parents: 
923diff
changeset | 291 | "u = ()"; | 
| 923 | 292 | by (stac (rewrite_rule [Unit_def] Rep_Unit RS CollectD RS sym) 1); | 
| 293 | by (rtac (Rep_Unit_inverse RS sym) 1); | |
| 294 | qed "unit_eq"; | |
| 1754 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 295 | |
| 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 296 | AddSIs [SigmaI, splitI, splitI2, mem_splitI, mem_splitI2]; | 
| 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 297 | AddIs [fst_imageI, snd_imageI, prod_fun_imageI]; | 
| 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 298 | AddSEs [SigmaE2, SigmaE, splitE, mem_splitE, | 
| 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 299 | fst_imageE, snd_imageE, prod_fun_imageE, | 
| 
852093aeb0ab
Replaced fast_tac by Fast_tac (which uses default claset)
 berghofe parents: 
1746diff
changeset | 300 | Pair_inject]; | 
| 923 | 301 | |
| 1454 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 302 | val prod_cs = set_cs addSIs [SigmaI, splitI, splitI2, mem_splitI, mem_splitI2] | 
| 923 | 303 | addIs [fst_imageI, snd_imageI, prod_fun_imageI] | 
| 1454 
d0266c81a85e
Streamlined defs in Relation and added new intro/elim rules to do with
 nipkow parents: 
1301diff
changeset | 304 | addSEs [SigmaE2, SigmaE, splitE, mem_splitE, | 
| 1465 | 305 | fst_imageE, snd_imageE, prod_fun_imageE, | 
| 306 | Pair_inject]; | |
| 1746 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 307 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 308 | structure Prod_Syntax = | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 309 | struct | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 310 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 311 | val unitT = Type("unit",[]);
 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 312 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 313 | fun mk_prod (T1,T2) = Type("*", [T1,T2]);
 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 314 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 315 | (*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: 
1727diff
changeset | 316 | fun factors (Type("*", [T1,T2])) = factors T1 @ factors T2
 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 317 | | factors T = [T]; | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 318 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 319 | (*Make a correctly typed ordered pair*) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 320 | fun mk_Pair (t1,t2) = | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 321 | let val T1 = fastype_of t1 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 322 | and T2 = fastype_of t2 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 323 |   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: 
1727diff
changeset | 324 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 325 | fun split_const(Ta,Tb,Tc) = | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 326 |     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: 
1727diff
changeset | 327 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 328 | (*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: 
1727diff
changeset | 329 | 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: 
1727diff
changeset | 330 | of type S.*) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 331 | fun ap_split (Type("*", [T1,T2])) T3 u = 
 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 332 | split_const(T1,T2,T3) $ | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 333 |       Abs("v", T1, 
 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 334 | ap_split T2 T3 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 335 | ((ap_split T1 (factors T2 ---> T3) (incr_boundvars 1 u)) $ | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 336 | Bound 0)) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 337 | | ap_split T T3 u = u; | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 338 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 339 | (*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: 
1727diff
changeset | 340 | fun mk_tuple (Type("*", [T1,T2])) tms = 
 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 341 | mk_Pair (mk_tuple T1 tms, | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 342 | mk_tuple T2 (drop (length (factors T1), tms))) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 343 | | mk_tuple T (t::_) = t; | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 344 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 345 | (*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: 
1727diff
changeset | 346 | val remove_split = rewrite_rule [split RS eq_reflection] o | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 347 | rule_by_tactic (ALLGOALS split_all_tac); | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 348 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 349 | (*Uncurries any Var of function type in the rule*) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 350 | 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: 
1727diff
changeset | 351 | let val T' = factors T1 ---> T2 | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 352 | val newt = ap_split T1 T2 (Var(v,T')) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 353 | val cterm = Thm.cterm_of (#sign(rep_thm rl)) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 354 | in | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 355 | remove_split (instantiate ([], [(cterm t, cterm newt)]) rl) | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 356 | end | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 357 | | split_rule_var (t,rl) = rl; | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 358 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 359 | (*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: 
1727diff
changeset | 360 | 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: 
1727diff
changeset | 361 | |> standard; | 
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 362 | |
| 
f0c6aabc6c02
Moved split_rule et al from ind_syntax.ML to Prod.ML.
 nipkow parents: 
1727diff
changeset | 363 | end; |