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
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
10 |
(* info of raw datatypes *)
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
11 |
type dt_info = string list * binding * mixfix * ((binding * typ list * mixfix) list) list
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
12 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
13 |
(* info of raw binding functions *)
|
2295
|
14 |
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
|
15 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
16 |
|
2295
|
17 |
(* 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
|
18 |
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
|
19 |
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
|
20 |
|
2296
|
21 |
val is_atom: Proof.context -> typ -> bool
|
|
22 |
val is_atom_set: Proof.context -> typ -> bool
|
|
23 |
val is_atom_fset: Proof.context -> typ -> bool
|
|
24 |
val is_atom_list: Proof.context -> typ -> bool
|
|
25 |
val mk_atom_set: term -> term
|
|
26 |
val mk_atom_fset: term -> term
|
|
27 |
|
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
|
28 |
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
|
29 |
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
|
30 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
31 |
(* TODO: should be here
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
32 |
val define_raw_bns: string list -> dt_info -> (binding * typ option * mixfix) list ->
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
33 |
(Attrib.binding * term) list -> thm list -> thm list -> local_theory ->
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
34 |
(term list * thm list * bn_info * thm list * local_theory) *)
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
35 |
|
2407
|
36 |
val define_raw_fvs: string list -> typ list -> cns_info list -> bn_info -> bclause list list list ->
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
37 |
thm list -> thm list -> Proof.context -> term list * term list * thm list * thm list * local_theory
|
2305
|
38 |
|
|
39 |
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
|
40 |
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
|
41 |
|
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 |
|
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
|
43 |
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
|
44 |
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
|
45 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
46 |
(* string list - type variables of a datatype
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
47 |
binding - name of the datatype
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
48 |
mixfix - its mixfix
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
49 |
(binding * typ list * mixfix) list - datatype constructors of the type
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
50 |
*)
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
51 |
type dt_info = string list * binding * mixfix * ((binding * typ list * mixfix) list) list
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
52 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
53 |
|
2375
|
54 |
(* term - is constant of the bn-function
|
|
55 |
int - is datatype number over which the bn-function is defined
|
|
56 |
int * term option - is number of the corresponding argument with possibly
|
|
57 |
recursive call with bn-function term
|
|
58 |
*)
|
2295
|
59 |
type bn_info = (term * int * (int * term option) list list) list
|
|
60 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
61 |
|
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
|
62 |
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
|
63 |
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
|
64 |
|
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
65 |
fun lookup xs x = the (AList.lookup (op=) xs x)
|
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
66 |
|
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
67 |
|
2292
|
68 |
(* 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
|
69 |
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
|
70 |
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
|
71 |
|
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 |
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
|
73 |
| 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
|
74 |
|
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 |
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
|
76 |
| 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
|
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 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
|
79 |
| 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
|
80 |
|
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 |
|
2292
|
82 |
(* functions for producing sets, fsets and lists of general atom type
|
|
83 |
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
|
84 |
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
|
85 |
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
|
86 |
val ty = fastype_of t;
|
2290
|
87 |
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
|
88 |
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
|
89 |
in
|
2292
|
90 |
Const (@{const_name image}, img_ty) $ mk_atom_ty atom_ty t
|
|
91 |
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
|
92 |
|
2321
|
93 |
|
|
94 |
fun dest_fsetT (Type (@{type_name fset}, [T])) = T
|
|
95 |
| dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []);
|
|
96 |
|
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
|
97 |
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
|
98 |
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
|
99 |
val ty = fastype_of t;
|
2290
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
fset_to_set $ (Const (@{const_name fmap}, fmap_ty) $ Const (@{const_name atom}, atom_ty) $ t)
|
2292
|
105 |
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
|
106 |
|
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 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
in
|
2292
|
113 |
Const (@{const_name map}, map_ty) $ mk_atom_ty atom_ty t
|
|
114 |
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
|
115 |
|
2295
|
116 |
(* functions that coerces singletons, sets and fsets of concrete atoms
|
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
|
2295
|
131 |
(* functions that coerces singletons and lists of concrete atoms
|
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
|
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
|
144 |
(* coerces a list into a set *)
|
2290
|
145 |
fun to_set t =
|
|
146 |
if fastype_of t = @{typ "atom list"}
|
|
147 |
then @{term "set::atom list => atom set"} $ t
|
|
148 |
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
|
149 |
|
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
|
150 |
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
151 |
|
2295
|
152 |
(** functions that construct the equations for fv and fv_bn **)
|
2292
|
153 |
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
154 |
fun mk_fv_rhs lthy fv_map fv_bn_map args (BC (bmode, binders, bodies)) =
|
2292
|
155 |
let
|
2295
|
156 |
fun mk_fv_body fv_map args i =
|
|
157 |
let
|
|
158 |
val arg = nth args i
|
|
159 |
val ty = fastype_of arg
|
|
160 |
in
|
|
161 |
case AList.lookup (op=) fv_map ty of
|
|
162 |
NONE => mk_supp arg
|
|
163 |
| SOME fv => fv $ arg
|
|
164 |
end
|
|
165 |
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
166 |
fun mk_fv_binder lthy fv_bn_map args binders =
|
2295
|
167 |
let
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
168 |
fun bind_set lthy args (NONE, i) = (setify lthy (nth args i), @{term "{}::atom set"})
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
169 |
| bind_set _ args (SOME bn, i) = (bn $ (nth args i),
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
170 |
if member (op=) bodies i then @{term "{}::atom set"}
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
171 |
else lookup fv_bn_map bn $ (nth args i))
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
172 |
fun bind_lst lthy args (NONE, i) = (listify lthy (nth args i), @{term "[]::atom list"})
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
173 |
| bind_lst _ args (SOME bn, i) = (bn $ (nth args i),
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
174 |
if member (op=) bodies i then @{term "[]::atom list"}
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
175 |
else lookup fv_bn_map bn $ (nth args i))
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
176 |
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
177 |
val (combine_fn, bind_fn) =
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
178 |
case bmode of
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
179 |
Lst => (fold_append, bind_lst)
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
180 |
| Set => (fold_union, bind_set)
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
181 |
| Res => (fold_union, bind_set)
|
2295
|
182 |
in
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
183 |
binders
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
184 |
|> map (bind_fn lthy args)
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
185 |
|> split_list
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
186 |
|> pairself combine_fn
|
2295
|
187 |
end
|
|
188 |
|
2292
|
189 |
val t1 = map (mk_fv_body fv_map args) bodies
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
190 |
val (t2, t3) = mk_fv_binder lthy fv_bn_map args binders
|
2292
|
191 |
in
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
192 |
mk_union (mk_diff (fold_union t1, to_set t2), to_set t3)
|
2292
|
193 |
end
|
|
194 |
|
2293
|
195 |
(* in case of fv_bn we have to treat the case special, where an
|
|
196 |
"empty" binding clause is given *)
|
2292
|
197 |
fun mk_fv_bn_rhs lthy fv_map fv_bn_map bn_args args bclause =
|
2295
|
198 |
let
|
|
199 |
fun mk_fv_bn_body fv_map fv_bn_map bn_args args i =
|
|
200 |
let
|
|
201 |
val arg = nth args i
|
|
202 |
val ty = fastype_of arg
|
|
203 |
in
|
|
204 |
case AList.lookup (op=) bn_args i of
|
|
205 |
NONE => (case (AList.lookup (op=) fv_map ty) of
|
|
206 |
NONE => mk_supp arg
|
2296
|
207 |
| SOME fv => fv $ arg)
|
2295
|
208 |
| SOME (NONE) => @{term "{}::atom set"}
|
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
209 |
| SOME (SOME bn) => lookup fv_bn_map bn $ arg
|
2295
|
210 |
end
|
|
211 |
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
|
212 |
case bclause of
|
2292
|
213 |
BC (_, [], bodies) => fold_union (map (mk_fv_bn_body fv_map fv_bn_map bn_args args) bodies)
|
2293
|
214 |
| _ => mk_fv_rhs lthy fv_map fv_bn_map args bclause
|
2295
|
215 |
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
|
216 |
|
2296
|
217 |
fun mk_fv_eq lthy fv_map fv_bn_map (constr, ty, arg_tys, _) bclauses =
|
2292
|
218 |
let
|
|
219 |
val arg_names = Datatype_Prop.make_tnames arg_tys
|
|
220 |
val args = map Free (arg_names ~~ arg_tys)
|
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
221 |
val fv = lookup fv_map ty
|
2292
|
222 |
val lhs = fv $ list_comb (constr, args)
|
|
223 |
val rhs_trms = map (mk_fv_rhs lthy fv_map fv_bn_map args) bclauses
|
|
224 |
val rhs = fold_union rhs_trms
|
|
225 |
in
|
|
226 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
|
227 |
end
|
|
228 |
|
2296
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
val args = map Free (arg_names ~~ arg_tys)
|
2438
abafea9b39bb
corrected bug with fv-function generation (that was the problem with recursive binders)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
233 |
val fv_bn = lookup fv_bn_map bn_trm
|
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
|
234 |
val lhs = fv_bn $ list_comb (constr, args)
|
2292
|
235 |
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
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
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
|
240 |
|
2292
|
241 |
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
|
242 |
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
|
243 |
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
|
244 |
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
|
245 |
in
|
2292
|
246 |
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
|
247 |
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
|
248 |
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
249 |
fun define_raw_fvs raw_full_ty_names raw_tys cns_info bn_info bclausesss constr_thms size_simps 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
|
250 |
let
|
2407
|
251 |
val fv_names = map (prefix "fv_" o Long_Name.base_name) raw_full_ty_names
|
|
252 |
val fv_tys = map (fn ty => ty --> @{typ "atom set"}) raw_tys
|
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 |
val fv_frees = map Free (fv_names ~~ fv_tys);
|
2407
|
254 |
val fv_map = raw_tys ~~ fv_frees
|
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
|
255 |
|
2295
|
256 |
val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_info)
|
|
257 |
val bn_names = map (fn bn => Long_Name.base_name (fst (dest_Const bn))) bns
|
|
258 |
val fv_bn_names = map (prefix "fv_") bn_names
|
2407
|
259 |
val fv_bn_arg_tys = map (nth raw_tys) bn_tys
|
2295
|
260 |
val fv_bn_tys = map (fn ty => ty --> @{typ "atom set"}) fv_bn_arg_tys
|
|
261 |
val fv_bn_frees = map Free (fv_bn_names ~~ fv_bn_tys)
|
|
262 |
val fv_bn_map = bns ~~ fv_bn_frees
|
2292
|
263 |
|
2407
|
264 |
val fv_eqs = map2 (map2 (mk_fv_eq lthy fv_map fv_bn_map)) cns_info bclausesss
|
|
265 |
val fv_bn_eqs = map (mk_fv_bn_eqs lthy fv_map fv_bn_map cns_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
|
266 |
|
2295
|
267 |
val all_fun_names = map (fn s => (Binding.name s, NONE, NoSyn)) (fv_names @ fv_bn_names)
|
|
268 |
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
|
269 |
|
2295
|
270 |
val (_, lthy') = Function.add_function all_fun_names all_fun_eqs
|
2304
|
271 |
Function_Common.default_config (pat_completeness_simp constr_thms) lthy
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
272 |
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
273 |
val (info, lthy'') = prove_termination size_simps (Local_Theory.restore lthy')
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
274 |
|
2305
|
275 |
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
|
276 |
|
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
|
277 |
val morphism = ProofContext.export_morphism lthy'' lthy
|
2409
|
278 |
val simps_exp = map (Morphism.thm morphism) (the simps)
|
|
279 |
val inducts_exp = map (Morphism.thm morphism) (the inducts)
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
280 |
|
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
281 |
val (fvs', fv_bns') = chop (length fv_frees) fs
|
2305
|
282 |
in
|
2431
331873ebc5cd
can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
283 |
(fvs', fv_bns', simps_exp, inducts_exp, lthy'')
|
2305
|
284 |
end
|
|
285 |
|
|
286 |
|
|
287 |
(** equivarance proofs **)
|
|
288 |
|
2311
|
289 |
val eqvt_apply_sym = @{thm eqvt_apply[symmetric]}
|
|
290 |
|
|
291 |
fun subproof_tac const_names simps =
|
2388
|
292 |
SUBPROOF (fn {prems, context, ...} =>
|
2311
|
293 |
HEADGOAL
|
|
294 |
(simp_tac (HOL_basic_ss addsimps simps)
|
|
295 |
THEN' Nominal_Permeq.eqvt_tac context [] const_names
|
2388
|
296 |
THEN' simp_tac (HOL_basic_ss addsimps (prems @ [eqvt_apply_sym]))))
|
2311
|
297 |
|
|
298 |
fun prove_eqvt_tac insts ind_thms const_names simps ctxt =
|
|
299 |
HEADGOAL
|
|
300 |
(Object_Logic.full_atomize_tac
|
|
301 |
THEN' (DETERM o (InductTacs.induct_rules_tac ctxt insts ind_thms))
|
|
302 |
THEN_ALL_NEW subproof_tac const_names simps ctxt)
|
|
303 |
|
2305
|
304 |
fun mk_eqvt_goal pi const arg =
|
|
305 |
let
|
|
306 |
val lhs = mk_perm pi (const $ arg)
|
|
307 |
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
|
308 |
in
|
2305
|
309 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
|
310 |
end
|
|
311 |
|
|
312 |
fun raw_prove_eqvt consts ind_thms simps ctxt =
|
2308
|
313 |
if null consts then []
|
|
314 |
else
|
|
315 |
let
|
|
316 |
val ([p], ctxt') = Variable.variant_fixes ["p"] ctxt
|
|
317 |
val p = Free (p, @{typ perm})
|
|
318 |
val arg_tys =
|
|
319 |
consts
|
|
320 |
|> map fastype_of
|
|
321 |
|> map domain_type
|
2311
|
322 |
val (arg_names, ctxt'') =
|
|
323 |
Variable.variant_fixes (Datatype_Prop.make_tnames arg_tys) ctxt'
|
2308
|
324 |
val args = map Free (arg_names ~~ arg_tys)
|
|
325 |
val goals = map2 (mk_eqvt_goal p) consts args
|
|
326 |
val insts = map (single o SOME) arg_names
|
2311
|
327 |
val const_names = map (fst o dest_Const) consts
|
2308
|
328 |
in
|
2311
|
329 |
Goal.prove_multi ctxt'' [] [] goals (fn {context, ...} =>
|
|
330 |
prove_eqvt_tac insts ind_thms const_names simps context)
|
2308
|
331 |
|> ProofContext.export ctxt'' ctxt
|
|
332 |
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
|
333 |
|
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
|
334 |
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
|
335 |
|