author  wenzelm 
Sat, 27 Oct 2001 23:16:15 +0200  
changeset 11966  8fe2ee787608 
parent 11838  02d75712061d 
child 12114  a8e860c86252 
permissions  rwrr 
10213  1 
(* Title: HOL/Product_Type.thy 
2 
ID: $Id$ 

3 
Author: Lawrence C Paulson, Cambridge University Computer Laboratory 

4 
Copyright 1992 University of Cambridge 

11777  5 
*) 
10213  6 

11838  7 
header {* Cartesian products *} 
10213  8 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

9 
theory Product_Type = Fun 
11838  10 
files ("Tools/split_rule.ML"): 
11 

12 
subsection {* Unit *} 

13 

14 
typedef unit = "{True}" 

15 
proof 

16 
show "True : ?unit" by blast 

17 
qed 

18 

19 
constdefs 

20 
Unity :: unit ("'(')") 

21 
"() == Abs_unit True" 

22 

23 
lemma unit_eq: "u = ()" 

24 
by (induct u) (simp add: unit_def Unity_def) 

25 

26 
text {* 

27 
Simplification procedure for @{thm [source] unit_eq}. Cannot use 

28 
this rule directly  it loops! 

29 
*} 

30 

31 
ML_setup {* 

32 
local 

33 
val unit_pat = Thm.cterm_of (Theory.sign_of (the_context ())) (Free ("x", HOLogic.unitT)); 

34 
val unit_meta_eq = standard (mk_meta_eq (thm "unit_eq")); 

35 
fun proc _ _ t = 

36 
if HOLogic.is_unit t then None 

37 
else Some unit_meta_eq 

38 
in val unit_eq_proc = Simplifier.mk_simproc "unit_eq" [unit_pat] proc end; 

39 

40 
Addsimprocs [unit_eq_proc]; 

41 
*} 

42 

43 
lemma unit_all_eq1: "(!!x::unit. PROP P x) == PROP P ()" 

44 
by simp 

45 

46 
lemma unit_all_eq2: "(!!x::unit. PROP P) == PROP P" 

47 
by (rule triv_forall_equality) 

48 

49 
lemma unit_induct [induct type: unit]: "P () ==> P x" 

50 
by simp 

51 

52 
text {* 

53 
This rewrite counters the effect of @{text unit_eq_proc} on @{term 

54 
[source] "%u::unit. f u"}, replacing it by @{term [source] 

55 
f} rather than by @{term [source] "%u. f ()"}. 

56 
*} 

57 

58 
lemma unit_abs_eta_conv [simp]: "(%u::unit. f ()) = f" 

59 
by (rule ext) simp 

10213  60 

61 

11838  62 
subsection {* Pairs *} 
10213  63 

11777  64 
subsubsection {* Type definition *} 
10213  65 

66 
constdefs 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

67 
Pair_Rep :: "['a, 'b] => ['a, 'b] => bool" 
11032  68 
"Pair_Rep == (%a b. %x y. x=a & y=b)" 
10213  69 

70 
global 

71 

72 
typedef (Prod) 

11838  73 
('a, 'b) "*" (infixr 20) 
11032  74 
= "{f. EX a b. f = Pair_Rep (a::'a) (b::'b)}" 
11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

75 
proof 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

76 
fix a b show "Pair_Rep a b : ?Prod" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

77 
by blast 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

78 
qed 
10213  79 

80 
syntax (symbols) 

11493  81 
"*" :: "[type, type] => type" ("(_ \<times>/ _)" [21, 20] 20) 
10213  82 
syntax (HTML output) 
11493  83 
"*" :: "[type, type] => type" ("(_ \<times>/ _)" [21, 20] 20) 
10213  84 

11777  85 
local 
10213  86 

11777  87 

88 
subsubsection {* Abstract constants and syntax *} 

89 

90 
global 

10213  91 

92 
consts 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

93 
fst :: "'a * 'b => 'a" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

94 
snd :: "'a * 'b => 'b" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

95 
split :: "[['a, 'b] => 'c, 'a * 'b] => 'c" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

96 
prod_fun :: "['a => 'b, 'c => 'd, 'a * 'c] => 'b * 'd" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

97 
Pair :: "['a, 'b] => 'a * 'b" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

