author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Wed, 17 Feb 2010 14:35:06 +0100 | |
changeset 1173 | 9cb99a28b40e |
parent 1172 | 9a609fefcf24 |
child 1174 | f6e9ae54b855 |
permissions | -rw-r--r-- |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
1 |
theory Fv |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
2 |
imports "Nominal2_Atoms" "Nominal2_Eqvt" "Nominal2_Supp" "Abs" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
3 |
begin |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
4 |
|
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
5 |
atom_decl name |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
6 |
|
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
7 |
datatype rlam = |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
8 |
rVar "name" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
9 |
| rApp "rlam" "rlam" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
10 |
| rLam "name" "rlam" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
11 |
|
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
12 |
ML {* |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
13 |
open Datatype_Aux (* typ_of_dtyp, DtRec, ... *); |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
14 |
fun mk_atom ty = Const (@{const_name atom}, ty --> @{typ atom}) |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
15 |
*} |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
16 |
|
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
17 |
ML {* dest_Type @{typ rlam} *} |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
18 |
|
1169
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
19 |
(* Bindings are given as a list which has a length being equal |
1172
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
20 |
to the length of the number of constructors. |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
21 |
|
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
22 |
Each element is a list whose length is equal to the number |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
23 |
of arguents. |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
24 |
|
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
25 |
Every element specifies bindings of this argument given as |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
26 |
a tuple: function, bound argument. |
1169
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
27 |
|
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
28 |
Eg: |
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
29 |
nominal_datatype |
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
30 |
|
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
31 |
C1 |
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
32 |
| C2 x y z bind x in z |
1172
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
33 |
| C3 x y z bind f x in z bind g y in z |
1169
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
34 |
|
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
35 |
yields: |
1172
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
36 |
[ |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
37 |
[], |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
38 |
[[], [], [(NONE, 0)]], |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
39 |
[[], [], [(SOME (Const f), 0), (Some (Const g), 1)]]] |
1169
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
40 |
*) |
b9d02e0800e9
Description of intended bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1168
diff
changeset
|
41 |
|
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
42 |
ML foldr1 |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
43 |
ML fold |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
44 |
ML {* |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
45 |
val {descr, ...} = Datatype.the_info @{theory} "Fv.rlam"; |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
46 |
val sorts = []; |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
47 |
val noatoms = @{term "{} :: atom set"} |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
48 |
val binds = [[[]], [[], []], [[], [(NONE, 0)]]]; |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
49 |
fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i); |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
50 |
val fv_names = Datatype_Prop.indexify_names (map (fn (i, _) => |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
51 |
"fv_" ^ name_of_typ (nth_dtyp i)) descr); |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
52 |
val fv_types = map (fn (i, _) => nth_dtyp i --> @{typ "atom set"}) descr; |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
53 |
val fv_frees = map Free (fv_names ~~ fv_types); |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
54 |
fun mk_union sets = |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
55 |
fold (fn a => fn b => |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
56 |
if a = noatoms then b else |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
57 |
if b = noatoms then a else |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
58 |
HOLogic.mk_binop @{const_name union} (a, b)) sets noatoms; |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
59 |
fun mk_diff a b = |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
60 |
if b = noatoms then a else |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
61 |
HOLogic.mk_binop @{const_name "Algebras.minus_class.minus"} (a, b); |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
62 |
fun fv_eq_constr i (cname, dts) bindcs = |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
63 |
let |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
64 |
val Ts = map (typ_of_dtyp descr sorts) dts; |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
65 |
val names = Name.variant_list ["pi"] (Datatype_Prop.make_tnames Ts); |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
66 |
val args = map Free (names ~~ Ts); |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
67 |
val c = Const (cname, Ts ---> (nth_dtyp i)); |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
68 |
val fv_c = Free (nth fv_names i, (nth_dtyp i) --> @{typ "atom set"}); |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
69 |
fun fv_bind (_, i) = @{term "{} :: atom set"} |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
70 |
fun fv_arg ((dt, x), bindxs) = |
1172
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
71 |
let |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
72 |
val arg = |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
73 |
if is_rec_type dt then nth fv_frees (body_index dt) $ x |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
74 |
(* TODO: we just assume everything is a 'name' *) |
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
75 |
else HOLogic.mk_set @{typ atom} [mk_atom (type_of x) $ x] |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
76 |
val sub = mk_union (map fv_bind bindxs) |
1172
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
77 |
in |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
78 |
mk_diff arg sub |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
79 |
end; |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
80 |
val _ = tracing (string_of_int (length dts)); |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
81 |
val _ = tracing (string_of_int (length bindcs)); |
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
82 |
in |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
83 |
(Attrib.empty_binding, HOLogic.mk_Trueprop (HOLogic.mk_eq |
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
84 |
(fv_c $ list_comb (c, args), mk_union (map fv_arg (dts ~~ args ~~ bindcs))))) |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
85 |
end; |
1172
9a609fefcf24
Simplified format of bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1169
diff
changeset
|
86 |
fun fv_eq (i, (_, _, constrs)) = map2 (fv_eq_constr i) constrs binds; |
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
87 |
val fv_eqs = maps fv_eq descr |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
88 |
*} |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
89 |
|
1173
9cb99a28b40e
Some optimizations and fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
1172
diff
changeset
|
90 |
|
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
91 |
local_setup {* |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
92 |
snd o (Primrec.add_primrec |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
93 |
(map (fn s => (Binding.name s, NONE, NoSyn)) fv_names) fv_eqs) |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
94 |
*} |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
95 |
print_theorems |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
96 |
|
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
97 |
fun |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
98 |
fv_rlam :: "rlam \<Rightarrow> atom set" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
99 |
where |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
100 |
"fv_rlam (rVar a) = {atom a}" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
101 |
| "fv_rlam (rApp t1 t2) = (fv_rlam t1) \<union> (fv_rlam t2)" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
102 |
| "fv_rlam (rLam a t) = (fv_rlam t) - {atom a}" |
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
103 |
|
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
|
104 |
end |