author | huffman |
Sat, 27 Feb 2010 08:30:11 -0800 | |
changeset 35457 | d63655b88369 |
parent 35456 | 5356534f880e |
child 35458 | deaf221c4a59 |
permissions | -rw-r--r-- |
35444 | 1 |
(* Title: HOLCF/Tools/domain/domain_constructors.ML |
2 |
Author: Brian Huffman |
|
3 |
||
4 |
Defines constructor functions for a given domain isomorphism |
|
5 |
and proves related theorems. |
|
6 |
*) |
|
7 |
||
8 |
signature DOMAIN_CONSTRUCTORS = |
|
9 |
sig |
|
10 |
val add_domain_constructors : |
|
11 |
string |
|
12 |
-> typ * (binding * (bool * binding option * typ) list * mixfix) list |
|
13 |
-> term * term |
|
14 |
-> thm * thm |
|
15 |
-> theory |
|
16 |
-> { con_consts : term list, |
|
35451 | 17 |
con_betas : thm list, |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
18 |
exhaust : thm, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
19 |
casedist : thm, |
35448
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
20 |
con_compacts : thm list, |
35452
cf8c5a751a9a
move proof of con_rews into domain_constructor.ML
huffman
parents:
35451
diff
changeset
|
21 |
con_rews : thm list, |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
22 |
inverts : thm list, |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
23 |
injects : thm list, |
35453 | 24 |
sel_rews : thm list |
25 |
} * theory; |
|
35444 | 26 |
end; |
27 |
||
28 |
||
29 |
structure Domain_Constructors :> DOMAIN_CONSTRUCTORS = |
|
30 |
struct |
|
31 |
||
32 |
(******************************************************************************) |
|
33 |
(************************** building types and terms **************************) |
|
34 |
(******************************************************************************) |
|
35 |
||
36 |
||
35448
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
37 |
(*** Operations from Isabelle/HOL ***) |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
38 |
|
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
39 |
val boolT = HOLogic.boolT; |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
40 |
|
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
41 |
val mk_equals = Logic.mk_equals; |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
42 |
val mk_eq = HOLogic.mk_eq; |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
43 |
val mk_trp = HOLogic.mk_Trueprop; |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
44 |
val mk_fst = HOLogic.mk_fst; |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
45 |
val mk_snd = HOLogic.mk_snd; |
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
46 |
val mk_not = HOLogic.mk_not; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
47 |
val mk_conj = HOLogic.mk_conj; |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
48 |
val mk_disj = HOLogic.mk_disj; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
49 |
|
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
50 |
fun mk_ex (x, t) = HOLogic.exists_const (fastype_of x) $ Term.lambda x t; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
51 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
52 |
(*** Basic HOLCF concepts ***) |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
53 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
54 |
fun mk_bottom T = Const (@{const_name UU}, T); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
55 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
56 |
fun below_const T = Const (@{const_name below}, [T, T] ---> boolT); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
57 |
fun mk_below (t, u) = below_const (fastype_of t) $ t $ u; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
58 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
59 |
fun mk_undef t = mk_eq (t, mk_bottom (fastype_of t)); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
60 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
61 |
fun mk_defined t = mk_not (mk_undef t); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
62 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
63 |
fun mk_compact t = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
64 |
Const (@{const_name compact}, fastype_of t --> boolT) $ t; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
65 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
66 |
fun mk_cont t = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
67 |
Const (@{const_name cont}, fastype_of t --> boolT) $ t; |
35448
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
68 |
|
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
69 |
|
35444 | 70 |
(*** Continuous function space ***) |
71 |
||
72 |
(* ->> is taken from holcf_logic.ML *) |
|
73 |
fun mk_cfunT (T, U) = Type(@{type_name "->"}, [T, U]); |
|
74 |
||
75 |
infixr 6 ->>; val (op ->>) = mk_cfunT; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
76 |
infix -->>; val (op -->>) = Library.foldr mk_cfunT; |
35444 | 77 |
|
78 |
fun dest_cfunT (Type(@{type_name "->"}, [T, U])) = (T, U) |
|
79 |
| dest_cfunT T = raise TYPE ("dest_cfunT", [T], []); |
|
80 |
||
81 |
fun capply_const (S, T) = |
|
82 |
Const(@{const_name Rep_CFun}, (S ->> T) --> (S --> T)); |
|
83 |
||
84 |
fun cabs_const (S, T) = |
|
85 |
Const(@{const_name Abs_CFun}, (S --> T) --> (S ->> T)); |
|
86 |
||
87 |
fun mk_cabs t = |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
88 |
let val T = fastype_of t |
35444 | 89 |
in cabs_const (Term.domain_type T, Term.range_type T) $ t end |
90 |
||
91 |
(* builds the expression (LAM v. rhs) *) |
|
92 |
fun big_lambda v rhs = |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
93 |
cabs_const (fastype_of v, fastype_of rhs) $ Term.lambda v rhs; |
35444 | 94 |
|
95 |
(* builds the expression (LAM v1 v2 .. vn. rhs) *) |
|
96 |
fun big_lambdas [] rhs = rhs |
|
97 |
| big_lambdas (v::vs) rhs = big_lambda v (big_lambdas vs rhs); |
|
98 |
||
99 |
fun mk_capply (t, u) = |
|
100 |
let val (S, T) = |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
101 |
case fastype_of t of |
35444 | 102 |
Type(@{type_name "->"}, [S, T]) => (S, T) |
103 |
| _ => raise TERM ("mk_capply " ^ ML_Syntax.print_list ML_Syntax.print_term [t, u], [t, u]); |
|
104 |
in capply_const (S, T) $ t $ u end; |
|
105 |
||
106 |
infix 9 ` ; val (op `) = mk_capply; |
|
107 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
108 |
val list_ccomb : term * term list -> term = Library.foldl mk_capply; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
109 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
110 |
fun mk_ID T = Const (@{const_name ID}, T ->> T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
111 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
112 |
fun cfcomp_const (T, U, V) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
113 |
Const (@{const_name cfcomp}, (U ->> V) ->> (T ->> U) ->> (T ->> V)); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
114 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
115 |
fun mk_cfcomp (f, g) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
116 |
let |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
117 |
val (U, V) = dest_cfunT (fastype_of f); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
118 |
val (T, U') = dest_cfunT (fastype_of g); |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
119 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
120 |
if U = U' |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
121 |
then mk_capply (mk_capply (cfcomp_const (T, U, V), f), g) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
122 |
else raise TYPE ("mk_cfcomp", [U, U'], [f, g]) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
123 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
124 |
|
35444 | 125 |
|
126 |
(*** Product type ***) |
|
127 |
||
128 |
fun mk_tupleT [] = HOLogic.unitT |
|
129 |
| mk_tupleT [T] = T |
|
130 |
| mk_tupleT (T :: Ts) = HOLogic.mk_prodT (T, mk_tupleT Ts); |
|
131 |
||
132 |
(* builds the expression (v1,v2,..,vn) *) |
|
133 |
fun mk_tuple [] = HOLogic.unit |
|
134 |
| mk_tuple (t::[]) = t |
|
135 |
| mk_tuple (t::ts) = HOLogic.mk_prod (t, mk_tuple ts); |
|
136 |
||
137 |
(* builds the expression (%(v1,v2,..,vn). rhs) *) |
|
138 |
fun lambda_tuple [] rhs = Term.lambda (Free("unit", HOLogic.unitT)) rhs |
|
139 |
| lambda_tuple (v::[]) rhs = Term.lambda v rhs |
|
140 |
| lambda_tuple (v::vs) rhs = |
|
141 |
HOLogic.mk_split (Term.lambda v (lambda_tuple vs rhs)); |
|
142 |
||
143 |
||
144 |
(*** Lifted cpo type ***) |
|
145 |
||
146 |
fun mk_upT T = Type(@{type_name "u"}, [T]); |
|
147 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
148 |
fun dest_upT (Type(@{type_name "u"}, [T])) = T |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
149 |
| dest_upT T = raise TYPE ("dest_upT", [T], []); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
150 |
|
35444 | 151 |
fun up_const T = Const(@{const_name up}, T ->> mk_upT T); |
152 |
||
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
153 |
fun mk_up t = up_const (fastype_of t) ` t; |
35444 | 154 |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
155 |
fun fup_const (T, U) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
156 |
Const(@{const_name fup}, (T ->> U) ->> mk_upT T ->> U); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
157 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
158 |
fun from_up T = fup_const (T, T) ` mk_ID T; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
159 |
|
35444 | 160 |
|
161 |
(*** Strict product type ***) |
|
162 |
||
163 |
val oneT = @{typ "one"}; |
|
164 |
||
165 |
fun mk_sprodT (T, U) = Type(@{type_name "**"}, [T, U]); |
|
166 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
167 |
fun dest_sprodT (Type(@{type_name "**"}, [T, U])) = (T, U) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
168 |
| dest_sprodT T = raise TYPE ("dest_sprodT", [T], []); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
169 |
|
35444 | 170 |
fun spair_const (T, U) = |
171 |
Const(@{const_name spair}, T ->> U ->> mk_sprodT (T, U)); |
|
172 |
||
173 |
(* builds the expression (:t, u:) *) |
|
174 |
fun mk_spair (t, u) = |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
175 |
spair_const (fastype_of t, fastype_of u) ` t ` u; |
35444 | 176 |
|
177 |
(* builds the expression (:t1,t2,..,tn:) *) |
|
178 |
fun mk_stuple [] = @{term "ONE"} |
|
179 |
| mk_stuple (t::[]) = t |
|
180 |
| mk_stuple (t::ts) = mk_spair (t, mk_stuple ts); |
|
181 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
182 |
fun sfst_const (T, U) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
183 |
Const(@{const_name sfst}, mk_sprodT (T, U) ->> T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
184 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
185 |
fun ssnd_const (T, U) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
186 |
Const(@{const_name ssnd}, mk_sprodT (T, U) ->> U); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
187 |
|
35444 | 188 |
|
189 |
(*** Strict sum type ***) |
|
190 |
||
191 |
fun mk_ssumT (T, U) = Type(@{type_name "++"}, [T, U]); |
|
192 |
||
193 |
fun dest_ssumT (Type(@{type_name "++"}, [T, U])) = (T, U) |
|
194 |
| dest_ssumT T = raise TYPE ("dest_ssumT", [T], []); |
|
195 |
||
196 |
fun sinl_const (T, U) = Const(@{const_name sinl}, T ->> mk_ssumT (T, U)); |
|
197 |
fun sinr_const (T, U) = Const(@{const_name sinr}, U ->> mk_ssumT (T, U)); |
|
198 |
||
199 |
(* builds the list [sinl(t1), sinl(sinr(t2)), ... sinr(...sinr(tn))] *) |
|
200 |
fun mk_sinjects ts = |
|
201 |
let |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
202 |
val Ts = map fastype_of ts; |
35444 | 203 |
fun combine (t, T) (us, U) = |
204 |
let |
|
205 |
val v = sinl_const (T, U) ` t; |
|
206 |
val vs = map (fn u => sinr_const (T, U) ` u) us; |
|
207 |
in |
|
208 |
(v::vs, mk_ssumT (T, U)) |
|
209 |
end |
|
210 |
fun inj [] = error "mk_sinjects: empty list" |
|
211 |
| inj ((t, T)::[]) = ([t], T) |
|
212 |
| inj ((t, T)::ts) = combine (t, T) (inj ts); |
|
213 |
in |
|
214 |
fst (inj (ts ~~ Ts)) |
|
215 |
end; |
|
216 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
217 |
fun sscase_const (T, U, V) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
218 |
Const(@{const_name sscase}, |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
219 |
(T ->> V) ->> (U ->> V) ->> mk_ssumT (T, U) ->> V); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
220 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
221 |
fun from_sinl (T, U) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
222 |
sscase_const (T, U, T) ` mk_ID T ` mk_bottom (U ->> T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
223 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
224 |
fun from_sinr (T, U) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
225 |
sscase_const (T, U, U) ` mk_bottom (T ->> U) ` mk_ID U; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
226 |
|
35444 | 227 |
|
228 |
(*** miscellaneous constructions ***) |
|
229 |
||
230 |
val trT = @{typ "tr"}; |
|
231 |
||
232 |
val deflT = @{typ "udom alg_defl"}; |
|
233 |
||
234 |
fun mapT T = |
|
235 |
let |
|
236 |
fun argTs (Type (_, Ts)) = Ts | argTs _ = []; |
|
237 |
fun auto T = T ->> T; |
|
238 |
in |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
239 |
map auto (argTs T) -->> auto T |
35444 | 240 |
end; |
241 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
242 |
fun mk_strict t = |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
243 |
let val (T, U) = dest_cfunT (fastype_of t); |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
244 |
in mk_eq (t ` mk_bottom T, mk_bottom U) end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
245 |
|
35444 | 246 |
fun mk_fix t = |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
247 |
let val (T, _) = dest_cfunT (fastype_of t) |
35444 | 248 |
in mk_capply (Const(@{const_name fix}, (T ->> T) ->> T), t) end; |
249 |
||
250 |
fun mk_Rep_of T = |
|
251 |
Const (@{const_name Rep_of}, Term.itselfT T --> deflT) $ Logic.mk_type T; |
|
252 |
||
253 |
fun coerce_const T = Const (@{const_name coerce}, T); |
|
254 |
||
255 |
fun isodefl_const T = |
|
35448
f9f73f0475eb
move proof of compactness rules into domain_constructors.ML
huffman
parents:
35447
diff
changeset
|
256 |
Const (@{const_name isodefl}, (T ->> T) --> deflT --> boolT); |
35444 | 257 |
|
258 |
(* splits a cterm into the right and lefthand sides of equality *) |
|
259 |
fun dest_eqs t = HOLogic.dest_eq (HOLogic.dest_Trueprop t); |
|
260 |
||
261 |
fun mk_eqs (t, u) = HOLogic.mk_Trueprop (HOLogic.mk_eq (t, u)); |
|
262 |
||
263 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
264 |
(************************** miscellaneous functions ***************************) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
265 |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
266 |
val simple_ss : simpset = HOL_basic_ss addsimps simp_thms; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
267 |
|
35444 | 268 |
fun define_consts |
269 |
(specs : (binding * term * mixfix) list) |
|
270 |
(thy : theory) |
|
271 |
: (term list * thm list) * theory = |
|
272 |
let |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
273 |
fun mk_decl (b, t, mx) = (b, fastype_of t, mx); |
35444 | 274 |
val decls = map mk_decl specs; |
275 |
val thy = Cont_Consts.add_consts decls thy; |
|
276 |
fun mk_const (b, T, mx) = Const (Sign.full_name thy b, T); |
|
277 |
val consts = map mk_const decls; |
|
278 |
fun mk_def c (b, t, mx) = |
|
279 |
(Binding.suffix_name "_def" b, Logic.mk_equals (c, t)); |
|
280 |
val defs = map2 mk_def consts specs; |
|
281 |
val (def_thms, thy) = |
|
282 |
PureThy.add_defs false (map Thm.no_attributes defs) thy; |
|
283 |
in |
|
284 |
((consts, def_thms), thy) |
|
285 |
end; |
|
286 |
||
35449 | 287 |
fun prove |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
288 |
(thy : theory) |
35449 | 289 |
(defs : thm list) |
35447 | 290 |
(goal : term) |
35449 | 291 |
(tacs : {prems: thm list, context: Proof.context} -> tactic list) |
35447 | 292 |
: thm = |
35449 | 293 |
let |
294 |
fun tac {prems, context} = |
|
295 |
rewrite_goals_tac defs THEN |
|
296 |
EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context}) |
|
297 |
in |
|
298 |
Goal.prove_global thy [] [] goal tac |
|
299 |
end; |
|
35445 | 300 |
|
301 |
(************** generating beta reduction rules from definitions **************) |
|
35444 | 302 |
|
35445 | 303 |
local |
304 |
fun arglist (Const _ $ Abs (s, T, t)) = |
|
305 |
let |
|
306 |
val arg = Free (s, T); |
|
307 |
val (args, body) = arglist (subst_bound (arg, t)); |
|
308 |
in (arg :: args, body) end |
|
309 |
| arglist t = ([], t); |
|
310 |
in |
|
311 |
fun beta_of_def thy def_thm = |
|
312 |
let |
|
313 |
val (con, lam) = Logic.dest_equals (concl_of def_thm); |
|
314 |
val (args, rhs) = arglist lam; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
315 |
val lhs = list_ccomb (con, args); |
35445 | 316 |
val goal = mk_equals (lhs, rhs); |
317 |
val cs = ContProc.cont_thms lam; |
|
318 |
val betas = map (fn c => mk_meta_eq (c RS @{thm beta_cfun})) cs; |
|
319 |
in |
|
35449 | 320 |
prove thy (def_thm::betas) goal (K [rtac reflexive_thm 1]) |
35445 | 321 |
end; |
322 |
end; |
|
35444 | 323 |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
324 |
(******************************************************************************) |
35453 | 325 |
(************* definitions and theorems for constructor functions *************) |
326 |
(******************************************************************************) |
|
327 |
||
328 |
fun add_constructors |
|
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
329 |
(spec : (binding * (bool * typ) list * mixfix) list) |
35453 | 330 |
(abs_const : term) |
331 |
(iso_locale : thm) |
|
332 |
(thy : theory) |
|
333 |
= |
|
334 |
let |
|
335 |
||
336 |
(* get theorems about rep and abs *) |
|
337 |
val abs_strict = iso_locale RS @{thm iso.abs_strict}; |
|
338 |
||
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
339 |
(* get types of type isomorphism *) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
340 |
val (rhsT, lhsT) = dest_cfunT (fastype_of abs_const); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
341 |
|
35455 | 342 |
fun vars_of args = |
343 |
let |
|
344 |
val Ts = map snd args; |
|
345 |
val ns = Datatype_Prop.make_tnames Ts; |
|
346 |
in |
|
347 |
map Free (ns ~~ Ts) |
|
348 |
end; |
|
349 |
||
35453 | 350 |
(* define constructor functions *) |
351 |
val ((con_consts, con_defs), thy) = |
|
352 |
let |
|
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
353 |
fun one_arg (lazy, T) var = if lazy then mk_up var else var; |
35453 | 354 |
fun one_con (_,args,_) = mk_stuple (map2 one_arg args (vars_of args)); |
355 |
fun mk_abs t = abs_const ` t; |
|
356 |
val rhss = map mk_abs (mk_sinjects (map one_con spec)); |
|
357 |
fun mk_def (bind, args, mx) rhs = |
|
358 |
(bind, big_lambdas (vars_of args) rhs, mx); |
|
359 |
in |
|
360 |
define_consts (map2 mk_def spec rhss) thy |
|
361 |
end; |
|
362 |
||
363 |
(* prove beta reduction rules for constructors *) |
|
364 |
val con_betas = map (beta_of_def thy) con_defs; |
|
365 |
||
366 |
(* replace bindings with terms in constructor spec *) |
|
367 |
val spec' : (term * (bool * typ) list) list = |
|
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
368 |
let fun one_con con (b, args, mx) = (con, args); |
35453 | 369 |
in map2 one_con con_consts spec end; |
370 |
||
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
371 |
(* prove exhaustiveness of constructors *) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
372 |
local |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
373 |
fun arg2typ n (true, T) = (n+1, mk_upT (TVar (("'a", n), @{sort cpo}))) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
374 |
| arg2typ n (false, T) = (n+1, TVar (("'a", n), @{sort pcpo})); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
375 |
fun args2typ n [] = (n, oneT) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
376 |
| args2typ n [arg] = arg2typ n arg |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
377 |
| args2typ n (arg::args) = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
378 |
let |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
379 |
val (n1, t1) = arg2typ n arg; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
380 |
val (n2, t2) = args2typ n1 args |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
381 |
in (n2, mk_sprodT (t1, t2)) end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
382 |
fun cons2typ n [] = (n, oneT) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
383 |
| cons2typ n [con] = args2typ n (snd con) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
384 |
| cons2typ n (con::cons) = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
385 |
let |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
386 |
val (n1, t1) = args2typ n (snd con); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
387 |
val (n2, t2) = cons2typ n1 cons |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
388 |
in (n2, mk_ssumT (t1, t2)) end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
389 |
val ct = ctyp_of thy (snd (cons2typ 1 spec')); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
390 |
val thm1 = instantiate' [SOME ct] [] @{thm exh_start}; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
391 |
val thm2 = rewrite_rule (map mk_meta_eq @{thms ex_defined_iffs}) thm1; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
392 |
val thm3 = rewrite_rule [mk_meta_eq @{thm conj_assoc}] thm2; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
393 |
|
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
394 |
val x = Free ("x", lhsT); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
395 |
fun one_con (con, args) = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
396 |
let |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
397 |
val Ts = map snd args; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
398 |
val ns = Name.variant_list ["x"] (Datatype_Prop.make_tnames Ts); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
399 |
val vs = map Free (ns ~~ Ts); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
400 |
val nonlazy = map snd (filter_out (fst o fst) (args ~~ vs)); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
401 |
val eqn = mk_eq (x, list_ccomb (con, vs)); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
402 |
val conj = foldr1 mk_conj (eqn :: map mk_defined nonlazy); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
403 |
in Library.foldr mk_ex (vs, conj) end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
404 |
val goal = mk_trp (foldr1 mk_disj (mk_undef x :: map one_con spec')); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
405 |
(* first 3 rules replace "x = UU \/ P" with "rep$x = UU \/ P" *) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
406 |
val tacs = [ |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
407 |
rtac (iso_locale RS @{thm iso.casedist_rule}) 1, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
408 |
rewrite_goals_tac [mk_meta_eq (iso_locale RS @{thm iso.iso_swap})], |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
409 |
rtac thm3 1]; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
410 |
in |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
411 |
val exhaust = prove thy con_betas goal (K tacs); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
412 |
val casedist = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
413 |
(exhaust RS @{thm exh_casedist0}) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
414 |
|> rewrite_rule @{thms exh_casedists} |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
415 |
|> Drule.export_without_context; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
416 |
end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
417 |
|
35453 | 418 |
(* prove compactness rules for constructors *) |
419 |
val con_compacts = |
|
420 |
let |
|
421 |
val rules = @{thms compact_sinl compact_sinr compact_spair |
|
422 |
compact_up compact_ONE}; |
|
423 |
val tacs = |
|
424 |
[rtac (iso_locale RS @{thm iso.compact_abs}) 1, |
|
425 |
REPEAT (resolve_tac rules 1 ORELSE atac 1)]; |
|
426 |
fun con_compact (con, args) = |
|
427 |
let |
|
35455 | 428 |
val vs = vars_of args; |
35453 | 429 |
val con_app = list_ccomb (con, vs); |
430 |
val concl = mk_trp (mk_compact con_app); |
|
431 |
val assms = map (mk_trp o mk_compact) vs; |
|
432 |
val goal = Logic.list_implies (assms, concl); |
|
433 |
in |
|
434 |
prove thy con_betas goal (K tacs) |
|
435 |
end; |
|
436 |
in |
|
437 |
map con_compact spec' |
|
438 |
end; |
|
439 |
||
440 |
(* prove strictness rules for constructors *) |
|
441 |
local |
|
442 |
fun con_strict (con, args) = |
|
443 |
let |
|
444 |
val rules = abs_strict :: @{thms con_strict_rules}; |
|
35455 | 445 |
val vs = vars_of args; |
35453 | 446 |
val nonlazy = map snd (filter_out fst (map fst args ~~ vs)); |
447 |
fun one_strict v' = |
|
448 |
let |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
449 |
val UU = mk_bottom (fastype_of v'); |
35453 | 450 |
val vs' = map (fn v => if v = v' then UU else v) vs; |
451 |
val goal = mk_trp (mk_undef (list_ccomb (con, vs'))); |
|
452 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
|
453 |
in prove thy con_betas goal (K tacs) end; |
|
454 |
in map one_strict nonlazy end; |
|
455 |
||
456 |
fun con_defin (con, args) = |
|
457 |
let |
|
458 |
fun iff_disj (t, []) = HOLogic.mk_not t |
|
459 |
| iff_disj (t, ts) = mk_eq (t, foldr1 HOLogic.mk_disj ts); |
|
35455 | 460 |
val vs = vars_of args; |
35453 | 461 |
val nonlazy = map snd (filter_out fst (map fst args ~~ vs)); |
462 |
val lhs = mk_undef (list_ccomb (con, vs)); |
|
463 |
val rhss = map mk_undef nonlazy; |
|
464 |
val goal = mk_trp (iff_disj (lhs, rhss)); |
|
465 |
val rule1 = iso_locale RS @{thm iso.abs_defined_iff}; |
|
466 |
val rules = rule1 :: @{thms con_defined_iff_rules}; |
|
467 |
val tacs = [simp_tac (HOL_ss addsimps rules) 1]; |
|
468 |
in prove thy con_betas goal (K tacs) end; |
|
469 |
in |
|
470 |
val con_stricts = maps con_strict spec'; |
|
471 |
val con_defins = map con_defin spec'; |
|
472 |
val con_rews = con_stricts @ con_defins; |
|
473 |
end; |
|
474 |
||
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
475 |
(* prove injectiveness of constructors *) |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
476 |
local |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
477 |
fun pgterm rel (con, args) = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
478 |
let |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
479 |
fun prime (Free (n, T)) = Free (n^"'", T) |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
480 |
| prime t = t; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
481 |
val xs = vars_of args; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
482 |
val ys = map prime xs; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
483 |
val nonlazy = map snd (filter_out (fst o fst) (args ~~ xs)); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
484 |
val lhs = rel (list_ccomb (con, xs), list_ccomb (con, ys)); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
485 |
val rhs = foldr1 mk_conj (ListPair.map rel (xs, ys)); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
486 |
val concl = mk_trp (mk_eq (lhs, rhs)); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
487 |
val zs = case args of [_] => [] | _ => nonlazy; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
488 |
val assms = map (mk_trp o mk_defined) zs; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
489 |
val goal = Logic.list_implies (assms, concl); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
490 |
in prove thy con_betas goal end; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
491 |
val cons' = filter (fn (_, args) => not (null args)) spec'; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
492 |
in |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
493 |
val inverts = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
494 |
let |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
495 |
val abs_below = iso_locale RS @{thm iso.abs_below}; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
496 |
val rules1 = abs_below :: @{thms sinl_below sinr_below spair_below up_below}; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
497 |
val rules2 = @{thms up_defined spair_defined ONE_defined} |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
498 |
val rules = rules1 @ rules2; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
499 |
val tacs = [asm_simp_tac (simple_ss addsimps rules) 1]; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
500 |
in map (fn c => pgterm mk_below c (K tacs)) cons' end; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
501 |
val injects = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
502 |
let |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
503 |
val abs_eq = iso_locale RS @{thm iso.abs_eq}; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
504 |
val rules1 = abs_eq :: @{thms sinl_eq sinr_eq spair_eq up_eq}; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
505 |
val rules2 = @{thms up_defined spair_defined ONE_defined} |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
506 |
val rules = rules1 @ rules2; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
507 |
val tacs = [asm_simp_tac (simple_ss addsimps rules) 1]; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
508 |
in map (fn c => pgterm mk_eq c (K tacs)) cons' end; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
509 |
end; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
510 |
|
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
511 |
|
35453 | 512 |
val result = |
513 |
{ |
|
514 |
con_consts = con_consts, |
|
515 |
con_betas = con_betas, |
|
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
516 |
exhaust = exhaust, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
517 |
casedist = casedist, |
35453 | 518 |
con_compacts = con_compacts, |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
519 |
con_rews = con_rews, |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
520 |
inverts = inverts, |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
521 |
injects = injects |
35453 | 522 |
}; |
523 |
in |
|
524 |
(result, thy) |
|
525 |
end; |
|
526 |
||
527 |
(******************************************************************************) |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
528 |
(************** definitions and theorems for selector functions ***************) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
529 |
(******************************************************************************) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
530 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
531 |
fun add_selectors |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
532 |
(spec : (term * (bool * binding option * typ) list) list) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
533 |
(rep_const : term) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
534 |
(abs_inv : thm) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
535 |
(rep_strict : thm) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
536 |
(rep_strict_iff : thm) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
537 |
(con_betas : thm list) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
538 |
(thy : theory) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
539 |
: thm list * theory = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
540 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
541 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
542 |
(* define selector functions *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
543 |
val ((sel_consts, sel_defs), thy) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
544 |
let |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
545 |
fun rangeT s = snd (dest_cfunT (fastype_of s)); |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
546 |
fun mk_outl s = mk_cfcomp (from_sinl (dest_ssumT (rangeT s)), s); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
547 |
fun mk_outr s = mk_cfcomp (from_sinr (dest_ssumT (rangeT s)), s); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
548 |
fun mk_sfst s = mk_cfcomp (sfst_const (dest_sprodT (rangeT s)), s); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
549 |
fun mk_ssnd s = mk_cfcomp (ssnd_const (dest_sprodT (rangeT s)), s); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
550 |
fun mk_down s = mk_cfcomp (from_up (dest_upT (rangeT s)), s); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
551 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
552 |
fun sels_of_arg s (lazy, NONE, T) = [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
553 |
| sels_of_arg s (lazy, SOME b, T) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
554 |
[(b, if lazy then mk_down s else s, NoSyn)]; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
555 |
fun sels_of_args s [] = [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
556 |
| sels_of_args s (v :: []) = sels_of_arg s v |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
557 |
| sels_of_args s (v :: vs) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
558 |
sels_of_arg (mk_sfst s) v @ sels_of_args (mk_ssnd s) vs; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
559 |
fun sels_of_cons s [] = [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
560 |
| sels_of_cons s ((con, args) :: []) = sels_of_args s args |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
561 |
| sels_of_cons s ((con, args) :: cs) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
562 |
sels_of_args (mk_outl s) args @ sels_of_cons (mk_outr s) cs; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
563 |
val sel_eqns : (binding * term * mixfix) list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
564 |
sels_of_cons rep_const spec; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
565 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
566 |
define_consts sel_eqns thy |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
567 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
568 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
569 |
(* replace bindings with terms in constructor spec *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
570 |
val spec2 : (term * (bool * term option * typ) list) list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
571 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
572 |
fun prep_arg (lazy, NONE, T) sels = ((lazy, NONE, T), sels) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
573 |
| prep_arg (lazy, SOME _, T) sels = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
574 |
((lazy, SOME (hd sels), T), tl sels); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
575 |
fun prep_con (con, args) sels = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
576 |
apfst (pair con) (fold_map prep_arg args sels); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
577 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
578 |
fst (fold_map prep_con spec sel_consts) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
579 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
580 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
581 |
(* prove selector strictness rules *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
582 |
val sel_stricts : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
583 |
let |
35449 | 584 |
val rules = rep_strict :: @{thms sel_strict_rules}; |
585 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
586 |
fun sel_strict sel = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
587 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
588 |
val goal = mk_trp (mk_strict sel); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
589 |
in |
35449 | 590 |
prove thy sel_defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
591 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
592 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
593 |
map sel_strict sel_consts |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
594 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
595 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
596 |
(* prove selector application rules *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
597 |
val sel_apps : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
598 |
let |
35449 | 599 |
val defs = con_betas @ sel_defs; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
600 |
val rules = abs_inv :: @{thms sel_app_rules}; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
601 |
val tacs = [asm_simp_tac (simple_ss addsimps rules) 1]; |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
602 |
fun sel_apps_of (i, (con, args)) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
603 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
604 |
val Ts : typ list = map #3 args; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
605 |
val ns : string list = Datatype_Prop.make_tnames Ts; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
606 |
val vs : term list = map Free (ns ~~ Ts); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
607 |
val con_app : term = list_ccomb (con, vs); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
608 |
val vs' : (bool * term) list = map #1 args ~~ vs; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
609 |
fun one_same (n, sel, T) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
610 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
611 |
val xs = map snd (filter_out fst (nth_drop n vs')); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
612 |
val assms = map (mk_trp o mk_defined) xs; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
613 |
val concl = mk_trp (mk_eq (sel ` con_app, nth vs n)); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
614 |
val goal = Logic.list_implies (assms, concl); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
615 |
in |
35449 | 616 |
prove thy defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
617 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
618 |
fun one_diff (n, sel, T) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
619 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
620 |
val goal = mk_trp (mk_eq (sel ` con_app, mk_bottom T)); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
621 |
in |
35449 | 622 |
prove thy defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
623 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
624 |
fun one_con (j, (_, args')) : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
625 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
626 |
fun prep (i, (lazy, NONE, T)) = NONE |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
627 |
| prep (i, (lazy, SOME sel, T)) = SOME (i, sel, T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
628 |
val sels : (int * term * typ) list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
629 |
map_filter prep (map_index I args'); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
630 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
631 |
if i = j |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
632 |
then map one_same sels |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
633 |
else map one_diff sels |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
634 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
635 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
636 |
flat (map_index one_con spec2) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
637 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
638 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
639 |
flat (map_index sel_apps_of spec2) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
640 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
641 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
642 |
(* prove selector definedness rules *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
643 |
val sel_defins : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
644 |
let |
35449 | 645 |
val rules = rep_strict_iff :: @{thms sel_defined_iff_rules}; |
646 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
647 |
fun sel_defin sel = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
648 |
let |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
649 |
val (T, U) = dest_cfunT (fastype_of sel); |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
650 |
val x = Free ("x", T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
651 |
val lhs = mk_eq (sel ` x, mk_bottom U); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
652 |
val rhs = mk_eq (x, mk_bottom T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
653 |
val goal = mk_trp (mk_eq (lhs, rhs)); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
654 |
in |
35449 | 655 |
prove thy sel_defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
656 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
657 |
fun one_arg (false, SOME sel, T) = SOME (sel_defin sel) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
658 |
| one_arg _ = NONE; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
659 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
660 |
case spec2 of |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
661 |
[(con, args)] => map_filter one_arg args |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
662 |
| _ => [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
663 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
664 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
665 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
666 |
(sel_stricts @ sel_defins @ sel_apps, thy) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
667 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
668 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
669 |
(******************************************************************************) |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
670 |
(******************************* main function ********************************) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
671 |
(******************************************************************************) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
672 |
|
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
673 |
fun add_domain_constructors |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
674 |
(dname : string) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
675 |
(lhsT : typ, |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
676 |
spec : (binding * (bool * binding option * typ) list * mixfix) list) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
677 |
(rep_const : term, abs_const : term) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
678 |
(rep_iso_thm : thm, abs_iso_thm : thm) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
679 |
(thy : theory) = |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
680 |
let |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
681 |
|
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
682 |
(* prove rep/abs strictness rules *) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
683 |
val iso_locale = @{thm iso.intro} OF [abs_iso_thm, rep_iso_thm]; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
684 |
val rep_strict = iso_locale RS @{thm iso.rep_strict}; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
685 |
val abs_strict = iso_locale RS @{thm iso.abs_strict}; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
686 |
val rep_defined_iff = iso_locale RS @{thm iso.rep_defined_iff}; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
687 |
val abs_defined_iff = iso_locale RS @{thm iso.abs_defined_iff}; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
688 |
|
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
689 |
(* define constructor functions *) |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
690 |
val (con_result, thy) = |
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
691 |
let |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
692 |
fun prep_arg (lazy, sel, T) = (lazy, T); |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
693 |
fun prep_con (b, args, mx) = (b, map prep_arg args, mx); |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
694 |
val con_spec = map prep_con spec; |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
695 |
in |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
696 |
add_constructors con_spec abs_const iso_locale thy |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
697 |
end; |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
698 |
val {con_consts, con_betas, ...} = con_result; |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
699 |
|
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
700 |
(* TODO: enable this earlier *) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
701 |
val thy = Sign.add_path dname thy; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
702 |
|
35447 | 703 |
(* replace bindings with terms in constructor spec *) |
704 |
val sel_spec : (term * (bool * binding option * typ) list) list = |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
705 |
map2 (fn con => fn (b, args, mx) => (con, args)) con_consts spec; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
706 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
707 |
(* define and prove theorems for selector functions *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
708 |
val (sel_thms : thm list, thy : theory) = |
35447 | 709 |
add_selectors sel_spec rep_const |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
710 |
abs_iso_thm rep_strict rep_defined_iff con_betas thy; |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
711 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
712 |
(* restore original signature path *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
713 |
val thy = Sign.parent_path thy; |
35444 | 714 |
|
715 |
val result = |
|
716 |
{ con_consts = con_consts, |
|
35451 | 717 |
con_betas = con_betas, |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
718 |
exhaust = #exhaust con_result, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
719 |
casedist = #casedist con_result, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
720 |
con_compacts = #con_compacts con_result, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
721 |
con_rews = #con_rews con_result, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
722 |
inverts = #inverts con_result, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
723 |
injects = #injects con_result, |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
724 |
sel_rews = sel_thms }; |
35444 | 725 |
in |
726 |
(result, thy) |
|
727 |
end; |
|
728 |
||
729 |
end; |