98 
Sigma :: "['a set, 'a => 'b set] => ('a * 'b) set" 
10213  99 

11777  100 
local 
10213  101 

11777  102 
text {* 
103 
Patterns  extends predefined type @{typ pttrn} used in 

104 
abstractions. 

105 
*} 

10213  106 

107 
nonterminals 

108 
tuple_args patterns 

109 

110 
syntax 

111 
"_tuple" :: "'a => tuple_args => 'a * 'b" ("(1'(_,/ _'))") 

112 
"_tuple_arg" :: "'a => tuple_args" ("_") 

113 
"_tuple_args" :: "'a => tuple_args => tuple_args" ("_,/ _") 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

114 
"_pattern" :: "[pttrn, patterns] => pttrn" ("'(_,/ _')") 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

115 
"" :: "pttrn => patterns" ("_") 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

116 
"_patterns" :: "[pttrn, patterns] => patterns" ("_,/ _") 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

117 
"@Sigma" ::"[pttrn, 'a set, 'b set] => ('a * 'b) set" ("(3SIGMA _:_./ _)" 10) 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

118 
"@Times" ::"['a set, 'a => 'b set] => ('a * 'b) set" (infixr "<*>" 80) 
10213  119 

120 
translations 

121 
"(x, y)" == "Pair x y" 

122 
"_tuple x (_tuple_args y z)" == "_tuple x (_tuple_arg (_tuple y z))" 

123 
"%(x,y,zs).b" == "split(%x (y,zs).b)" 

124 
"%(x,y).b" == "split(%x y. b)" 

125 
"_abs (Pair x y) t" => "%(x,y).t" 

