author | lcp |
Thu, 18 Aug 1994 12:07:51 +0200 | |
changeset 109 | c53c19fb22cb |
parent 107 | 960e332d2e70 |
child 117 | 3716c99fb6a1 |
permissions | -rw-r--r-- |
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
1 |
(* Title: HOL/Sum.ML |
0 | 2 |
ID: $Id$ |
3 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
4 |
Copyright 1991 University of Cambridge |
|
5 |
||
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
6 |
For Sum.thy. The disjoint sum of two types |
0 | 7 |
*) |
8 |
||
9 |
open Sum; |
|
10 |
||
11 |
(** Inl_Rep and Inr_Rep: Representations of the constructors **) |
|
12 |
||
13 |
(*This counts as a non-emptiness result for admitting 'a+'b as a type*) |
|
14 |
goalw Sum.thy [Sum_def] "Inl_Rep(a) : Sum"; |
|
15 |
by (EVERY1 [rtac CollectI, rtac disjI1, rtac exI, rtac refl]); |
|
16 |
val Inl_RepI = result(); |
|
17 |
||
18 |
goalw Sum.thy [Sum_def] "Inr_Rep(b) : Sum"; |
|
19 |
by (EVERY1 [rtac CollectI, rtac disjI2, rtac exI, rtac refl]); |
|
20 |
val Inr_RepI = result(); |
|
21 |
||
22 |
goal Sum.thy "inj_onto(Abs_Sum,Sum)"; |
|
23 |
by (rtac inj_onto_inverseI 1); |
|
24 |
by (etac Abs_Sum_inverse 1); |
|
25 |
val inj_onto_Abs_Sum = result(); |
|
26 |
||
27 |
(** Distinctness of Inl and Inr **) |
|
28 |
||
5 | 29 |
goalw Sum.thy [Inl_Rep_def, Inr_Rep_def] "Inl_Rep(a) ~= Inr_Rep(b)"; |
0 | 30 |
by (EVERY1 [rtac notI, |
31 |
etac (fun_cong RS fun_cong RS fun_cong RS iffE), |
|
32 |
rtac (notE RS ccontr), etac (mp RS conjunct2), |
|
33 |
REPEAT o (ares_tac [refl,conjI]) ]); |
|
34 |
val Inl_Rep_not_Inr_Rep = result(); |
|
35 |
||
5 | 36 |
goalw Sum.thy [Inl_def,Inr_def] "Inl(a) ~= Inr(b)"; |
0 | 37 |
by (rtac (inj_onto_Abs_Sum RS inj_onto_contraD) 1); |
38 |
by (rtac Inl_Rep_not_Inr_Rep 1); |
|
39 |
by (rtac Inl_RepI 1); |
|
40 |
by (rtac Inr_RepI 1); |
|
41 |
val Inl_not_Inr = result(); |
|
42 |
||
43 |
val Inl_neq_Inr = standard (Inl_not_Inr RS notE); |
|
44 |
val Inr_neq_Inl = sym RS Inl_neq_Inr; |
|
45 |
||
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
46 |
goal Sum.thy "(Inl(a)=Inr(b)) = False"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
47 |
by (simp_tac (HOL_ss addsimps [Inl_not_Inr]) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
48 |
val Inl_Inr_eq = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
49 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
50 |
goal Sum.thy "(Inr(b)=Inl(a)) = False"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
51 |
by (simp_tac (HOL_ss addsimps [Inl_not_Inr RS not_sym]) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
52 |
val Inr_Inl_eq = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
53 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
54 |
|
0 | 55 |
(** Injectiveness of Inl and Inr **) |
56 |
||
57 |
val [major] = goalw Sum.thy [Inl_Rep_def] "Inl_Rep(a) = Inl_Rep(c) ==> a=c"; |
|
58 |
by (rtac (major RS fun_cong RS fun_cong RS fun_cong RS iffE) 1); |
|
59 |
by (fast_tac HOL_cs 1); |
|
60 |
val Inl_Rep_inject = result(); |
|
61 |
||
62 |
val [major] = goalw Sum.thy [Inr_Rep_def] "Inr_Rep(b) = Inr_Rep(d) ==> b=d"; |
|
63 |
by (rtac (major RS fun_cong RS fun_cong RS fun_cong RS iffE) 1); |
|
64 |
by (fast_tac HOL_cs 1); |
|
65 |
val Inr_Rep_inject = result(); |
|
66 |
||
67 |
goalw Sum.thy [Inl_def] "inj(Inl)"; |
|
68 |
by (rtac injI 1); |
|
69 |
by (etac (inj_onto_Abs_Sum RS inj_ontoD RS Inl_Rep_inject) 1); |
|
70 |
by (rtac Inl_RepI 1); |
|
71 |
by (rtac Inl_RepI 1); |
|
72 |
val inj_Inl = result(); |
|
73 |
val Inl_inject = inj_Inl RS injD; |
|
74 |
||
75 |
goalw Sum.thy [Inr_def] "inj(Inr)"; |
|
76 |
by (rtac injI 1); |
|
77 |
by (etac (inj_onto_Abs_Sum RS inj_ontoD RS Inr_Rep_inject) 1); |
|
78 |
by (rtac Inr_RepI 1); |
|
79 |
by (rtac Inr_RepI 1); |
|
80 |
val inj_Inr = result(); |
|
81 |
val Inr_inject = inj_Inr RS injD; |
|
82 |
||
83 |
goal Sum.thy "(Inl(x)=Inl(y)) = (x=y)"; |
|
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
84 |
by (fast_tac (HOL_cs addSEs [Inl_inject]) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
85 |
val Inl_eq = result(); |
0 | 86 |
|
87 |
goal Sum.thy "(Inr(x)=Inr(y)) = (x=y)"; |
|
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
88 |
by (fast_tac (HOL_cs addSEs [Inr_inject]) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
89 |
val Inr_eq = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
90 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
91 |
val sum_cs = set_cs addSEs [Inl_neq_Inr, Inr_neq_Inl] |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
92 |
addSDs [Inl_inject, Inr_inject]; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
93 |
|
0 | 94 |
|
38 | 95 |
(** sum_case -- the selection operator for sums **) |
0 | 96 |
|
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
97 |
goalw Sum.thy [sum_case_def] "sum_case(f, g, Inl(x)) = f(x)"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
98 |
by (fast_tac (sum_cs addIs [select_equality]) 1); |
38 | 99 |
val sum_case_Inl = result(); |
0 | 100 |
|
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
101 |
goalw Sum.thy [sum_case_def] "sum_case(f, g, Inr(x)) = g(x)"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
102 |
by (fast_tac (sum_cs addIs [select_equality]) 1); |
38 | 103 |
val sum_case_Inr = result(); |
0 | 104 |
|
105 |
(** Exhaustion rule for sums -- a degenerate form of induction **) |
|
106 |
||
107 |
val prems = goalw Sum.thy [Inl_def,Inr_def] |
|
108 |
"[| !!x::'a. s = Inl(x) ==> P; !!y::'b. s = Inr(y) ==> P \ |
|
109 |
\ |] ==> P"; |
|
110 |
by (rtac (rewrite_rule [Sum_def] Rep_Sum RS CollectE) 1); |
|
111 |
by (REPEAT (eresolve_tac [disjE,exE] 1 |
|
112 |
ORELSE EVERY1 [resolve_tac prems, |
|
113 |
etac subst, |
|
114 |
rtac (Rep_Sum_inverse RS sym)])); |
|
115 |
val sumE = result(); |
|
116 |
||
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
117 |
goal Sum.thy "sum_case(%x::'a. f(Inl(x)), %y::'b. f(Inr(y)), s) = f(s)"; |
0 | 118 |
by (EVERY1 [res_inst_tac [("s","s")] sumE, |
38 | 119 |
etac ssubst, rtac sum_case_Inl, |
120 |
etac ssubst, rtac sum_case_Inr]); |
|
0 | 121 |
val surjective_sum = result(); |
122 |
||
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
123 |
goal Sum.thy "R(sum_case(f,g,s)) = \ |
0 | 124 |
\ ((! x. s = Inl(x) --> R(f(x))) & (! y. s = Inr(y) --> R(g(y))))"; |
125 |
by (rtac sumE 1); |
|
126 |
by (etac ssubst 1); |
|
38 | 127 |
by (stac sum_case_Inl 1); |
0 | 128 |
by (fast_tac (set_cs addSEs [make_elim Inl_inject, Inl_neq_Inr]) 1); |
129 |
by (etac ssubst 1); |
|
38 | 130 |
by (stac sum_case_Inr 1); |
0 | 131 |
by (fast_tac (set_cs addSEs [make_elim Inr_inject, Inr_neq_Inl]) 1); |
38 | 132 |
val expand_sum_case = result(); |
0 | 133 |
|
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
134 |
val sum_ss = prod_ss addsimps [Inl_eq, Inr_eq, Inl_Inr_eq, Inr_Inl_eq, |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
135 |
sum_case_Inl, sum_case_Inr]; |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
136 |
|
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
137 |
(*Prevents simplification of f and g: much faster*) |
38 | 138 |
val sum_case_weak_cong = prove_goal Sum.thy |
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
139 |
"s=t ==> sum_case(f,g,s) = sum_case(f,g,t)" |
2
befa4e9f7c90
Added weak congruence rules to HOL: if_weak_cong, case_weak_cong,
lcp
parents:
0
diff
changeset
|
140 |
(fn [prem] => [rtac (prem RS arg_cong) 1]); |
107
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
141 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
142 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
143 |
(** Rules for the Part primitive **) |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
144 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
145 |
goalw Sum.thy [Part_def] |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
146 |
"!!a b A h. [| a : A; a=h(b) |] ==> a : Part(A,h)"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
147 |
by (fast_tac set_cs 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
148 |
val Part_eqI = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
149 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
150 |
val PartI = refl RSN (2,Part_eqI); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
151 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
152 |
val major::prems = goalw Sum.thy [Part_def] |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
153 |
"[| a : Part(A,h); !!z. [| a : A; a=h(z) |] ==> P \ |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
154 |
\ |] ==> P"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
155 |
by (rtac (major RS IntE) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
156 |
by (etac CollectE 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
157 |
by (etac exE 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
158 |
by (REPEAT (ares_tac prems 1)); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
159 |
val PartE = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
160 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
161 |
goalw Sum.thy [Part_def] "Part(A,h) <= A"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
162 |
by (rtac Int_lower1 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
163 |
val Part_subset = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
164 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
165 |
goal Sum.thy "!!A B. A<=B ==> Part(A,h) <= Part(B,h)"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
166 |
by (fast_tac (set_cs addSIs [PartI] addSEs [PartE]) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
167 |
val Part_mono = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
168 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
169 |
goalw Sum.thy [Part_def] "!!a. a : Part(A,h) ==> a : A"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
170 |
by (etac IntD1 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
171 |
val PartD1 = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
172 |
|
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
173 |
goal Sum.thy "Part(A,%x.x) = A"; |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
174 |
by (fast_tac (set_cs addIs [PartI,equalityI] addSEs [PartE]) 1); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
175 |
val Part_id = result(); |
960e332d2e70
HOL/Sum: rotated arguments of sum_case; added translation for case macro
lcp
parents:
38
diff
changeset
|
176 |