author | huffman |
Thu, 03 Nov 2005 02:19:48 +0100 | |
changeset 18083 | cf7669049df5 |
parent 18075 | 43000d7a017c |
child 18084 | 3f767ed1f7ae |
permissions | -rw-r--r-- |
2453 | 1 |
(* Title: HOLCF/domain/axioms.ML |
2 |
ID: $Id$ |
|
12030 | 3 |
Author: David von Oheimb |
2453 | 4 |
|
12030 | 5 |
Syntax generator for domain section. |
1274 | 6 |
*) |
7 |
||
8 |
structure Domain_Axioms = struct |
|
9 |
||
10 |
local |
|
11 |
||
12 |
open Domain_Library; |
|
13 |
infixr 0 ===>;infixr 0 ==>;infix 0 == ; |
|
14 |
infix 1 ===; infix 1 ~= ; infix 1 <<; infix 1 ~<<; |
|
15 |
infix 9 ` ; infix 9 `% ; infix 9 `%%; infixr 9 oo; |
|
16 |
||
17 |
fun infer_types thy' = map (inferT_axm (sign_of thy')); |
|
18 |
||
19 |
fun calc_axioms comp_dname (eqs : eq list) n (((dname,_),cons) : eq)= |
|
20 |
let |
|
21 |
||
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
22 |
(* ----- axioms and definitions concerning the isomorphism ------------------ *) |
1274 | 23 |
|
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
24 |
val dc_abs = %%:(dname^"_abs"); |
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
25 |
val dc_rep = %%:(dname^"_rep"); |
1274 | 26 |
val x_name'= "x"; |
27 |
val x_name = idx_name eqs x_name' (n+1); |
|
4008 | 28 |
val dnam = Sign.base_name dname; |
1274 | 29 |
|
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
30 |
val abs_iso_ax = ("abs_iso", mk_trp(dc_rep`(dc_abs`%x_name') === %:x_name')); |
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
31 |
val rep_iso_ax = ("rep_iso", mk_trp(dc_abs`(dc_rep`%x_name') === %:x_name')); |
1274 | 32 |
|
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
33 |
val when_def = ("when_def",%%:(dname^"_when") == |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
34 |
foldr (uncurry /\ ) (/\x_name'((when_body cons (fn (x,y) => |
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
35 |
Bound(1+length cons+x-y)))`(dc_rep`Bound 0))) (when_funs cons)); |
1274 | 36 |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
37 |
fun con_def outer recu m n (_,args) = let |
16842 | 38 |
fun idxs z x arg = (if is_lazy arg then fn t => %%:upN`t else I) |
4755 | 39 |
(if recu andalso is_rec arg then (cproj (Bound z) eqs |
40 |
(rec_of arg))`Bound(z-x) else Bound(z-x)); |
|
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
41 |
fun parms vs = mk_stuple (mapn (idxs(length vs)) 1 vs); |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
42 |
fun inj y 1 _ = y |
16778 | 43 |
| inj y _ 0 = %%:sinlN`y |
44 |
| inj y i j = %%:sinrN`(inj y (i-1) (j-1)); |
|
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
45 |
in foldr /\# (outer (inj (parms args) m n)) args end; |
1274 | 46 |
|
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
47 |
val copy_def = ("copy_def", %%:(dname^"_copy") == /\"f" (dc_abs oo |
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
48 |
list_ccomb (%%:(dname^"_when") , |
16842 | 49 |
mapn (con_def I true (length cons)) 0 cons))); |
1274 | 50 |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
51 |
(* -- definitions concerning the constructors, discriminators and selectors - *) |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
52 |
|
4043 | 53 |
val con_defs = mapn (fn n => fn (con,args) => (extern_name con ^"_def", |
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
54 |
%%:con == con_def (fn t => dc_abs`t) false (length cons) n (con,args))) 0 cons; |
1274 | 55 |
|
4043 | 56 |
val dis_defs = let |
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
57 |
fun ddef (con,_) = (dis_name con ^"_def",%%:(dis_name con) == |
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
58 |
list_ccomb(%%:(dname^"_when"),map |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
59 |
(fn (con',args) => (foldr /\# |
16778 | 60 |
(if con'=con then %%:TT_N else %%:FF_N) args)) cons)) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
61 |
in map ddef cons end; |
1274 | 62 |
|
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15574
diff
changeset
|
63 |
val mat_defs = let |
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15574
diff
changeset
|
64 |
fun mdef (con,_) = (mat_name con ^"_def",%%:(mat_name con) == |
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
65 |
list_ccomb(%%:(dname^"_when"),map |
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15574
diff
changeset
|
66 |
(fn (con',args) => (foldr /\# |
16778 | 67 |
(if con'=con |
68 |
then %%:returnN`(mk_ctuple (map (bound_arg args) args)) |
|
69 |
else %%:failN) args)) cons)) |
|
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15574
diff
changeset
|
70 |
in map mdef cons end; |
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15574
diff
changeset
|
71 |
|
4043 | 72 |
val sel_defs = let |
16394
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16332
diff
changeset
|
73 |
fun sdef con n arg = Option.map (fn sel => (sel^"_def",%%:sel == |
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
74 |
list_ccomb(%%:(dname^"_when"),map |
16778 | 75 |
(fn (con',args) => if con'<>con then UU else |
16394
495dbcd4f4c9
in domain declarations, selector names are now optional
huffman
parents:
16332
diff
changeset
|
76 |
foldr /\# (Bound (length args - n)) args) cons))) (sel_of arg); |
16842 | 77 |
in List.mapPartial I (List.concat(map (fn (con,args) => mapn (sdef con) 1 args) cons)) end; |
1274 | 78 |
|
79 |
||
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
80 |
(* ----- axiom and definitions concerning induction ------------------------- *) |
1274 | 81 |
|
16778 | 82 |
val reach_ax = ("reach", mk_trp(cproj (%%:fixN`%%(comp_dname^"_copy")) eqs n |
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
83 |
`%x_name === %:x_name)); |
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
84 |
val take_def = ("take_def",%%:(dname^"_take") == mk_lam("n",cproj' |
18075 | 85 |
(%%:iterateN $ Bound 0 ` %%:(comp_dname^"_copy") ` UU) eqs n)); |
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
86 |
val finite_def = ("finite_def",%%:(dname^"_finite") == mk_lam(x_name, |
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
87 |
mk_ex("n",(%%:(dname^"_take") $ Bound 0)`Bound 1 === Bound 1))); |
1274 | 88 |
|
4043 | 89 |
in (dnam, |
90 |
[abs_iso_ax, rep_iso_ax, reach_ax], |
|
91 |
[when_def, copy_def] @ |
|
16224
57094b83774e
Domain package generates match functions for new datatypes, for use with the fixrec package
huffman
parents:
15574
diff
changeset
|
92 |
con_defs @ dis_defs @ mat_defs @ sel_defs @ |
4043 | 93 |
[take_def, finite_def]) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
94 |
end; (* let *) |
1274 | 95 |
|
8438 | 96 |
fun add_axioms_i x = #1 o PureThy.add_axioms_i (map Thm.no_attributes x); |
16332 | 97 |
fun add_axioms_infer axms thy = add_axioms_i (infer_types thy axms) thy; |
1274 | 98 |
|
99 |
in (* local *) |
|
100 |
||
4008 | 101 |
fun add_axioms (comp_dnam, eqs : eq list) thy' = let |
102 |
val comp_dname = Sign.full_name (sign_of thy') comp_dnam; |
|
1274 | 103 |
val dnames = map (fst o fst) eqs; |
104 |
val x_name = idx_name dnames "x"; |
|
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
105 |
fun copy_app dname = %%:(dname^"_copy")`Bound 0; |
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
106 |
val copy_def = ("copy_def" , %%:(comp_dname^"_copy") == |
17811 | 107 |
/\"f"(foldr1 cpair (map copy_app dnames))); |
11531
d038246a62f2
Renamed functions % and %% to avoid clash with syntax for proof terms.
berghofe
parents:
8438
diff
changeset
|
108 |
val bisim_def = ("bisim_def",%%:(comp_dname^"_bisim")==mk_lam("R", |
1274 | 109 |
let |
110 |
fun one_con (con,args) = let |
|
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
111 |
val nonrec_args = filter_out is_rec args; |
15570 | 112 |
val rec_args = List.filter is_rec args; |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
113 |
val recs_cnt = length rec_args; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
114 |
val allargs = nonrec_args @ rec_args |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
115 |
@ map (upd_vname (fn s=> s^"'")) rec_args; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
116 |
val allvns = map vname allargs; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
117 |
fun vname_arg s arg = if is_rec arg then vname arg^s else vname arg; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
118 |
val vns1 = map (vname_arg "" ) args; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
119 |
val vns2 = map (vname_arg "'") args; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
120 |
val allargs_cnt = length nonrec_args + 2*recs_cnt; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
121 |
val rec_idxs = (recs_cnt-1) downto 0; |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
122 |
val nonlazy_idxs = map snd (filter_out (fn (arg,_) => is_lazy arg) |
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
123 |
(allargs~~((allargs_cnt-1) downto 0))); |
4755 | 124 |
fun rel_app i ra = proj (Bound(allargs_cnt+2)) eqs (rec_of ra) $ |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
125 |
Bound (2*recs_cnt-i) $ Bound (recs_cnt-i); |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
126 |
val capps = foldr mk_conj (mk_conj( |
18083
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
127 |
Bound(allargs_cnt+1)===list_ccomb(%%:con,map (bound_arg allvns) vns1), |
cf7669049df5
cleaned up; renamed library function mk_cRep_CFun to list_ccomb; replaced rep_TFree with dest_TFree; added functions spair, mk_stuple
huffman
parents:
18075
diff
changeset
|
128 |
Bound(allargs_cnt+0)===list_ccomb(%%:con,map (bound_arg allvns) vns2))) |
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
129 |
(mapn rel_app 1 rec_args); |
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
130 |
in foldr mk_ex (Library.foldr mk_conj |
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
131 |
(map (defined o Bound) nonlazy_idxs,capps)) allvns end; |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
132 |
fun one_comp n (_,cons) =mk_all(x_name(n+1),mk_all(x_name(n+1)^"'",mk_imp( |
4755 | 133 |
proj (Bound 2) eqs n $ Bound 1 $ Bound 0, |
17811 | 134 |
foldr1 mk_disj (mk_conj(Bound 1 === UU,Bound 0 === UU) |
1637
b8a8ae2e5de1
Updated: 01-Mar-96 when functional strictified, copy_def based on when_def
oheimb
parents:
1461
diff
changeset
|
135 |
::map one_con cons)))); |
17811 | 136 |
in foldr1 mk_conj (mapn one_comp 0 eqs)end )); |
16332 | 137 |
fun add_one (thy,(dnam,axs,dfs)) = thy |
4043 | 138 |
|> Theory.add_path dnam |
16332 | 139 |
|> add_axioms_infer dfs(*add_defs_i*) |
140 |
|> add_axioms_infer axs |
|
4862 | 141 |
|> Theory.parent_path; |
15570 | 142 |
val thy = Library.foldl add_one (thy', mapn (calc_axioms comp_dname eqs) 0 eqs); |
4043 | 143 |
in thy |> Theory.add_path comp_dnam |
16332 | 144 |
|> add_axioms_infer (bisim_def::(if length eqs>1 then [copy_def] else [])) |
4862 | 145 |
|> Theory.parent_path |
4043 | 146 |
end; |
1274 | 147 |
|
148 |
end; (* local *) |
|
149 |
end; (* struct *) |