126 
(* The last rule accommodates tuples in `case C ... (x,y) ... => ...' 

127 
The (x,y) is parsed as `Pair x y' because it is logic, not pttrn *) 

128 

129 
"SIGMA x:A. B" => "Sigma A (%x. B)" 

130 
"A <*> B" => "Sigma A (_K B)" 

131 

132 
syntax (symbols) 

11493  133 
"@Sigma" :: "[pttrn, 'a set, 'b set] => ('a * 'b) set" ("(3\<Sigma> _\<in>_./ _)" 10) 
134 
"@Times" :: "['a set, 'a => 'b set] => ('a * 'b) set" ("_ \<times> _" [81, 80] 80) 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

135 

11032  136 
print_translation {* [("Sigma", dependent_tr' ("@Sigma", "@Times"))] *} 
10213  137 

138 

11777  139 
subsubsection {* Definitions *} 
10213  140 

141 
defs 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

142 
Pair_def: "Pair a b == Abs_Prod(Pair_Rep a b)" 
11451
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
paulson
parents:
11425
diff
changeset

143 
fst_def: "fst p == THE a. EX b. p = (a, b)" 
8abfb4f7bd02
partial restructuring to reduce dependence on Axiom of Choice
paulson
parents:
11425
diff
changeset

144 
snd_def: "snd p == THE b. EX a. p = (a, b)" 
11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

145 
split_def: "split == (%c p. c (fst p) (snd p))" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

146 
prod_fun_def: "prod_fun f g == split(%x y.(f(x), g(y)))" 
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

147 
Sigma_def: "Sigma A B == UN x:A. UN y:B(x). {(x, y)}" 
10213  148 

149 

11966  150 
subsubsection {* Lemmas and proof tool setup *} 
11838  151 

152 
lemma ProdI: "Pair_Rep a b : Prod" 

153 
by (unfold Prod_def) blast 

154 

155 
lemma Pair_Rep_inject: "Pair_Rep a b = Pair_Rep a' b' ==> a = a' & b = b'" 

156 
apply (unfold Pair_Rep_def) 

157 
apply (drule fun_cong [THEN fun_cong]) 

158 
apply blast 

159 
done 

10213  160 

11838  161 
lemma inj_on_Abs_Prod: "inj_on Abs_Prod Prod" 
162 
apply (rule inj_on_inverseI) 

163 
apply (erule Abs_Prod_inverse) 

164 
done 

165 

166 
lemma Pair_inject: 

167 
"(a, b) = (a', b') ==> (a = a' ==> b = b' ==> R) ==> R" 

168 
proof  

169 
case rule_context [unfolded Pair_def] 

170 
show ?thesis 

171 
apply (rule inj_on_Abs_Prod [THEN inj_onD, THEN Pair_Rep_inject, THEN conjE]) 

172 
apply (rule rule_context ProdI)+ 

173 
. 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

174 
qed 
10213  175 

11838  176 
lemma Pair_eq [iff]: "((a, b) = (a', b')) = (a = a' & b = b')" 
177 
by (blast elim!: Pair_inject) 

178 

179 
lemma fst_conv [simp]: "fst (a, b) = a" 

180 
by (unfold fst_def) blast 

181 

182 
lemma snd_conv [simp]: "snd (a, b) = b" 

183 
by (unfold snd_def) blast 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

184 

11838  185 
lemma fst_eqD: "fst (x, y) = a ==> x = a" 
186 
by simp 

187 

188 
lemma snd_eqD: "snd (x, y) = a ==> y = a" 

189 
by simp 

190 

191 
lemma PairE_lemma: "EX x y. p = (x, y)" 

192 
apply (unfold Pair_def) 

193 
apply (rule Rep_Prod [unfolded Prod_def, THEN CollectE]) 

194 
apply (erule exE, erule exE, rule exI, rule exI) 

195 
apply (rule Rep_Prod_inverse [symmetric, THEN trans]) 

196 
apply (erule arg_cong) 

197 
done 

11032  198 

11838  199 
lemma PairE [cases type: *]: "(!!x y. p = (x, y) ==> Q) ==> Q" 
200 
by (insert PairE_lemma [of p]) blast 

201 

202 
ML_setup {* 

203 
local val PairE = thm "PairE" in 

204 
fun pair_tac s = 

205 
EVERY' [res_inst_tac [("p", s)] PairE, hyp_subst_tac, K prune_params_tac]; 

206 
end; 

207 
*} 

11032  208 

11838  209 
lemma surjective_pairing: "p = (fst p, snd p)" 
210 
 {* Do not add as rewrite rule: invalidates some proofs in IMP *} 

211 
by (cases p) simp 

212 

213 
declare surjective_pairing [symmetric, simp] 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

214 

11838  215 
lemma surj_pair [simp]: "EX x y. z = (x, y)" 
216 
apply (rule exI) 

217 
apply (rule exI) 

218 
apply (rule surjective_pairing) 

219 
done 

220 

221 
lemma split_paired_all: "(!!x. PROP P x) == (!!a b. PROP P (a, b))" 

11820
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

222 
proof 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

223 
fix a b 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

224 
assume "!!x. PROP P x" 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

225 
thus "PROP P (a, b)" . 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

226 
next 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

227 
fix x 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

228 
assume "!!a b. PROP P (a, b)" 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

229 
hence "PROP P (fst x, snd x)" . 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

230 
thus "PROP P x" by simp 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

231 
qed 
015a82d4ee96
proper proof of split_paired_all (presently unused);
wenzelm
parents:
11777
diff
changeset

232 

11838  233 
lemmas split_tupled_all = split_paired_all unit_all_eq2 
234 

235 
text {* 

236 
The rule @{thm [source] split_paired_all} does not work with the 

237 
Simplifier because it also affects premises in congrence rules, 

238 
where this can lead to premises of the form @{text "!!a b. ... = 

239 
?P(a, b)"} which cannot be solved by reflexivity. 

240 
*} 

241 

242 
ML_setup " 

243 
(* replace parameters of product type by individual component parameters *) 

244 
val safe_full_simp_tac = generic_simp_tac true (true, false, false); 

245 
local (* filtering with exists_paired_all is an essential optimization *) 

246 
fun exists_paired_all (Const (\"all\", _) $ Abs (_, T, t)) = 

247 
can HOLogic.dest_prodT T orelse exists_paired_all t 

248 
 exists_paired_all (t $ u) = exists_paired_all t orelse exists_paired_all u 

249 
 exists_paired_all (Abs (_, _, t)) = exists_paired_all t 

250 
 exists_paired_all _ = false; 

251 
val ss = HOL_basic_ss 

252 
addsimps [thm \"split_paired_all\", thm \"unit_all_eq2\", thm \"unit_abs_eta_conv\"] 

253 
addsimprocs [unit_eq_proc]; 

254 
in 

255 
val split_all_tac = SUBGOAL (fn (t, i) => 

256 
if exists_paired_all t then safe_full_simp_tac ss i else no_tac); 

257 
val unsafe_split_all_tac = SUBGOAL (fn (t, i) => 

258 
if exists_paired_all t then full_simp_tac ss i else no_tac); 

259 
fun split_all th = 

260 
if exists_paired_all (#prop (Thm.rep_thm th)) then full_simplify ss th else th; 

261 
end; 

262 

263 
claset_ref() := claset() addSbefore (\"split_all_tac\", split_all_tac); 

264 
" 

265 

266 
lemma split_paired_All [simp]: "(ALL x. P x) = (ALL a b. P (a, b))" 

267 
 {* @{text "[iff]"} is not a good idea because it makes @{text blast} loop *} 

268 
by fast 

269 

270 
lemma prod_induct [induct type: *]: "!!x. (!!a b. P (a, b)) ==> P x" 

271 
by fast 

272 

273 
lemma split_paired_Ex [simp]: "(EX x. P x) = (EX a b. P (a, b))" 

274 
by fast 

275 

276 
lemma split_conv [simp]: "split c (a, b) = c a b" 

277 
by (simp add: split_def) 

278 

279 
lemmas split = split_conv  {* for backwards compatibility *} 

280 

281 
lemmas splitI = split_conv [THEN iffD2, standard] 

282 
lemmas splitD = split_conv [THEN iffD1, standard] 

283 

284 
lemma split_Pair_apply: "split (%x y. f (x, y)) = f" 

285 
 {* Subsumes the old @{text split_Pair} when @{term f} is the identity function. *} 

286 
apply (rule ext) 

287 
apply (tactic {* pair_tac "x" 1 *}) 

288 
apply simp 

289 
done 

290 

291 
lemma split_paired_The: "(THE x. P x) = (THE (a, b). P (a, b))" 

292 
 {* Can't be added to simpset: loops! *} 

293 
by (simp add: split_Pair_apply) 

294 

295 
lemma The_split: "The (split P) = (THE xy. P (fst xy) (snd xy))" 

296 
by (simp add: split_def) 

297 

298 
lemma Pair_fst_snd_eq: "!!s t. (s = t) = (fst s = fst t & snd s = snd t)" 

299 
apply (simp only: split_tupled_all) 

300 
apply simp 

301 
done 

302 

303 
lemma prod_eqI [intro?]: "fst p = fst q ==> snd p = snd q ==> p = q" 

304 
by (simp add: Pair_fst_snd_eq) 

305 

306 
lemma split_weak_cong: "p = q ==> split c p = split c q" 

307 
 {* Prevents simplification of @{term c}: much faster *} 

308 
by (erule arg_cong) 

309 

310 
lemma split_eta: "(%(x, y). f (x, y)) = f" 

311 
apply (rule ext) 

312 
apply (simp only: split_tupled_all) 

313 
apply (rule split_conv) 

314 
done 

315 

316 
lemma cond_split_eta: "(!!x y. f x y = g (x, y)) ==> (%(x, y). f x y) = g" 

317 
by (simp add: split_eta) 

318 

319 
text {* 

320 
Simplification procedure for @{thm [source] cond_split_eta}. Using 

321 
@{thm [source] split_eta} as a rewrite rule is not general enough, 

322 
and using @{thm [source] cond_split_eta} directly would render some 

323 
existing proofs very inefficient; similarly for @{text 

324 
split_beta}. *} 

325 

326 
ML_setup {* 

327 

328 
local 

329 
val cond_split_eta = thm "cond_split_eta"; 

330 
fun Pair_pat k 0 (Bound m) = (m = k) 

331 
 Pair_pat k i (Const ("Pair", _) $ Bound m $ t) = i > 0 andalso 

332 
m = k+i andalso Pair_pat k (i1) t 

333 
 Pair_pat _ _ _ = false; 

334 
fun no_args k i (Abs (_, _, t)) = no_args (k+1) i t 

335 
 no_args k i (t $ u) = no_args k i t andalso no_args k i u 

336 
 no_args k i (Bound m) = m < k orelse m > k+i 

337 
 no_args _ _ _ = true; 

338 
fun split_pat tp i (Abs (_,_,t)) = if tp 0 i t then Some (i,t) else None 

339 
 split_pat tp i (Const ("split", _) $ Abs (_, _, t)) = split_pat tp (i+1) t 

340 
 split_pat tp i _ = None; 

341 
fun metaeq sg lhs rhs = mk_meta_eq (prove_goalw_cterm [] 

342 
(cterm_of sg (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs,rhs)))) 

343 
(K [simp_tac (HOL_basic_ss addsimps [cond_split_eta]) 1])); 

344 
val sign = sign_of (the_context ()); 

345 
fun simproc name patstr = Simplifier.mk_simproc name 

346 
[Thm.read_cterm sign (patstr, HOLogic.termT)]; 

347 

348 
val beta_patstr = "split f z"; 

349 
val eta_patstr = "split f"; 

350 
fun beta_term_pat k i (Abs (_, _, t)) = beta_term_pat (k+1) i t 

351 
 beta_term_pat k i (t $ u) = Pair_pat k i (t $ u) orelse 

352 
(beta_term_pat k i t andalso beta_term_pat k i u) 

353 
 beta_term_pat k i t = no_args k i t; 

354 
fun eta_term_pat k i (f $ arg) = no_args k i f andalso Pair_pat k i arg 

355 
 eta_term_pat _ _ _ = false; 

356 
fun subst arg k i (Abs (x, T, t)) = Abs (x, T, subst arg (k+1) i t) 

357 
 subst arg k i (t $ u) = if Pair_pat k i (t $ u) then incr_boundvars k arg 

358 
else (subst arg k i t $ subst arg k i u) 

359 
 subst arg k i t = t; 

360 
fun beta_proc sg _ (s as Const ("split", _) $ Abs (_, _, t) $ arg) = 

361 
(case split_pat beta_term_pat 1 t of 

362 
Some (i,f) => Some (metaeq sg s (subst arg 0 i f)) 

363 
 None => None) 

364 
 beta_proc _ _ _ = None; 

365 
fun eta_proc sg _ (s as Const ("split", _) $ Abs (_, _, t)) = 

366 
(case split_pat eta_term_pat 1 t of 

367 
Some (_,ft) => Some (metaeq sg s (let val (f $ arg) = ft in f end)) 

368 
 None => None) 

369 
 eta_proc _ _ _ = None; 

370 
in 

371 
val split_beta_proc = simproc "split_beta" beta_patstr beta_proc; 

372 
val split_eta_proc = simproc "split_eta" eta_patstr eta_proc; 

373 
end; 

374 

375 
Addsimprocs [split_beta_proc, split_eta_proc]; 

376 
*} 

377 

378 
lemma split_beta: "(%(x, y). P x y) z = P (fst z) (snd z)" 

379 
by (subst surjective_pairing, rule split_conv) 

380 

381 
lemma split_split: "R (split c p) = (ALL x y. p = (x, y) > R (c x y))" 

382 
 {* For use with @{text split} and the Simplifier. *} 

383 
apply (subst surjective_pairing) 

384 
apply (subst split_conv) 

385 
apply blast 

386 
done 

387 

388 
text {* 

389 
@{thm [source] split_split} could be declared as @{text "[split]"} 

390 
done after the Splitter has been speeded up significantly; 

391 
precompute the constants involved and don't do anything unless the 

392 
current goal contains one of those constants. 

393 
*} 

394 

395 
lemma split_split_asm: "R (split c p) = (~(EX x y. p = (x, y) & (~R (c x y))))" 

396 
apply (subst split_split) 

397 
apply simp 

398 
done 

399 

400 

401 
text {* 

402 
\medskip @{term split} used as a logical connective or set former. 

403 

404 
\medskip These rules are for use with @{text blast}; could instead 

405 
call @{text simp} using @{thm [source] split} as rewrite. *} 

406 

407 
lemma splitI2: "!!p. [ !!a b. p = (a, b) ==> c a b ] ==> split c p" 

408 
apply (simp only: split_tupled_all) 

409 
apply (simp (no_asm_simp)) 

410 
done 

411 

412 
lemma splitI2': "!!p. [ !!a b. (a, b) = p ==> c a b x ] ==> split c p x" 

413 
apply (simp only: split_tupled_all) 

414 
apply (simp (no_asm_simp)) 

415 
done 

416 

417 
lemma splitE: "split c p ==> (!!x y. p = (x, y) ==> c x y ==> Q) ==> Q" 

418 
by (induct p) (auto simp add: split_def) 

419 

420 
lemma splitE': "split c p z ==> (!!x y. p = (x, y) ==> c x y z ==> Q) ==> Q" 

421 
by (induct p) (auto simp add: split_def) 

422 

423 
lemma splitE2: 

424 
"[ Q (split P z); !!x y. [z = (x, y); Q (P x y)] ==> R ] ==> R" 

425 
proof  

426 
assume q: "Q (split P z)" 

427 
assume r: "!!x y. [z = (x, y); Q (P x y)] ==> R" 

428 
show R 

429 
apply (rule r surjective_pairing)+ 

430 
apply (rule split_beta [THEN subst], rule q) 

431 
done 

432 
qed 

433 

434 
lemma splitD': "split R (a,b) c ==> R a b c" 

435 
by simp 

436 

437 
lemma mem_splitI: "z: c a b ==> z: split c (a, b)" 

438 
by simp 

439 

440 
lemma mem_splitI2: "!!p. [ !!a b. p = (a, b) ==> z: c a b ] ==> z: split c p" 

441 
apply (simp only: split_tupled_all) 

442 
apply simp 

443 
done 

444 

445 
lemma mem_splitE: "[ z: split c p; !!x y. [ p = (x,y); z: c x y ] ==> Q ] ==> Q" 

446 
proof  

447 
case rule_context [unfolded split_def] 

448 
show ?thesis by (rule rule_context surjective_pairing)+ 

449 
qed 

450 

451 
declare mem_splitI2 [intro!] mem_splitI [intro!] splitI2' [intro!] splitI2 [intro!] splitI [intro!] 

452 
declare mem_splitE [elim!] splitE' [elim!] splitE [elim!] 

453 

454 
ML_setup " 

455 
local (* filtering with exists_p_split is an essential optimization *) 

456 
fun exists_p_split (Const (\"split\",_) $ _ $ (Const (\"Pair\",_)$_$_)) = true 

457 
 exists_p_split (t $ u) = exists_p_split t orelse exists_p_split u 

458 
 exists_p_split (Abs (_, _, t)) = exists_p_split t 

459 
 exists_p_split _ = false; 

460 
val ss = HOL_basic_ss addsimps [thm \"split_conv\"]; 

461 
in 

462 
val split_conv_tac = SUBGOAL (fn (t, i) => 

463 
if exists_p_split t then safe_full_simp_tac ss i else no_tac); 

464 
end; 

465 
(* This prevents applications of splitE for already splitted arguments leading 

466 
to quite timeconsuming computations (in particular for nested tuples) *) 

467 
claset_ref() := claset() addSbefore (\"split_conv_tac\", split_conv_tac); 

468 
" 

469 

470 
lemma split_eta_SetCompr [simp]: "(%u. EX x y. u = (x, y) & P (x, y)) = P" 

471 
apply (rule ext) 

472 
apply fast 

473 
done 

474 

475 
lemma split_eta_SetCompr2 [simp]: "(%u. EX x y. u = (x, y) & P x y) = split P" 

476 
apply (rule ext) 

477 
apply fast 

478 
done 

479 

480 
lemma split_part [simp]: "(%(a,b). P & Q a b) = (%ab. P & split Q ab)" 

481 
 {* Allows simplifications of nested splits in case of independent predicates. *} 

482 
apply (rule ext) 

483 
apply blast 

484 
done 

485 

486 
lemma The_split_eq [simp]: "(THE (x',y'). x = x' & y = y') = (x, y)" 

487 
by blast 

488 

489 
(* 

490 
the following would be slightly more general, 

491 
but cannot be used as rewrite rule: 

492 
### Cannot add premise as rewrite rule because it contains (type) unknowns: 

493 
### ?y = .x 

494 
Goal "[ P y; !!x. P x ==> x = y ] ==> (@(x',y). x = x' & P y) = (x,y)" 

495 
by (rtac some_equality 1); 

496 
by ( Simp_tac 1); 

497 
by (split_all_tac 1); 

498 
by (Asm_full_simp_tac 1); 

499 
qed "The_split_eq"; 

500 
*) 

501 

502 
lemma injective_fst_snd: "!!x y. [fst x = fst y; snd x = snd y] ==> x = y" 

503 
by auto 

504 

505 

506 
text {* 

507 
\bigskip @{term prod_fun}  action of the product functor upon 

508 
functions. 

509 
*} 

510 

511 
lemma prod_fun [simp]: "prod_fun f g (a, b) = (f a, g b)" 

512 
by (simp add: prod_fun_def) 

513 

514 
lemma prod_fun_compose: "prod_fun (f1 o f2) (g1 o g2) = (prod_fun f1 g1 o prod_fun f2 g2)" 

515 
apply (rule ext) 

516 
apply (tactic {* pair_tac "x" 1 *}) 

517 
apply simp 

518 
done 

519 

520 
lemma prod_fun_ident [simp]: "prod_fun (%x. x) (%y. y) = (%z. z)" 

521 
apply (rule ext) 

522 
apply (tactic {* pair_tac "z" 1 *}) 

523 
apply simp 

524 
done 

525 

526 
lemma prod_fun_imageI [intro]: "(a, b) : r ==> (f a, g b) : prod_fun f g ` r" 

527 
apply (rule image_eqI) 

528 
apply (rule prod_fun [symmetric]) 

529 
apply assumption 

530 
done 

531 

532 
lemma prod_fun_imageE [elim!]: 

533 
"[ c: (prod_fun f g)`r; !!x y. [ c=(f(x),g(y)); (x,y):r ] ==> P 

534 
] ==> P" 

535 
proof  

536 
case rule_context 

537 
assume major: "c: (prod_fun f g)`r" 

538 
show ?thesis 

539 
apply (rule major [THEN imageE]) 

540 
apply (rule_tac p = x in PairE) 

541 
apply (rule rule_context) 

542 
prefer 2 

543 
apply blast 

544 
apply (blast intro: prod_fun) 

545 
done 

546 
qed 

547 

548 

549 
text {* 

550 
\bigskip Disjoint union of a family of sets  Sigma. 

551 
*} 

552 

553 
lemma SigmaI [intro!]: "[ a:A; b:B(a) ] ==> (a,b) : Sigma A B" 

554 
by (unfold Sigma_def) blast 

555 

556 

557 
lemma SigmaE: 

558 
"[ c: Sigma A B; 

559 
!!x y.[ x:A; y:B(x); c=(x,y) ] ==> P 

560 
] ==> P" 

561 
 {* The general elimination rule. *} 

562 
by (unfold Sigma_def) blast 

563 

564 
text {* 

565 
Elimination of @{term "(a, b) : A \<times> B"}  introduces no 

566 
eigenvariables. 

567 
*} 

568 

569 
lemma SigmaD1: "(a, b) : Sigma A B ==> a : A" 

570 
apply (erule SigmaE) 

571 
apply blast 

572 
done 

573 

574 
lemma SigmaD2: "(a, b) : Sigma A B ==> b : B a" 

575 
apply (erule SigmaE) 

576 
apply blast 

577 
done 

578 

579 
lemma SigmaE2: 

580 
"[ (a, b) : Sigma A B; 

581 
[ a:A; b:B(a) ] ==> P 

582 
] ==> P" 

583 
by (blast dest: SigmaD1 SigmaD2) 

584 

585 
declare SigmaE [elim!] SigmaE2 [elim!] 

586 

587 
lemma Sigma_mono: "[ A <= C; !!x. x:A ==> B x <= D x ] ==> Sigma A B <= Sigma C D" 

588 
by blast 

589 

590 
lemma Sigma_empty1 [simp]: "Sigma {} B = {}" 

591 
by blast 

592 

593 
lemma Sigma_empty2 [simp]: "A <*> {} = {}" 

594 
by blast 

595 

596 
lemma UNIV_Times_UNIV [simp]: "UNIV <*> UNIV = UNIV" 

597 
by auto 

598 

599 
lemma Compl_Times_UNIV1 [simp]: " (UNIV <*> A) = UNIV <*> (A)" 

600 
by auto 

601 

602 
lemma Compl_Times_UNIV2 [simp]: " (A <*> UNIV) = (A) <*> UNIV" 

603 
by auto 

604 

605 
lemma mem_Sigma_iff [iff]: "((a,b): Sigma A B) = (a:A & b:B(a))" 

606 
by blast 

607 

608 
lemma Times_subset_cancel2: "x:C ==> (A <*> C <= B <*> C) = (A <= B)" 

609 
by blast 

610 

611 
lemma Times_eq_cancel2: "x:C ==> (A <*> C = B <*> C) = (A = B)" 

612 
by (blast elim: equalityE) 

613 

614 
lemma SetCompr_Sigma_eq: 

615 
"Collect (split (%x y. P x & Q x y)) = (SIGMA x:Collect P. Collect (Q x))" 

616 
by blast 

617 

618 
text {* 

619 
\bigskip Complex rules for Sigma. 

620 
*} 

621 

622 
lemma Collect_split [simp]: "{(a,b). P a & Q b} = Collect P <*> Collect Q" 

623 
by blast 

624 

625 
lemma UN_Times_distrib: 

626 
"(UN (a,b):(A <*> B). E a <*> F b) = (UNION A E) <*> (UNION B F)" 

627 
 {* Suggested by Pierre Chartier *} 

628 
by blast 

629 

630 
lemma split_paired_Ball_Sigma [simp]: 

631 
"(ALL z: Sigma A B. P z) = (ALL x:A. ALL y: B x. P(x,y))" 

632 
by blast 

633 

634 
lemma split_paired_Bex_Sigma [simp]: 

635 
"(EX z: Sigma A B. P z) = (EX x:A. EX y: B x. P(x,y))" 

636 
by blast 

637 

638 
lemma Sigma_Un_distrib1: "(SIGMA i:I Un J. C(i)) = (SIGMA i:I. C(i)) Un (SIGMA j:J. C(j))" 

639 
by blast 

640 

641 
lemma Sigma_Un_distrib2: "(SIGMA i:I. A(i) Un B(i)) = (SIGMA i:I. A(i)) Un (SIGMA i:I. B(i))" 

642 
by blast 

643 

644 
lemma Sigma_Int_distrib1: "(SIGMA i:I Int J. C(i)) = (SIGMA i:I. C(i)) Int (SIGMA j:J. C(j))" 

645 
by blast 

646 

647 
lemma Sigma_Int_distrib2: "(SIGMA i:I. A(i) Int B(i)) = (SIGMA i:I. A(i)) Int (SIGMA i:I. B(i))" 

648 
by blast 

649 

650 
lemma Sigma_Diff_distrib1: "(SIGMA i:I  J. C(i)) = (SIGMA i:I. C(i))  (SIGMA j:J. C(j))" 

651 
by blast 

652 

653 
lemma Sigma_Diff_distrib2: "(SIGMA i:I. A(i)  B(i)) = (SIGMA i:I. A(i))  (SIGMA i:I. B(i))" 

654 
by blast 

655 

656 
lemma Sigma_Union: "Sigma (Union X) B = (UN A:X. Sigma A B)" 

657 
by blast 

658 

659 
text {* 

660 
Nondependent versions are needed to avoid the need for higherorder 

661 
matching, especially when the rules are reoriented. 

662 
*} 

663 

664 
lemma Times_Un_distrib1: "(A Un B) <*> C = (A <*> C) Un (B <*> C)" 

665 
by blast 

666 

667 
lemma Times_Int_distrib1: "(A Int B) <*> C = (A <*> C) Int (B <*> C)" 

668 
by blast 

669 

670 
lemma Times_Diff_distrib1: "(A  B) <*> C = (A <*> C)  (B <*> C)" 

671 
by blast 

672 

673 

11493  674 
lemma pair_imageI [intro]: "(a, b) : A ==> f a b : (%(a, b). f a b) ` A" 
11777  675 
apply (rule_tac x = "(a, b)" in image_eqI) 
676 
apply auto 

677 
done 

678 

11493  679 

11838  680 
text {* 
681 
Setup of internal @{text split_rule}. 

682 
*} 

683 

11032  684 
constdefs 
11425  685 
internal_split :: "('a => 'b => 'c) => 'a * 'b => 'c" 
11032  686 
"internal_split == split" 
687 

688 
lemma internal_split_conv: "internal_split c (a, b) = c a b" 

689 
by (simp only: internal_split_def split_conv) 

690 

691 
hide const internal_split 

692 

11025
a70b796d9af8
converted to Isar therory, adding attributes complete_split and split_format
oheimb
parents:
10289
diff
changeset

693 
use "Tools/split_rule.ML" 
11032  694 
setup SplitRule.setup 
10213  695 

696 
end 