author | huffman |
Sun, 24 Oct 2010 15:19:17 -0700 | |
changeset 40212 | 20df78048db5 |
parent 40019 | 05cda34d36e7 |
child 40213 | b63e966564da |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: HOLCF/Tools/Domain/domain_constructors.ML |
35444 | 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 |
|
40014 | 10 |
type constr_info = |
11 |
{ |
|
40017 | 12 |
iso_info : Domain_Take_Proofs.iso_info, |
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
13 |
con_specs : (term * (bool * typ) list) list, |
40014 | 14 |
con_betas : thm list, |
15 |
nchotomy : thm, |
|
16 |
exhaust : thm, |
|
17 |
compacts : thm list, |
|
18 |
con_rews : thm list, |
|
19 |
inverts : thm list, |
|
20 |
injects : thm list, |
|
21 |
dist_les : thm list, |
|
22 |
dist_eqs : thm list, |
|
23 |
cases : thm list, |
|
24 |
sel_rews : thm list, |
|
25 |
dis_rews : thm list, |
|
26 |
match_rews : thm list |
|
27 |
} |
|
35444 | 28 |
val add_domain_constructors : |
35777
bcc77916b7b9
pass binding as argument to add_domain_constructors; proper binding for case combinator
huffman
parents:
35561
diff
changeset
|
29 |
binding |
35481
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
30 |
-> (binding * (bool * binding option * typ) list * mixfix) list |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35496
diff
changeset
|
31 |
-> Domain_Take_Proofs.iso_info |
35444 | 32 |
-> theory |
40014 | 33 |
-> constr_info * theory; |
35444 | 34 |
end; |
35 |
||
36 |
||
37 |
structure Domain_Constructors :> DOMAIN_CONSTRUCTORS = |
|
38 |
struct |
|
39 |
||
35475
979019ab92eb
move common functions into new file holcf_library.ML
huffman
parents:
35472
diff
changeset
|
40 |
open HOLCF_Library; |
35561 | 41 |
|
35476 | 42 |
infixr 6 ->>; |
43 |
infix -->>; |
|
35561 | 44 |
infix 9 `; |
35444 | 45 |
|
40014 | 46 |
type constr_info = |
47 |
{ |
|
40017 | 48 |
iso_info : Domain_Take_Proofs.iso_info, |
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
49 |
con_specs : (term * (bool * typ) list) list, |
40014 | 50 |
con_betas : thm list, |
51 |
nchotomy : thm, |
|
52 |
exhaust : thm, |
|
53 |
compacts : thm list, |
|
54 |
con_rews : thm list, |
|
55 |
inverts : thm list, |
|
56 |
injects : thm list, |
|
57 |
dist_les : thm list, |
|
58 |
dist_eqs : thm list, |
|
59 |
cases : thm list, |
|
60 |
sel_rews : thm list, |
|
61 |
dis_rews : thm list, |
|
62 |
match_rews : thm list |
|
63 |
} |
|
64 |
||
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
65 |
(************************** miscellaneous functions ***************************) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
66 |
|
37078
a1656804fcad
domain package internal proofs use fixed set of continuity rules, rather than taking cont2cont rules from context
huffman
parents:
36998
diff
changeset
|
67 |
val simple_ss = HOL_basic_ss addsimps simp_thms; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
68 |
|
37078
a1656804fcad
domain package internal proofs use fixed set of continuity rules, rather than taking cont2cont rules from context
huffman
parents:
36998
diff
changeset
|
69 |
val beta_rules = |
a1656804fcad
domain package internal proofs use fixed set of continuity rules, rather than taking cont2cont rules from context
huffman
parents:
36998
diff
changeset
|
70 |
@{thms beta_cfun cont_id cont_const cont2cont_Rep_CFun cont2cont_LAM'} @ |
a1656804fcad
domain package internal proofs use fixed set of continuity rules, rather than taking cont2cont rules from context
huffman
parents:
36998
diff
changeset
|
71 |
@{thms cont2cont_fst cont2cont_snd cont2cont_Pair}; |
a1656804fcad
domain package internal proofs use fixed set of continuity rules, rather than taking cont2cont rules from context
huffman
parents:
36998
diff
changeset
|
72 |
|
a1656804fcad
domain package internal proofs use fixed set of continuity rules, rather than taking cont2cont rules from context
huffman
parents:
36998
diff
changeset
|
73 |
val beta_ss = HOL_basic_ss addsimps (simp_thms @ beta_rules); |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
74 |
|
35444 | 75 |
fun define_consts |
76 |
(specs : (binding * term * mixfix) list) |
|
77 |
(thy : theory) |
|
78 |
: (term list * thm list) * theory = |
|
79 |
let |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
80 |
fun mk_decl (b, t, mx) = (b, fastype_of t, mx); |
35444 | 81 |
val decls = map mk_decl specs; |
82 |
val thy = Cont_Consts.add_consts decls thy; |
|
83 |
fun mk_const (b, T, mx) = Const (Sign.full_name thy b, T); |
|
84 |
val consts = map mk_const decls; |
|
85 |
fun mk_def c (b, t, mx) = |
|
86 |
(Binding.suffix_name "_def" b, Logic.mk_equals (c, t)); |
|
87 |
val defs = map2 mk_def consts specs; |
|
88 |
val (def_thms, thy) = |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
37744
diff
changeset
|
89 |
Global_Theory.add_defs false (map Thm.no_attributes defs) thy; |
35444 | 90 |
in |
91 |
((consts, def_thms), thy) |
|
92 |
end; |
|
93 |
||
35449 | 94 |
fun prove |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
95 |
(thy : theory) |
35449 | 96 |
(defs : thm list) |
35447 | 97 |
(goal : term) |
35449 | 98 |
(tacs : {prems: thm list, context: Proof.context} -> tactic list) |
35447 | 99 |
: thm = |
35449 | 100 |
let |
101 |
fun tac {prems, context} = |
|
102 |
rewrite_goals_tac defs THEN |
|
103 |
EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context}) |
|
104 |
in |
|
105 |
Goal.prove_global thy [] [] goal tac |
|
106 |
end; |
|
35445 | 107 |
|
35483 | 108 |
fun get_vars_avoiding |
109 |
(taken : string list) |
|
110 |
(args : (bool * typ) list) |
|
111 |
: (term list * term list) = |
|
112 |
let |
|
113 |
val Ts = map snd args; |
|
114 |
val ns = Name.variant_list taken (Datatype_Prop.make_tnames Ts); |
|
115 |
val vs = map Free (ns ~~ Ts); |
|
116 |
val nonlazy = map snd (filter_out (fst o fst) (args ~~ vs)); |
|
117 |
in |
|
118 |
(vs, nonlazy) |
|
119 |
end; |
|
120 |
||
121 |
fun get_vars args = get_vars_avoiding [] args; |
|
122 |
||
35445 | 123 |
(************** generating beta reduction rules from definitions **************) |
35444 | 124 |
|
35445 | 125 |
local |
126 |
fun arglist (Const _ $ Abs (s, T, t)) = |
|
127 |
let |
|
128 |
val arg = Free (s, T); |
|
129 |
val (args, body) = arglist (subst_bound (arg, t)); |
|
130 |
in (arg :: args, body) end |
|
131 |
| arglist t = ([], t); |
|
132 |
in |
|
133 |
fun beta_of_def thy def_thm = |
|
134 |
let |
|
135 |
val (con, lam) = Logic.dest_equals (concl_of def_thm); |
|
136 |
val (args, rhs) = arglist lam; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
137 |
val lhs = list_ccomb (con, args); |
35445 | 138 |
val goal = mk_equals (lhs, rhs); |
139 |
val cs = ContProc.cont_thms lam; |
|
140 |
val betas = map (fn c => mk_meta_eq (c RS @{thm beta_cfun})) cs; |
|
141 |
in |
|
35449 | 142 |
prove thy (def_thm::betas) goal (K [rtac reflexive_thm 1]) |
35445 | 143 |
end; |
144 |
end; |
|
35444 | 145 |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
146 |
(******************************************************************************) |
35453 | 147 |
(************* definitions and theorems for constructor functions *************) |
148 |
(******************************************************************************) |
|
149 |
||
150 |
fun add_constructors |
|
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
151 |
(spec : (binding * (bool * typ) list * mixfix) list) |
35453 | 152 |
(abs_const : term) |
153 |
(iso_locale : thm) |
|
154 |
(thy : theory) |
|
155 |
= |
|
156 |
let |
|
157 |
||
158 |
(* get theorems about rep and abs *) |
|
159 |
val abs_strict = iso_locale RS @{thm iso.abs_strict}; |
|
160 |
||
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
161 |
(* get types of type isomorphism *) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
162 |
val (rhsT, lhsT) = dest_cfunT (fastype_of abs_const); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
163 |
|
35455 | 164 |
fun vars_of args = |
165 |
let |
|
166 |
val Ts = map snd args; |
|
167 |
val ns = Datatype_Prop.make_tnames Ts; |
|
168 |
in |
|
169 |
map Free (ns ~~ Ts) |
|
170 |
end; |
|
171 |
||
35453 | 172 |
(* define constructor functions *) |
173 |
val ((con_consts, con_defs), thy) = |
|
174 |
let |
|
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
175 |
fun one_arg (lazy, T) var = if lazy then mk_up var else var; |
35453 | 176 |
fun one_con (_,args,_) = mk_stuple (map2 one_arg args (vars_of args)); |
177 |
fun mk_abs t = abs_const ` t; |
|
178 |
val rhss = map mk_abs (mk_sinjects (map one_con spec)); |
|
179 |
fun mk_def (bind, args, mx) rhs = |
|
180 |
(bind, big_lambdas (vars_of args) rhs, mx); |
|
181 |
in |
|
182 |
define_consts (map2 mk_def spec rhss) thy |
|
183 |
end; |
|
184 |
||
185 |
(* prove beta reduction rules for constructors *) |
|
186 |
val con_betas = map (beta_of_def thy) con_defs; |
|
187 |
||
188 |
(* replace bindings with terms in constructor spec *) |
|
189 |
val spec' : (term * (bool * typ) list) list = |
|
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
190 |
let fun one_con con (b, args, mx) = (con, args); |
35453 | 191 |
in map2 one_con con_consts spec end; |
192 |
||
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
193 |
(* prove exhaustiveness of constructors *) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
194 |
local |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
195 |
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
|
196 |
| 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
|
197 |
fun args2typ n [] = (n, oneT) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
198 |
| args2typ n [arg] = arg2typ n arg |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
199 |
| args2typ n (arg::args) = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
200 |
let |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
201 |
val (n1, t1) = arg2typ n arg; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
202 |
val (n2, t2) = args2typ n1 args |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
203 |
in (n2, mk_sprodT (t1, t2)) end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
204 |
fun cons2typ n [] = (n, oneT) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
205 |
| cons2typ n [con] = args2typ n (snd con) |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
206 |
| cons2typ n (con::cons) = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
207 |
let |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
208 |
val (n1, t1) = args2typ n (snd con); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
209 |
val (n2, t2) = cons2typ n1 cons |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
210 |
in (n2, mk_ssumT (t1, t2)) end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
211 |
val ct = ctyp_of thy (snd (cons2typ 1 spec')); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
212 |
val thm1 = instantiate' [SOME ct] [] @{thm exh_start}; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
213 |
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
|
214 |
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
|
215 |
|
35526
85e9423d7deb
use y as variable name in casedist, like datatype package
huffman
parents:
35514
diff
changeset
|
216 |
val y = Free ("y", lhsT); |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
217 |
fun one_con (con, args) = |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
218 |
let |
35526
85e9423d7deb
use y as variable name in casedist, like datatype package
huffman
parents:
35514
diff
changeset
|
219 |
val (vs, nonlazy) = get_vars_avoiding ["y"] args; |
85e9423d7deb
use y as variable name in casedist, like datatype package
huffman
parents:
35514
diff
changeset
|
220 |
val eqn = mk_eq (y, list_ccomb (con, vs)); |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
221 |
val conj = foldr1 mk_conj (eqn :: map mk_defined nonlazy); |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
222 |
in Library.foldr mk_ex (vs, conj) end; |
35526
85e9423d7deb
use y as variable name in casedist, like datatype package
huffman
parents:
35514
diff
changeset
|
223 |
val goal = mk_trp (foldr1 mk_disj (mk_undef y :: map one_con spec')); |
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35785
diff
changeset
|
224 |
(* first rules replace "y = UU \/ P" with "rep$y = UU \/ P" *) |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
225 |
val tacs = [ |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
226 |
rtac (iso_locale RS @{thm iso.casedist_rule}) 1, |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
227 |
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
|
228 |
rtac thm3 1]; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
229 |
in |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
230 |
val nchotomy = prove thy con_betas goal (K tacs); |
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
231 |
val exhaust = |
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
232 |
(nchotomy RS @{thm exh_casedist0}) |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
233 |
|> rewrite_rule @{thms exh_casedists} |
36241
2a4cec6bcae2
replace many uses of Drule.export_without_context with Drule.zero_var_indexes
huffman
parents:
35785
diff
changeset
|
234 |
|> Drule.zero_var_indexes; |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
235 |
end; |
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
236 |
|
35453 | 237 |
(* prove compactness rules for constructors *) |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
238 |
val compacts = |
35453 | 239 |
let |
240 |
val rules = @{thms compact_sinl compact_sinr compact_spair |
|
241 |
compact_up compact_ONE}; |
|
242 |
val tacs = |
|
243 |
[rtac (iso_locale RS @{thm iso.compact_abs}) 1, |
|
244 |
REPEAT (resolve_tac rules 1 ORELSE atac 1)]; |
|
245 |
fun con_compact (con, args) = |
|
246 |
let |
|
35455 | 247 |
val vs = vars_of args; |
35453 | 248 |
val con_app = list_ccomb (con, vs); |
249 |
val concl = mk_trp (mk_compact con_app); |
|
250 |
val assms = map (mk_trp o mk_compact) vs; |
|
251 |
val goal = Logic.list_implies (assms, concl); |
|
252 |
in |
|
253 |
prove thy con_betas goal (K tacs) |
|
254 |
end; |
|
255 |
in |
|
256 |
map con_compact spec' |
|
257 |
end; |
|
258 |
||
259 |
(* prove strictness rules for constructors *) |
|
260 |
local |
|
261 |
fun con_strict (con, args) = |
|
262 |
let |
|
263 |
val rules = abs_strict :: @{thms con_strict_rules}; |
|
35484 | 264 |
val (vs, nonlazy) = get_vars args; |
35453 | 265 |
fun one_strict v' = |
266 |
let |
|
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
267 |
val UU = mk_bottom (fastype_of v'); |
35453 | 268 |
val vs' = map (fn v => if v = v' then UU else v) vs; |
269 |
val goal = mk_trp (mk_undef (list_ccomb (con, vs'))); |
|
270 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
|
271 |
in prove thy con_betas goal (K tacs) end; |
|
272 |
in map one_strict nonlazy end; |
|
273 |
||
274 |
fun con_defin (con, args) = |
|
275 |
let |
|
276 |
fun iff_disj (t, []) = HOLogic.mk_not t |
|
277 |
| iff_disj (t, ts) = mk_eq (t, foldr1 HOLogic.mk_disj ts); |
|
35484 | 278 |
val (vs, nonlazy) = get_vars args; |
35453 | 279 |
val lhs = mk_undef (list_ccomb (con, vs)); |
280 |
val rhss = map mk_undef nonlazy; |
|
281 |
val goal = mk_trp (iff_disj (lhs, rhss)); |
|
282 |
val rule1 = iso_locale RS @{thm iso.abs_defined_iff}; |
|
283 |
val rules = rule1 :: @{thms con_defined_iff_rules}; |
|
284 |
val tacs = [simp_tac (HOL_ss addsimps rules) 1]; |
|
285 |
in prove thy con_betas goal (K tacs) end; |
|
286 |
in |
|
287 |
val con_stricts = maps con_strict spec'; |
|
288 |
val con_defins = map con_defin spec'; |
|
289 |
val con_rews = con_stricts @ con_defins; |
|
290 |
end; |
|
291 |
||
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
292 |
(* prove injectiveness of constructors *) |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
293 |
local |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
294 |
fun pgterm rel (con, args) = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
295 |
let |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
296 |
fun prime (Free (n, T)) = Free (n^"'", T) |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
297 |
| prime t = t; |
35484 | 298 |
val (xs, nonlazy) = get_vars args; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
299 |
val ys = map prime xs; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
300 |
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
|
301 |
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
|
302 |
val concl = mk_trp (mk_eq (lhs, rhs)); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
303 |
val zs = case args of [_] => [] | _ => nonlazy; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
304 |
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
|
305 |
val goal = Logic.list_implies (assms, concl); |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
306 |
in prove thy con_betas goal end; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
307 |
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
|
308 |
in |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
309 |
val inverts = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
310 |
let |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
val rules = rules1 @ rules2; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
val injects = |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
318 |
let |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
319 |
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
|
320 |
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
|
321 |
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
|
322 |
val rules = rules1 @ rules2; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
323 |
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
|
324 |
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
|
325 |
end; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
326 |
|
35458
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
327 |
(* prove distinctness of constructors *) |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
328 |
local |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
| prime t = t; |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
333 |
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
|
334 |
| 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
|
335 |
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
|
336 |
| 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
|
337 |
| iff_disj2 (t, ts, us) = |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
338 |
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
|
339 |
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
|
340 |
let |
35484 | 341 |
val (vs1, zs1) = get_vars args1; |
342 |
val (vs2, zs2) = get_vars args2 |> pairself (map prime); |
|
35458
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
343 |
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
|
344 |
val rhss = map mk_undef zs1; |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
345 |
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
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
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
|
350 |
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
|
351 |
let |
35484 | 352 |
val (vs1, zs1) = get_vars args1; |
353 |
val (vs2, zs2) = get_vars args2 |> pairself (map prime); |
|
35458
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
354 |
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
|
355 |
val rhss1 = map mk_undef zs1; |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
356 |
val rhss2 = map mk_undef zs2; |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
357 |
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
|
358 |
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
|
359 |
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
|
360 |
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
|
361 |
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
|
362 |
in |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
363 |
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
|
364 |
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
|
365 |
end; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
366 |
|
35453 | 367 |
val result = |
368 |
{ |
|
369 |
con_consts = con_consts, |
|
370 |
con_betas = con_betas, |
|
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
371 |
nchotomy = nchotomy, |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
372 |
exhaust = exhaust, |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
373 |
compacts = compacts, |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
374 |
con_rews = con_rews, |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
375 |
inverts = inverts, |
35458
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
376 |
injects = injects, |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
377 |
dist_les = dist_les, |
deaf221c4a59
moved proofs of dist_les and dist_eqs to domain_constructors.ML
huffman
parents:
35457
diff
changeset
|
378 |
dist_eqs = dist_eqs |
35453 | 379 |
}; |
380 |
in |
|
381 |
(result, thy) |
|
382 |
end; |
|
383 |
||
384 |
(******************************************************************************) |
|
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
385 |
(**************** definition and theorems for case combinator *****************) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
386 |
(******************************************************************************) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
387 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
388 |
fun add_case_combinator |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
389 |
(spec : (term * (bool * typ) list) list) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
390 |
(lhsT : typ) |
35777
bcc77916b7b9
pass binding as argument to add_domain_constructors; proper binding for case combinator
huffman
parents:
35561
diff
changeset
|
391 |
(dbind : binding) |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
392 |
(con_betas : thm list) |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
393 |
(exhaust : thm) |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
394 |
(iso_locale : thm) |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
395 |
(rep_const : term) |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
396 |
(thy : theory) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
397 |
: ((typ -> term) * thm list) * theory = |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
398 |
let |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
399 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
400 |
(* prove rep/abs rules *) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
401 |
val rep_strict = iso_locale RS @{thm iso.rep_strict}; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
402 |
val abs_inverse = iso_locale RS @{thm iso.abs_iso}; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
403 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
404 |
(* calculate function arguments of case combinator *) |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
405 |
val tns = map (fst o dest_TFree) (snd (dest_Type lhsT)); |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
406 |
val resultT = TFree (Name.variant tns "'t", @{sort pcpo}); |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
407 |
fun fTs T = map (fn (_, args) => map snd args -->> T) spec; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
408 |
val fns = Datatype_Prop.indexify_names (map (K "f") spec); |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
409 |
val fs = map Free (fns ~~ fTs resultT); |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
410 |
fun caseT T = fTs T -->> (lhsT ->> T); |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
411 |
|
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
412 |
(* definition of case combinator *) |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
413 |
local |
35777
bcc77916b7b9
pass binding as argument to add_domain_constructors; proper binding for case combinator
huffman
parents:
35561
diff
changeset
|
414 |
val case_bind = Binding.suffix_name "_when" dbind; |
35784 | 415 |
fun lambda_arg (lazy, v) t = |
416 |
(if lazy then mk_fup else I) (big_lambda v t); |
|
40212 | 417 |
fun lambda_args [] t = mk_one_case t |
35784 | 418 |
| lambda_args (x::[]) t = lambda_arg x t |
419 |
| lambda_args (x::xs) t = mk_ssplit (lambda_arg x (lambda_args xs t)); |
|
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
420 |
fun one_con f (_, args) = |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
421 |
let |
35784 | 422 |
val Ts = map snd args; |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
423 |
val ns = Name.variant_list fns (Datatype_Prop.make_tnames Ts); |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
424 |
val vs = map Free (ns ~~ Ts); |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
425 |
in |
35784 | 426 |
lambda_args (map fst args ~~ vs) (list_ccomb (f, vs)) |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
427 |
end; |
35785 | 428 |
fun mk_sscases [t] = mk_strictify t |
429 |
| mk_sscases ts = foldr1 mk_sscase ts; |
|
35784 | 430 |
val body = mk_sscases (map2 one_con fs spec); |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
431 |
val rhs = big_lambdas fs (mk_cfcomp (body, rep_const)); |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
432 |
val ((case_consts, case_defs), thy) = |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
433 |
define_consts [(case_bind, rhs, NoSyn)] thy; |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
434 |
val case_name = Sign.full_name thy case_bind; |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
435 |
in |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
436 |
val case_def = hd case_defs; |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
437 |
fun case_const T = Const (case_name, caseT T); |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
438 |
val case_app = list_ccomb (case_const resultT, fs); |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
439 |
val thy = thy; |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
440 |
end; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
441 |
|
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
442 |
(* define syntax for case combinator *) |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
443 |
(* TODO: re-implement case syntax using a parse translation *) |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
444 |
local |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
445 |
open Syntax |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
446 |
fun syntax c = Syntax.mark_const (fst (dest_Const c)); |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
447 |
fun xconst c = Long_Name.base_name (fst (dest_Const c)); |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
448 |
fun c_ast authentic con = |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
449 |
Constant (if authentic then syntax con else xconst con); |
35485 | 450 |
fun showint n = string_of_int (n+1); |
451 |
fun expvar n = Variable ("e" ^ showint n); |
|
452 |
fun argvar n (m, _) = Variable ("a" ^ showint n ^ "_" ^ showint m); |
|
453 |
fun argvars n args = map_index (argvar n) args; |
|
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
454 |
fun app s (l, r) = mk_appl (Constant s) [l, r]; |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
455 |
val cabs = app "_cabs"; |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
456 |
val capp = app @{const_syntax Rep_CFun}; |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
457 |
val capps = Library.foldl capp |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
458 |
fun con1 authentic n (con,args) = |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
459 |
Library.foldl capp (c_ast authentic con, argvars n args); |
35485 | 460 |
fun case1 authentic (n, c) = |
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
461 |
app "_case1" (con1 authentic n c, expvar n); |
35485 | 462 |
fun arg1 (n, (con,args)) = List.foldr cabs (expvar n) (argvars n args); |
463 |
fun when1 n (m, c) = |
|
464 |
if n = m then arg1 (n, c) else (Constant @{const_syntax UU}); |
|
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
465 |
val case_constant = Constant (syntax (case_const dummyT)); |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
466 |
fun case_trans authentic = |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
467 |
ParsePrintRule |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
468 |
(app "_case_syntax" |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
469 |
(Variable "x", |
35485 | 470 |
foldr1 (app "_case2") (map_index (case1 authentic) spec)), |
471 |
capp (capps (case_constant, map_index arg1 spec), Variable "x")); |
|
472 |
fun one_abscon_trans authentic (n, c) = |
|
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
473 |
ParsePrintRule |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
474 |
(cabs (con1 authentic n c, expvar n), |
35485 | 475 |
capps (case_constant, map_index (when1 n) spec)); |
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
476 |
fun abscon_trans authentic = |
35485 | 477 |
map_index (one_abscon_trans authentic) spec; |
35472
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
478 |
val trans_rules : ast Syntax.trrule list = |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
479 |
case_trans false :: case_trans true :: |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
480 |
abscon_trans false @ abscon_trans true; |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
481 |
in |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
482 |
val thy = Sign.add_trrules_i trans_rules thy; |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
483 |
end; |
c23b42730b9b
move case combinator syntax to domain_constructors.ML
huffman
parents:
35470
diff
changeset
|
484 |
|
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
485 |
(* prove beta reduction rule for case combinator *) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
486 |
val case_beta = beta_of_def thy case_def; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
487 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
488 |
(* prove strictness of case combinator *) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
489 |
val case_strict = |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
490 |
let |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
491 |
val defs = case_beta :: map mk_meta_eq [rep_strict, @{thm cfcomp2}]; |
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
492 |
val goal = mk_trp (mk_strict case_app); |
40212 | 493 |
val rules = @{thms sscase1 ssplit1 strictify1 one_case1}; |
35496 | 494 |
val tacs = [resolve_tac rules 1]; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
495 |
in prove thy defs goal (K tacs) end; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
496 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
497 |
(* prove rewrites for case combinator *) |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
498 |
local |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
499 |
fun one_case (con, args) f = |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
500 |
let |
35483 | 501 |
val (vs, nonlazy) = get_vars args; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
502 |
val assms = map (mk_trp o mk_defined) nonlazy; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
503 |
val lhs = case_app ` list_ccomb (con, vs); |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
504 |
val rhs = list_ccomb (f, vs); |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
505 |
val concl = mk_trp (mk_eq (lhs, rhs)); |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
506 |
val goal = Logic.list_implies (assms, concl); |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
507 |
val defs = case_beta :: con_betas; |
35488 | 508 |
val rules1 = @{thms strictify2 sscase2 sscase3 ssplit2 fup2 ID1}; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
509 |
val rules2 = @{thms con_defined_iff_rules}; |
40212 | 510 |
val rules3 = @{thms cfcomp2 one_case2}; |
35486
c91854705b1d
move definition of case combinator to domain_constructors.ML
huffman
parents:
35485
diff
changeset
|
511 |
val rules = abs_inverse :: rules1 @ rules2 @ rules3; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
512 |
val tacs = [asm_simp_tac (beta_ss addsimps rules) 1]; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
513 |
in prove thy defs goal (K tacs) end; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
514 |
in |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
515 |
val case_apps = map2 one_case spec fs; |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
516 |
end |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
517 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
518 |
in |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
519 |
((case_const, case_strict :: case_apps), thy) |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
520 |
end |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
521 |
|
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
522 |
(******************************************************************************) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
523 |
(************** definitions and theorems for selector functions ***************) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
524 |
(******************************************************************************) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
525 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
526 |
fun add_selectors |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
527 |
(spec : (term * (bool * binding option * typ) list) list) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
528 |
(rep_const : term) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
529 |
(abs_inv : thm) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
530 |
(rep_strict : thm) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
531 |
(rep_strict_iff : thm) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
532 |
(con_betas : thm list) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
533 |
(thy : theory) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
534 |
: thm list * theory = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
535 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
536 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
537 |
(* define selector functions *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
538 |
val ((sel_consts, sel_defs), thy) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
539 |
let |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
540 |
fun rangeT s = snd (dest_cfunT (fastype_of s)); |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
541 |
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
|
542 |
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
|
543 |
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
|
544 |
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
|
545 |
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
|
546 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
547 |
fun sels_of_arg s (lazy, NONE, T) = [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
548 |
| sels_of_arg s (lazy, SOME b, T) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
549 |
[(b, if lazy then mk_down s else s, NoSyn)]; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
550 |
fun sels_of_args s [] = [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
551 |
| sels_of_args s (v :: []) = sels_of_arg s v |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
552 |
| sels_of_args s (v :: vs) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
553 |
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
|
554 |
fun sels_of_cons s [] = [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
555 |
| sels_of_cons s ((con, args) :: []) = sels_of_args s args |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
556 |
| sels_of_cons s ((con, args) :: cs) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
557 |
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
|
558 |
val sel_eqns : (binding * term * mixfix) list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
559 |
sels_of_cons rep_const spec; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
560 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
561 |
define_consts sel_eqns thy |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
562 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
563 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
564 |
(* replace bindings with terms in constructor spec *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
565 |
val spec2 : (term * (bool * term option * typ) list) list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
566 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
567 |
fun prep_arg (lazy, NONE, T) sels = ((lazy, NONE, T), sels) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
568 |
| prep_arg (lazy, SOME _, T) sels = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
569 |
((lazy, SOME (hd sels), T), tl sels); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
570 |
fun prep_con (con, args) sels = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
571 |
apfst (pair con) (fold_map prep_arg args sels); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
572 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
573 |
fst (fold_map prep_con spec sel_consts) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
574 |
end; |
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 |
(* prove selector strictness rules *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
577 |
val sel_stricts : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
578 |
let |
35449 | 579 |
val rules = rep_strict :: @{thms sel_strict_rules}; |
580 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
581 |
fun sel_strict sel = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
582 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
583 |
val goal = mk_trp (mk_strict sel); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
584 |
in |
35449 | 585 |
prove thy sel_defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
586 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
587 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
588 |
map sel_strict sel_consts |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
589 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
590 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
591 |
(* prove selector application rules *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
592 |
val sel_apps : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
593 |
let |
35449 | 594 |
val defs = con_betas @ sel_defs; |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
595 |
val rules = abs_inv :: @{thms sel_app_rules}; |
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
596 |
val tacs = [asm_simp_tac (simple_ss addsimps rules) 1]; |
37165 | 597 |
fun sel_apps_of (i, (con, args: (bool * term option * typ) list)) = |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
598 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
599 |
val Ts : typ list = map #3 args; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
600 |
val ns : string list = Datatype_Prop.make_tnames Ts; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
601 |
val vs : term list = map Free (ns ~~ Ts); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
602 |
val con_app : term = list_ccomb (con, vs); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
603 |
val vs' : (bool * term) list = map #1 args ~~ vs; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
604 |
fun one_same (n, sel, T) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
605 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
606 |
val xs = map snd (filter_out fst (nth_drop n vs')); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
607 |
val assms = map (mk_trp o mk_defined) xs; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
608 |
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
|
609 |
val goal = Logic.list_implies (assms, concl); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
610 |
in |
35449 | 611 |
prove thy defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
612 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
613 |
fun one_diff (n, sel, T) = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
614 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
615 |
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
|
616 |
in |
35449 | 617 |
prove thy defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
618 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
619 |
fun one_con (j, (_, args')) : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
620 |
let |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
621 |
fun prep (i, (lazy, NONE, T)) = NONE |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
622 |
| prep (i, (lazy, SOME sel, T)) = SOME (i, sel, T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
623 |
val sels : (int * term * typ) list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
624 |
map_filter prep (map_index I args'); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
625 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
626 |
if i = j |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
627 |
then map one_same sels |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
628 |
else map one_diff sels |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
629 |
end |
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 |
flat (map_index one_con spec2) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
632 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
633 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
634 |
flat (map_index sel_apps_of spec2) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
635 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
636 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
637 |
(* prove selector definedness rules *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
638 |
val sel_defins : thm list = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
639 |
let |
35449 | 640 |
val rules = rep_strict_iff :: @{thms sel_defined_iff_rules}; |
641 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
642 |
fun sel_defin sel = |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
643 |
let |
35456
5356534f880e
move proofs of injects and inverts to domain_constructors.ML
huffman
parents:
35455
diff
changeset
|
644 |
val (T, U) = dest_cfunT (fastype_of sel); |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
645 |
val x = Free ("x", T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
646 |
val lhs = mk_eq (sel ` x, mk_bottom U); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
647 |
val rhs = mk_eq (x, mk_bottom T); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
648 |
val goal = mk_trp (mk_eq (lhs, rhs)); |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
649 |
in |
35449 | 650 |
prove thy sel_defs goal (K tacs) |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
651 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
652 |
fun one_arg (false, SOME sel, T) = SOME (sel_defin sel) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
653 |
| one_arg _ = NONE; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
654 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
655 |
case spec2 of |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
656 |
[(con, args)] => map_filter one_arg args |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
657 |
| _ => [] |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
658 |
end; |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
659 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
660 |
in |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
661 |
(sel_stricts @ sel_defins @ sel_apps, thy) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
662 |
end |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
663 |
|
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
664 |
(******************************************************************************) |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
665 |
(************ definitions and theorems for discriminator functions ************) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
666 |
(******************************************************************************) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
667 |
|
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
668 |
fun add_discriminators |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
669 |
(bindings : binding list) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
670 |
(spec : (term * (bool * typ) list) list) |
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
671 |
(lhsT : typ) |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
672 |
(exhaust : thm) |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
673 |
(case_const : typ -> term) |
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
674 |
(case_rews : thm list) |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
675 |
(thy : theory) = |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
676 |
let |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
677 |
|
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
678 |
fun vars_of args = |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
679 |
let |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
680 |
val Ts = map snd args; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
681 |
val ns = Datatype_Prop.make_tnames Ts; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
682 |
in |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
683 |
map Free (ns ~~ Ts) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
684 |
end; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
685 |
|
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
686 |
(* define discriminator functions *) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
687 |
local |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
688 |
fun dis_fun i (j, (con, args)) = |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
689 |
let |
35483 | 690 |
val (vs, nonlazy) = get_vars args; |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
691 |
val tr = if i = j then @{term TT} else @{term FF}; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
692 |
in |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
693 |
big_lambdas vs tr |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
694 |
end; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
695 |
fun dis_eqn (i, bind) : binding * term * mixfix = |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
696 |
let |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
697 |
val dis_bind = Binding.prefix_name "is_" bind; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
698 |
val rhs = list_ccomb (case_const trT, map_index (dis_fun i) spec); |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
699 |
in |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
700 |
(dis_bind, rhs, NoSyn) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
701 |
end; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
702 |
in |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
703 |
val ((dis_consts, dis_defs), thy) = |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
704 |
define_consts (map_index dis_eqn bindings) thy |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
705 |
end; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
706 |
|
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
707 |
(* prove discriminator strictness rules *) |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
708 |
local |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
709 |
fun dis_strict dis = |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
710 |
let val goal = mk_trp (mk_strict dis); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
711 |
in prove thy dis_defs goal (K [rtac (hd case_rews) 1]) end; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
712 |
in |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
713 |
val dis_stricts = map dis_strict dis_consts; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
714 |
end; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
715 |
|
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
716 |
(* prove discriminator/constructor rules *) |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
717 |
local |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
718 |
fun dis_app (i, dis) (j, (con, args)) = |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
719 |
let |
35483 | 720 |
val (vs, nonlazy) = get_vars args; |
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
721 |
val lhs = dis ` list_ccomb (con, vs); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
722 |
val rhs = if i = j then @{term TT} else @{term FF}; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
723 |
val assms = map (mk_trp o mk_defined) nonlazy; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
724 |
val concl = mk_trp (mk_eq (lhs, rhs)); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
725 |
val goal = Logic.list_implies (assms, concl); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
726 |
val tacs = [asm_simp_tac (beta_ss addsimps case_rews) 1]; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
727 |
in prove thy dis_defs goal (K tacs) end; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
728 |
fun one_dis (i, dis) = |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
729 |
map_index (dis_app (i, dis)) spec; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
730 |
in |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
731 |
val dis_apps = flat (map_index one_dis dis_consts); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
732 |
end; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
733 |
|
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
734 |
(* prove discriminator definedness rules *) |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
735 |
local |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
736 |
fun dis_defin dis = |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
737 |
let |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
738 |
val x = Free ("x", lhsT); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
739 |
val simps = dis_apps @ @{thms dist_eq_tr}; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
740 |
val tacs = |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
741 |
[rtac @{thm iffI} 1, |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
742 |
asm_simp_tac (HOL_basic_ss addsimps dis_stricts) 2, |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
743 |
rtac exhaust 1, atac 1, |
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
744 |
DETERM_UNTIL_SOLVED (CHANGED |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
745 |
(asm_full_simp_tac (simple_ss addsimps simps) 1))]; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
746 |
val goal = mk_trp (mk_eq (mk_undef (dis ` x), mk_undef x)); |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
747 |
in prove thy [] goal (K tacs) end; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
748 |
in |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
749 |
val dis_defins = map dis_defin dis_consts; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
750 |
end; |
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
751 |
|
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
752 |
in |
35461
34360a1e3537
move proofs of dis_rews to domain_constructors.ML; change dis_defins to iff-style
huffman
parents:
35460
diff
changeset
|
753 |
(dis_stricts @ dis_defins @ dis_apps, thy) |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
754 |
end; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
755 |
|
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
756 |
(******************************************************************************) |
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
757 |
(*************** definitions and theorems for match combinators ***************) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
758 |
(******************************************************************************) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
759 |
|
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
760 |
fun add_match_combinators |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
761 |
(bindings : binding list) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
762 |
(spec : (term * (bool * typ) list) list) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
763 |
(lhsT : typ) |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
764 |
(exhaust : thm) |
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
765 |
(case_const : typ -> term) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
766 |
(case_rews : thm list) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
767 |
(thy : theory) = |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
768 |
let |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
769 |
|
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
770 |
(* get a fresh type variable for the result type *) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
771 |
val resultT : typ = |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
772 |
let |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
773 |
val ts : string list = map (fst o dest_TFree) (snd (dest_Type lhsT)); |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
774 |
val t : string = Name.variant ts "'t"; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
775 |
in TFree (t, @{sort pcpo}) end; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
776 |
|
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
777 |
(* define match combinators *) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
778 |
local |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
779 |
val x = Free ("x", lhsT); |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
780 |
fun k args = Free ("k", map snd args -->> mk_matchT resultT); |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
781 |
val fail = mk_fail resultT; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
782 |
fun mat_fun i (j, (con, args)) = |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
783 |
let |
35483 | 784 |
val (vs, nonlazy) = get_vars_avoiding ["x","k"] args; |
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
785 |
in |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
786 |
if i = j then k args else big_lambdas vs fail |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
787 |
end; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
788 |
fun mat_eqn (i, (bind, (con, args))) : binding * term * mixfix = |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
789 |
let |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
790 |
val mat_bind = Binding.prefix_name "match_" bind; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
791 |
val funs = map_index (mat_fun i) spec |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
792 |
val body = list_ccomb (case_const (mk_matchT resultT), funs); |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
793 |
val rhs = big_lambda x (big_lambda (k args) (body ` x)); |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
794 |
in |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
795 |
(mat_bind, rhs, NoSyn) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
796 |
end; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
797 |
in |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
798 |
val ((match_consts, match_defs), thy) = |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
799 |
define_consts (map_index mat_eqn (bindings ~~ spec)) thy |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
800 |
end; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
801 |
|
35463
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
802 |
(* register match combinators with fixrec package *) |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
803 |
local |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
804 |
val con_names = map (fst o dest_Const o fst) spec; |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
805 |
val mat_names = map (fst o dest_Const) match_consts; |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
806 |
in |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
807 |
val thy = Fixrec.add_matchers (con_names ~~ mat_names) thy; |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
808 |
end; |
b20501588930
register match functions from domain_constructors.ML
huffman
parents:
35462
diff
changeset
|
809 |
|
35466
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
810 |
(* prove strictness of match combinators *) |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
811 |
local |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
812 |
fun match_strict mat = |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
813 |
let |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
814 |
val (T, (U, V)) = apsnd dest_cfunT (dest_cfunT (fastype_of mat)); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
815 |
val k = Free ("k", U); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
816 |
val goal = mk_trp (mk_eq (mat ` mk_bottom T ` k, mk_bottom V)); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
817 |
val tacs = [asm_simp_tac (beta_ss addsimps case_rews) 1]; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
818 |
in prove thy match_defs goal (K tacs) end; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
819 |
in |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
820 |
val match_stricts = map match_strict match_consts; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
821 |
end; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
822 |
|
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
823 |
(* prove match/constructor rules *) |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
824 |
local |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
825 |
val fail = mk_fail resultT; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
826 |
fun match_app (i, mat) (j, (con, args)) = |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
827 |
let |
35483 | 828 |
val (vs, nonlazy) = get_vars_avoiding ["k"] args; |
35466
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
829 |
val (_, (kT, _)) = apsnd dest_cfunT (dest_cfunT (fastype_of mat)); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
830 |
val k = Free ("k", kT); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
831 |
val lhs = mat ` list_ccomb (con, vs) ` k; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
832 |
val rhs = if i = j then list_ccomb (k, vs) else fail; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
833 |
val assms = map (mk_trp o mk_defined) nonlazy; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
834 |
val concl = mk_trp (mk_eq (lhs, rhs)); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
835 |
val goal = Logic.list_implies (assms, concl); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
836 |
val tacs = [asm_simp_tac (beta_ss addsimps case_rews) 1]; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
837 |
in prove thy match_defs goal (K tacs) end; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
838 |
fun one_match (i, mat) = |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
839 |
map_index (match_app (i, mat)) spec; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
840 |
in |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
841 |
val match_apps = flat (map_index one_match match_consts); |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
842 |
end; |
9fcfd5763181
move proofs of match_rews to domain_constructors.ML
huffman
parents:
35463
diff
changeset
|
843 |
|
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
844 |
in |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
845 |
(match_stricts @ match_apps, thy) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
846 |
end; |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
847 |
|
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
848 |
(******************************************************************************) |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
849 |
(******************************* main function ********************************) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
850 |
(******************************************************************************) |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
851 |
|
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
852 |
fun add_domain_constructors |
35777
bcc77916b7b9
pass binding as argument to add_domain_constructors; proper binding for case combinator
huffman
parents:
35561
diff
changeset
|
853 |
(dbind : binding) |
35481
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
854 |
(spec : (binding * (bool * binding option * typ) list * mixfix) list) |
35514
a2cfa413eaab
move take-related definitions and proofs to new module; simplify map_of_typ functions
huffman
parents:
35496
diff
changeset
|
855 |
(iso_info : Domain_Take_Proofs.iso_info) |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
856 |
(thy : theory) = |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
857 |
let |
35777
bcc77916b7b9
pass binding as argument to add_domain_constructors; proper binding for case combinator
huffman
parents:
35561
diff
changeset
|
858 |
val dname = Binding.name_of dbind; |
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
859 |
val _ = writeln ("Proving isomorphism properties of domain "^dname^" ..."); |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
860 |
|
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
861 |
val bindings = map #1 spec; |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
862 |
|
35481
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
863 |
(* retrieve facts about rep/abs *) |
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
864 |
val lhsT = #absT iso_info; |
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
865 |
val {rep_const, abs_const, ...} = iso_info; |
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
866 |
val abs_iso_thm = #abs_inverse iso_info; |
7bb9157507a9
add_domain_constructors takes iso_info record as argument
huffman
parents:
35476
diff
changeset
|
867 |
val rep_iso_thm = #rep_inverse iso_info; |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
868 |
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
|
869 |
val rep_strict = iso_locale RS @{thm iso.rep_strict}; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
870 |
val abs_strict = iso_locale RS @{thm iso.abs_strict}; |
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
871 |
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
|
872 |
val abs_defined_iff = iso_locale RS @{thm iso.abs_defined_iff}; |
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
873 |
val iso_rews = [abs_iso_thm, rep_iso_thm, abs_strict, rep_strict]; |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
874 |
|
35487 | 875 |
(* qualify constants and theorems with domain name *) |
876 |
val thy = Sign.add_path dname thy; |
|
877 |
||
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
878 |
(* define constructor functions *) |
35457
d63655b88369
move proofs of casedist into domain_constructors.ML
huffman
parents:
35456
diff
changeset
|
879 |
val (con_result, thy) = |
35454
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
880 |
let |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
881 |
fun prep_arg (lazy, sel, T) = (lazy, T); |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
882 |
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
|
883 |
val con_spec = map prep_con spec; |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
884 |
in |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
885 |
add_constructors con_spec abs_const iso_locale thy |
cf6ba350b7ca
remove unnecessary stuff from argument to add_constructors function
huffman
parents:
35453
diff
changeset
|
886 |
end; |
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
887 |
val {con_consts, con_betas, nchotomy, exhaust, compacts, con_rews, |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
888 |
inverts, injects, dist_les, dist_eqs} = con_result; |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
889 |
|
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
890 |
(* prepare constructor spec *) |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
891 |
val con_specs : (term * (bool * typ) list) list = |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
892 |
let |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
893 |
fun prep_arg (lazy, sel, T) = (lazy, T); |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
894 |
fun prep_con c (b, args, mx) = (c, map prep_arg args); |
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
895 |
in |
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
896 |
map2 prep_con con_consts spec |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
897 |
end; |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
898 |
|
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
899 |
(* define case combinator *) |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
900 |
val ((case_const : typ -> term, cases : thm list), thy) = |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
901 |
add_case_combinator con_specs lhsT dbind |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
902 |
con_betas exhaust iso_locale rep_const thy |
35450
e9ef2b50ac59
move constructor-specific stuff to a separate function
huffman
parents:
35449
diff
changeset
|
903 |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
904 |
(* define and prove theorems for selector functions *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
905 |
val (sel_thms : thm list, thy : theory) = |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
906 |
let |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
907 |
val sel_spec : (term * (bool * binding option * typ) list) list = |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
908 |
map2 (fn con => fn (b, args, mx) => (con, args)) con_consts spec; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
909 |
in |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
910 |
add_selectors sel_spec rep_const |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
911 |
abs_iso_thm rep_strict rep_defined_iff con_betas thy |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
912 |
end; |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
913 |
|
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
914 |
(* define and prove theorems for discriminator functions *) |
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
915 |
val (dis_thms : thm list, thy : theory) = |
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
916 |
add_discriminators bindings con_specs lhsT |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
917 |
exhaust case_const cases thy; |
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
918 |
|
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
919 |
(* define and prove theorems for match combinators *) |
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
920 |
val (match_thms : thm list, thy : theory) = |
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
921 |
add_match_combinators bindings con_specs lhsT |
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
922 |
exhaust case_const cases thy; |
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
923 |
|
35446
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
924 |
(* restore original signature path *) |
b719dad322fa
rewrite domain package code for selector functions
huffman
parents:
35445
diff
changeset
|
925 |
val thy = Sign.parent_path thy; |
35444 | 926 |
|
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
927 |
(* bind theorem names in global theory *) |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
928 |
val (_, thy) = |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
929 |
let |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
930 |
fun qualified name = Binding.qualified true name dbind; |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
931 |
val names = "bottom" :: map (fn (b,_,_) => Binding.name_of b) spec; |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
932 |
val dname = fst (dest_Type lhsT); |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
933 |
val simp = Simplifier.simp_add; |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
934 |
val case_names = Rule_Cases.case_names names; |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
935 |
val cases_type = Induct.cases_type dname; |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
936 |
in |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
937 |
Global_Theory.add_thmss [ |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
938 |
((qualified "iso_rews" , iso_rews ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
939 |
((qualified "nchotomy" , [nchotomy] ), []), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
940 |
((qualified "exhaust" , [exhaust] ), [case_names, cases_type]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
941 |
((qualified "when_rews" , cases ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
942 |
((qualified "compacts" , compacts ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
943 |
((qualified "con_rews" , con_rews ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
944 |
((qualified "sel_rews" , sel_thms ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
945 |
((qualified "dis_rews" , dis_thms ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
946 |
((qualified "dist_les" , dist_les ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
947 |
((qualified "dist_eqs" , dist_eqs ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
948 |
((qualified "inverts" , inverts ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
949 |
((qualified "injects" , injects ), [simp]), |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
950 |
((qualified "match_rews", match_thms ), [simp])] thy |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
951 |
end; |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
952 |
|
35444 | 953 |
val result = |
40017 | 954 |
{ |
955 |
iso_info = iso_info, |
|
40019
05cda34d36e7
put constructor argument specs in constr_info type
huffman
parents:
40017
diff
changeset
|
956 |
con_specs = con_specs, |
35451 | 957 |
con_betas = con_betas, |
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
958 |
nchotomy = nchotomy, |
35781
b7738ab762b1
renamed some lemmas generated by the domain package
huffman
parents:
35777
diff
changeset
|
959 |
exhaust = exhaust, |
40016
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
960 |
compacts = compacts, |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
961 |
con_rews = con_rews, |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
962 |
inverts = inverts, |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
963 |
injects = injects, |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
964 |
dist_les = dist_les, |
2eff1cbc1ccb
remove function Domain_Theorems.theorems; bind theorem names directly from Domain_Constructors.add_domain_constructors
huffman
parents:
40014
diff
changeset
|
965 |
dist_eqs = dist_eqs, |
35459
3d8acfae6fb8
move proofs of when_rews intro domain_constructors.ML
huffman
parents:
35458
diff
changeset
|
966 |
cases = cases, |
35460
8cb42aa19358
move definition of discriminators to domain_constructors.ML
huffman
parents:
35459
diff
changeset
|
967 |
sel_rews = sel_thms, |
35462
f5461b02d754
move definition of match combinators to domain_constructors.ML
huffman
parents:
35461
diff
changeset
|
968 |
dis_rews = dis_thms, |
40017 | 969 |
match_rews = match_thms |
970 |
}; |
|
35444 | 971 |
in |
972 |
(result, thy) |
|
973 |
end; |
|
974 |
||
975 |
end; |