2297
|
1 |
(* Title: nominal_dt_rawfuns.ML
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Cezary Kaliszyk
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
Author: Christian Urban
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
2297
|
5 |
Definitions of the raw fv and fv_bn functions
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
*)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
signature NOMINAL_DT_RAWFUNS =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
9 |
sig
|
2295
|
10 |
(* info of binding functions *)
|
|
11 |
type bn_info = (term * int * (int * term option) list list) list
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
|
2295
|
13 |
(* binding modes and binding clauses *)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
datatype bmode = Lst | Res | Set
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
15 |
datatype bclause = BC of bmode * (term option * int) list * int list
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
16 |
|
2296
|
17 |
val is_atom: Proof.context -> typ -> bool
|
|
18 |
val is_atom_set: Proof.context -> typ -> bool
|
|
19 |
val is_atom_fset: Proof.context -> typ -> bool
|
|
20 |
val is_atom_list: Proof.context -> typ -> bool
|
|
21 |
val mk_atom_set: term -> term
|
|
22 |
val mk_atom_fset: term -> term
|
|
23 |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
val setify: Proof.context -> term -> term
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
val listify: Proof.context -> term -> term
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
|
2295
|
27 |
val define_raw_fvs: Datatype_Aux.descr -> (string * sort) list -> bn_info ->
|
2305
|
28 |
bclause list list list -> thm list -> Proof.context ->
|
|
29 |
term list * term list * thm list * thm list * local_theory
|
|
30 |
|
|
31 |
val raw_prove_eqvt: term list -> thm list -> thm list -> Proof.context -> thm list
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
end
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
structure Nominal_Dt_RawFuns: NOMINAL_DT_RAWFUNS =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
struct
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
|
2295
|
38 |
type bn_info = (term * int * (int * term option) list list) list
|
|
39 |
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
datatype bmode = Lst | Res | Set
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
datatype bclause = BC of bmode * (term option * int) list * int list
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
|
2292
|
43 |
(* testing for concrete atom types *)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
fun is_atom ctxt ty =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
Sign.of_sort (ProofContext.theory_of ctxt) (ty, @{sort at_base})
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
fun is_atom_set ctxt (Type ("fun", [t, @{typ bool}])) = is_atom ctxt t
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
| is_atom_set _ _ = false;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
fun is_atom_fset ctxt (Type (@{type_name "fset"}, [t])) = is_atom ctxt t
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
| is_atom_fset _ _ = false;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
53 |
fun is_atom_list ctxt (Type (@{type_name "list"}, [t])) = is_atom ctxt t
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
54 |
| is_atom_list _ _ = false
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
55 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
56 |
|
2292
|
57 |
(* functions for producing sets, fsets and lists of general atom type
|
|
58 |
out from concrete atom types *)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
fun mk_atom_set t =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
val ty = fastype_of t;
|
2290
|
62 |
val atom_ty = HOLogic.dest_setT ty --> @{typ "atom"};
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
val img_ty = atom_ty --> ty --> @{typ "atom set"};
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
in
|
2292
|
65 |
Const (@{const_name image}, img_ty) $ mk_atom_ty atom_ty t
|
|
66 |
end
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
67 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
68 |
fun mk_atom_fset t =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
69 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
70 |
val ty = fastype_of t;
|
2290
|
71 |
val atom_ty = dest_fsetT ty --> @{typ "atom"};
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
72 |
val fmap_ty = atom_ty --> ty --> @{typ "atom fset"};
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
73 |
val fset_to_set = @{term "fset_to_set :: atom fset => atom set"}
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
74 |
in
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
75 |
fset_to_set $ (Const (@{const_name fmap}, fmap_ty) $ Const (@{const_name atom}, atom_ty) $ t)
|
2292
|
76 |
end
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
77 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
78 |
fun mk_atom_list t =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
79 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
80 |
val ty = fastype_of t;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
81 |
val atom_ty = dest_listT ty --> @{typ atom};
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
82 |
val map_ty = atom_ty --> ty --> @{typ "atom list"};
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
83 |
in
|
2292
|
84 |
Const (@{const_name map}, map_ty) $ mk_atom_ty atom_ty t
|
|
85 |
end
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
|
2295
|
87 |
(* functions that coerces singletons, sets and fsets of concrete atoms
|
|
88 |
into sets of general atoms *)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
fun setify ctxt t =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
val ty = fastype_of t;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
in
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
if is_atom ctxt ty
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
then HOLogic.mk_set @{typ atom} [mk_atom t]
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
else if is_atom_set ctxt ty
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
then mk_atom_set t
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
else if is_atom_fset ctxt ty
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
then mk_atom_fset t
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
else raise TERM ("setify", [t])
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
100 |
end
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
101 |
|
2295
|
102 |
(* functions that coerces singletons and lists of concrete atoms
|
|
103 |
into lists of general atoms *)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
fun listify ctxt t =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
val ty = fastype_of t;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
in
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
if is_atom ctxt ty
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
then HOLogic.mk_list @{typ atom} [mk_atom t]
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
else if is_atom_list ctxt ty
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
then mk_atom_set t
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
else raise TERM ("listify", [t])
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
end
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
114 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
(* coerces a list into a set *)
|
2290
|
116 |
fun to_set t =
|
|
117 |
if fastype_of t = @{typ "atom list"}
|
|
118 |
then @{term "set::atom list => atom set"} $ t
|
|
119 |
else t
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
|
2295
|
122 |
(** functions that construct the equations for fv and fv_bn **)
|
2292
|
123 |
|
|
124 |
fun mk_fv_rhs lthy fv_map fv_bn_map args (BC (_, binders, bodies)) =
|
|
125 |
let
|
2295
|
126 |
fun mk_fv_body fv_map args i =
|
|
127 |
let
|
|
128 |
val arg = nth args i
|
|
129 |
val ty = fastype_of arg
|
|
130 |
in
|
|
131 |
case AList.lookup (op=) fv_map ty of
|
|
132 |
NONE => mk_supp arg
|
|
133 |
| SOME fv => fv $ arg
|
|
134 |
end
|
|
135 |
|
|
136 |
fun mk_fv_binder lthy fv_bn_map args (bn_option, i) =
|
|
137 |
let
|
|
138 |
val arg = nth args i
|
|
139 |
in
|
|
140 |
case bn_option of
|
|
141 |
NONE => (setify lthy arg, @{term "{}::atom set"})
|
|
142 |
| SOME bn => (to_set (bn $ arg), the (AList.lookup (op=) fv_bn_map bn) $ arg)
|
|
143 |
end
|
|
144 |
|
2292
|
145 |
val t1 = map (mk_fv_body fv_map args) bodies
|
|
146 |
val (t2, t3) = split_list (map (mk_fv_binder lthy fv_bn_map args) binders)
|
|
147 |
in
|
|
148 |
fold_union (mk_diff (fold_union t1, fold_union t2)::t3)
|
|
149 |
end
|
|
150 |
|
2293
|
151 |
(* in case of fv_bn we have to treat the case special, where an
|
|
152 |
"empty" binding clause is given *)
|
2292
|
153 |
fun mk_fv_bn_rhs lthy fv_map fv_bn_map bn_args args bclause =
|
2295
|
154 |
let
|
|
155 |
fun mk_fv_bn_body fv_map fv_bn_map bn_args args i =
|
|
156 |
let
|
|
157 |
val arg = nth args i
|
|
158 |
val ty = fastype_of arg
|
|
159 |
in
|
|
160 |
case AList.lookup (op=) bn_args i of
|
|
161 |
NONE => (case (AList.lookup (op=) fv_map ty) of
|
|
162 |
NONE => mk_supp arg
|
2296
|
163 |
| SOME fv => fv $ arg)
|
2295
|
164 |
| SOME (NONE) => @{term "{}::atom set"}
|
|
165 |
| SOME (SOME bn) => the (AList.lookup (op=) fv_bn_map bn) $ arg
|
|
166 |
end
|
|
167 |
in
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
case bclause of
|
2292
|
169 |
BC (_, [], bodies) => fold_union (map (mk_fv_bn_body fv_map fv_bn_map bn_args args) bodies)
|
2293
|
170 |
| _ => mk_fv_rhs lthy fv_map fv_bn_map args bclause
|
2295
|
171 |
end
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
|
2296
|
173 |
fun mk_fv_eq lthy fv_map fv_bn_map (constr, ty, arg_tys, _) bclauses =
|
2292
|
174 |
let
|
|
175 |
val arg_names = Datatype_Prop.make_tnames arg_tys
|
|
176 |
val args = map Free (arg_names ~~ arg_tys)
|
|
177 |
val fv = the (AList.lookup (op=) fv_map ty)
|
|
178 |
val lhs = fv $ list_comb (constr, args)
|
|
179 |
val rhs_trms = map (mk_fv_rhs lthy fv_map fv_bn_map args) bclauses
|
|
180 |
val rhs = fold_union rhs_trms
|
|
181 |
in
|
|
182 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
|
183 |
end
|
|
184 |
|
2296
|
185 |
fun mk_fv_bn_eq lthy bn_trm fv_map fv_bn_map (bn_args, (constr, _, arg_tys, _)) bclauses =
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
186 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
187 |
val arg_names = Datatype_Prop.make_tnames arg_tys
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
188 |
val args = map Free (arg_names ~~ arg_tys)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
189 |
val fv_bn = the (AList.lookup (op=) fv_bn_map bn_trm)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
190 |
val lhs = fv_bn $ list_comb (constr, args)
|
2292
|
191 |
val rhs_trms = map (mk_fv_bn_rhs lthy fv_map fv_bn_map bn_args args) bclauses
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
192 |
val rhs = fold_union rhs_trms
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
193 |
in
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
194 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
195 |
end
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
196 |
|
2292
|
197 |
fun mk_fv_bn_eqs lthy fv_map fv_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) =
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
198 |
let
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
199 |
val nth_constrs_info = nth constrs_info bn_n
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
200 |
val nth_bclausess = nth bclausesss bn_n
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
201 |
in
|
2292
|
202 |
map2 (mk_fv_bn_eq lthy bn_trm fv_map fv_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
203 |
end
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
204 |
|
2304
|
205 |
fun define_raw_fvs descr sorts bn_info bclausesss constr_thms lthy =
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
206 |
let
|
2295
|
207 |
val fv_names = prefix_dt_names descr sorts "fv_"
|
2296
|
208 |
val fv_arg_tys = all_dtyps descr sorts
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
209 |
val fv_tys = map (fn ty => ty --> @{typ "atom set"}) fv_arg_tys;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
210 |
val fv_frees = map Free (fv_names ~~ fv_tys);
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
211 |
val fv_map = fv_arg_tys ~~ fv_frees
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
212 |
|
2295
|
213 |
val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
|
|
214 |
val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
|
|
215 |
val fv_bn_names = map (prefix "fv_") bn_names
|
|
216 |
val fv_bn_arg_tys = map (fn i => nth_dtyp descr sorts i) bn_tys
|
|
217 |
val fv_bn_tys = map (fn ty => ty --> @{typ "atom set"}) fv_bn_arg_tys
|
|
218 |
val fv_bn_frees = map Free (fv_bn_names ~~ fv_bn_tys)
|
|
219 |
val fv_bn_map = bns ~~ fv_bn_frees
|
2292
|
220 |
|
2295
|
221 |
val constrs_info = all_dtyp_constrs_types descr sorts
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
222 |
|
2295
|
223 |
val fv_eqs = map2 (map2 (mk_fv_eq lthy fv_map fv_bn_map)) constrs_info bclausesss
|
|
224 |
val fv_bn_eqs = map (mk_fv_bn_eqs lthy fv_map fv_bn_map constrs_info bclausesss) bn_info
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
225 |
|
2295
|
226 |
val all_fun_names = map (fn s => (Binding.name s, NONE, NoSyn)) (fv_names @ fv_bn_names)
|
|
227 |
val all_fun_eqs = map (pair Attrib.empty_binding) (flat fv_eqs @ flat fv_bn_eqs)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
228 |
|
2295
|
229 |
val (_, lthy') = Function.add_function all_fun_names all_fun_eqs
|
2304
|
230 |
Function_Common.default_config (pat_completeness_simp constr_thms) lthy
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
231 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
232 |
val (info, lthy'') = prove_termination (Local_Theory.restore lthy')
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
233 |
|
2305
|
234 |
val {fs, simps, inducts, ...} = info;
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
235 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
236 |
val morphism = ProofContext.export_morphism lthy'' lthy
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
237 |
val fs_exp = map (Morphism.term morphism) fs
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
238 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
239 |
val (fv_frees_exp, fv_bns_exp) = chop (length fv_frees) fs_exp
|
2305
|
240 |
val simps_exp = map (Morphism.thm morphism) (the simps)
|
|
241 |
val fv_bns_inducts_exp = map (Morphism.thm morphism) (the inducts)
|
|
242 |
in
|
|
243 |
(fv_frees_exp, fv_bns_exp, simps_exp, fv_bns_inducts_exp, lthy'')
|
|
244 |
end
|
|
245 |
|
|
246 |
|
|
247 |
(** equivarance proofs **)
|
|
248 |
|
|
249 |
fun mk_eqvt_goal pi const arg =
|
|
250 |
let
|
|
251 |
val lhs = mk_perm pi (const $ arg)
|
|
252 |
val rhs = const $ (mk_perm pi arg)
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
253 |
in
|
2305
|
254 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
|
255 |
end
|
|
256 |
|
|
257 |
fun raw_prove_eqvt consts ind_thms simps ctxt =
|
|
258 |
let
|
|
259 |
val ([p], ctxt') = Variable.variant_fixes ["p"] ctxt
|
|
260 |
val p = Free (p, @{typ perm})
|
|
261 |
val arg_tys =
|
|
262 |
consts
|
|
263 |
|> map fastype_of
|
|
264 |
|> map domain_type
|
|
265 |
val (arg_names, ctxt'') = Variable.variant_fixes (replicate (length arg_tys) "") ctxt'
|
|
266 |
val args = map Free (arg_names ~~ arg_tys)
|
|
267 |
val goals = map2 (mk_eqvt_goal p) consts args
|
|
268 |
val insts = map (single o SOME) arg_names
|
|
269 |
val const_names = map (fst o dest_Const) consts
|
|
270 |
fun tac ctxt =
|
|
271 |
Object_Logic.full_atomize_tac
|
|
272 |
THEN' InductTacs.induct_rules_tac ctxt insts ind_thms
|
|
273 |
THEN_ALL_NEW
|
|
274 |
(asm_full_simp_tac (HOL_basic_ss addsimps simps)
|
|
275 |
THEN' Nominal_Permeq.eqvt_tac ctxt simps const_names
|
|
276 |
THEN' asm_simp_tac HOL_basic_ss)
|
|
277 |
in
|
|
278 |
Goal.prove_multi ctxt' [] [] goals (fn {context, ...} => (HEADGOAL (tac context)))
|
|
279 |
|> ProofContext.export ctxt'' ctxt
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
280 |
end
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
281 |
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
282 |
end (* structure *)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
283 |
|