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