1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 1
theory Fv
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 2
imports "Nominal2_Atoms" "Abs" "Perm" "Rsp" "Nominal2_FSet"
1168
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
1505
+ − 5
(* The bindings data structure:
+ − 6
+ − 7
Bindings are a list of lists of lists of triples.
1172
+ − 8
1358
+ − 9
The first list represents the datatypes defined.
+ − 10
The second list represents the constructors.
+ − 11
The internal list is a list of all the bndings that
+ − 12
concern the constructor.
1172
+ − 13
1358
+ − 14
Every triple consists of a function, the binding and
+ − 15
the body.
1169
+ − 16
+ − 17
Eg:
+ − 18
nominal_datatype
+ − 19
+ − 20
C1
+ − 21
| C2 x y z bind x in z
1172
+ − 22
| C3 x y z bind f x in z bind g y in z
1169
+ − 23
+ − 24
yields:
1172
+ − 25
[
+ − 26
[],
1358
+ − 27
[(NONE, 0, 2)],
+ − 28
[(SOME (Const f), 0, 2), (Some (Const g), 1, 2)]]
1185
+ − 29
1358
+ − 30
A SOME binding has to have a function which takes an appropriate
+ − 31
argument and returns an atom set. A NONE binding has to be on an
+ − 32
argument that is an atom or an atom set.
1505
+ − 33
*)
1185
+ − 34
1505
+ − 35
(*
1510
+ − 36
An overview of the generation of free variables:
1505
+ − 37
+ − 38
1) fv_bn functions are generated only for the non-recursive binds.
+ − 39
+ − 40
An fv_bn for a constructor is a union of values for the arguments:
1191
+ − 41
1505
+ − 42
For an argument x that is in the bn function
+ − 43
- if it is a recursive argument bn' we return: fv_bn' x
+ − 44
- otherwise empty
+ − 45
+ − 46
For an argument x that is not in the bn function
+ − 47
- for atom we return: {atom x}
+ − 48
- for atom set we return: atom ` x
+ − 49
- for a recursive call to type ty' we return: fv_ty' x
+ − 50
with fv of the appropriate type
+ − 51
- otherwise empty
+ − 52
1514
+ − 53
2) fv_ty functions generated for all types being defined:
1191
+ − 54
1514
+ − 55
fv_ty for a constructor is a union of values for the arguments.
1505
+ − 56
1508
+ − 57
For an argument that is bound in a shallow binding we return empty.
+ − 58
+ − 59
For an argument x that bound in a non-recursive deep binding
1505
+ − 60
we return: fv_bn x.
+ − 61
+ − 62
Otherwise we return the free variables of the argument minus the
+ − 63
bound variables of the argument.
1358
+ − 64
1505
+ − 65
The free variables for an argument x are:
+ − 66
- for an atom: {atom x}
+ − 67
- for atom set: atom ` x
+ − 68
- for recursive call to type ty' return: fv_ty' x
+ − 69
- for nominal datatype ty' return: fv_ty' x
+ − 70
+ − 71
The bound variables are a union of results of all bindings that
+ − 72
involve the given argument. For a paricular binding:
+ − 73
+ − 74
- for a binding function bn: bn x
+ − 75
- for a recursive argument of type ty': fv_fy' x
+ − 76
- for nominal datatype ty' return: fv_ty' x
1169
+ − 77
*)
+ − 78
1510
+ − 79
(*
+ − 80
An overview of the generation of alpha-equivalence:
1513
+ − 81
+ − 82
1) alpha_bn relations are generated for binding functions.
+ − 83
+ − 84
An alpha_bn for a constructor is true if a conjunction of
+ − 85
propositions for each argument holds.
+ − 86
+ − 87
For an argument a proposition is build as follows from
+ − 88
th:
+ − 89
+ − 90
- for a recursive argument in the bn function, we return: alpha_bn argl argr
+ − 91
- for a recursive argument for type ty not in bn, we return: alpha_ty argl argr
+ − 92
- for other arguments in the bn function we return: True
+ − 93
- for other arguments not in the bn function we return: argl = argr
+ − 94
1514
+ − 95
2) alpha_ty relations are generated for all the types being defined:
+ − 96
1516
+ − 97
For each constructor we gather all the arguments that are bound,
+ − 98
and for each of those we add a permutation. We associate those
+ − 99
permutations with the bindings. Note that two bindings can have
+ − 100
the same permutation if the arguments being bound are the same.
1514
+ − 101
1516
+ − 102
An alpha_ty for a constructor is true if there exist permutations
+ − 103
as above such that a conjunction of propositions for all arguments holds.
1514
+ − 104
+ − 105
For an argument we allow bindings where only one of the following
+ − 106
holds:
+ − 107
+ − 108
- Argument is bound in some shallow bindings: We return true
1516
+ − 109
- Argument of type ty is bound recursively in some other
+ − 110
arguments [i1, .. in] with one binding function bn.
+ − 111
We return:
+ − 112
+ − 113
(bn argl, (argl, argl_i1, ..., argl_in)) \<approx>gen
+ − 114
\<lambda>(argl,argl1,..,argln) (argr,argr1,..,argrn).
+ − 115
(alpha_ty argl argr) \<and> (alpha_i1 argl1 argr1) \<and> .. \<and> (alpha_in argln argrn)
+ − 116
\<lambda>(arg,arg1,..,argn). (fv_ty arg) \<union> (fv_i1 arg1) \<union> .. \<union> (fv_in argn)
+ − 117
pi
+ − 118
(bn argr, (argr, argr_i1, ..., argr_in))
+ − 119
1514
+ − 120
- Argument is bound in some deep non-recursive bindings.
+ − 121
We return: alpha_bn argl argr
1516
+ − 122
- Argument of type ty has some shallow bindings [b1..bn] and/or
+ − 123
non-recursive bindings [f1 a1, .., fm am], where the bindings
+ − 124
have the permutations p1..pl. We return:
+ − 125
+ − 126
(b1l \<union>..\<union> bnl \<union> f1 a1l \<union>..\<union> fn anl, argl) \<approx>gen
+ − 127
alpha_ty fv_ty (p1 +..+ pl)
+ − 128
(b1r \<union>..\<union> bnr \<union> f1 a1r \<union>..\<union> fn anr, argr)
+ − 129
1514
+ − 130
- Argument has some recursive bindings. The bindings were
+ − 131
already treated in 2nd case so we return: True
+ − 132
- Argument has no bindings and is not bound.
+ − 133
If it is recursive for type ty, we return: alpha_ty argl argr
+ − 134
Otherwise we return: argl = argr
+ − 135
1510
+ − 136
*)
+ − 137
1362
+ − 138
ML {*
+ − 139
fun is_atom thy typ =
+ − 140
Sign.of_sort thy (typ, @{sort at})
1366
+ − 141
+ − 142
fun is_atom_set thy (Type ("fun", [t, @{typ bool}])) = is_atom thy t
+ − 143
| is_atom_set thy _ = false;
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 144
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 145
fun is_atom_fset thy (Type ("FSet.fset", [t])) = is_atom thy t
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 146
| is_atom_fset thy _ = false;
1362
+ − 147
*}
+ − 148
+ − 149
1358
+ − 150
(* Like map2, only if the second list is empty passes empty lists insted of error *)
1302
+ − 151
ML {*
+ − 152
fun map2i _ [] [] = []
+ − 153
| map2i f (x :: xs) (y :: ys) = f x y :: map2i f xs ys
+ − 154
| map2i f (x :: xs) [] = f x [] :: map2i f xs []
+ − 155
| map2i _ _ _ = raise UnequalLengths;
+ − 156
*}
+ − 157
1358
+ − 158
(* Finds bindings with the same function and binding, and gathers all
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 159
bodys for such pairs
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 160
*)
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 161
ML {*
1357
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 162
fun gather_binds binds =
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 163
let
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 164
fun gather_binds_cons binds =
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 165
let
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 166
val common = map (fn (f, bi, _) => (f, bi)) binds
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 167
val nodups = distinct (op =) common
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 168
fun find_bodys (sf, sbi) =
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 169
filter (fn (f, bi, _) => f = sf andalso bi = sbi) binds
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 170
val bodys = map ((map (fn (_, _, bo) => bo)) o find_bodys) nodups
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 171
in
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 172
nodups ~~ bodys
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 173
end
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 174
in
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 175
map (map gather_binds_cons) binds
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 176
end
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 177
*}
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 178
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 179
ML {*
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 180
fun un_gather_binds_cons binds =
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 181
flat (map (fn (((f, bi), bos), pi) => map (fn bo => ((f, bi, bo), pi)) bos) binds)
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 182
*}
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 183
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 184
ML {*
1175
+ − 185
open Datatype_Aux; (* typ_of_dtyp, DtRec, ... *);
1178
+ − 186
(* TODO: It is the same as one in 'nominal_atoms' *)
1175
+ − 187
fun mk_atom ty = Const (@{const_name atom}, ty --> @{typ atom});
+ − 188
val noatoms = @{term "{} :: atom set"};
+ − 189
fun mk_single_atom x = HOLogic.mk_set @{typ atom} [mk_atom (type_of x) $ x];
+ − 190
fun mk_union sets =
+ − 191
fold (fn a => fn b =>
+ − 192
if a = noatoms then b else
+ − 193
if b = noatoms then a else
1323
+ − 194
if a = b then a else
1325
+ − 195
HOLogic.mk_binop @{const_name sup} (a, b)) (rev sets) noatoms;
+ − 196
val mk_inter = foldr1 (HOLogic.mk_binop @{const_name inf})
1175
+ − 197
fun mk_diff a b =
+ − 198
if b = noatoms then a else
+ − 199
if b = a then noatoms else
+ − 200
HOLogic.mk_binop @{const_name minus} (a, b);
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 201
fun mk_atom_set t =
1185
+ − 202
let
+ − 203
val ty = fastype_of t;
+ − 204
val atom_ty = HOLogic.dest_setT ty --> @{typ atom};
+ − 205
val img_ty = atom_ty --> ty --> @{typ "atom set"};
+ − 206
in
+ − 207
(Const (@{const_name image}, img_ty) $ Const (@{const_name atom}, atom_ty) $ t)
+ − 208
end;
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 209
fun mk_atom_fset t =
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 210
let
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 211
val ty = fastype_of t;
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 212
val atom_ty = dest_fsetT ty --> @{typ atom};
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 213
val fmap_ty = atom_ty --> ty --> @{typ "atom fset"};
1656
+ − 214
val fset_to_set = @{term "fset_to_set :: atom fset \<Rightarrow> atom set"}
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 215
in
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 216
fset_to_set $ ((Const (@{const_name fmap}, fmap_ty) $ Const (@{const_name atom}, atom_ty) $ t))
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 217
end;
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 218
(* Similar to one in USyntax *)
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 219
fun mk_pair (fst, snd) =
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 220
let val ty1 = fastype_of fst
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 221
val ty2 = fastype_of snd
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 222
val c = HOLogic.pair_const ty1 ty2
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 223
in c $ fst $ snd
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 224
end;
1468
+ − 225
*}
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 226
1468
+ − 227
(* Given [fv1, fv2, fv3] creates %(x, y, z). fv1 x u fv2 y u fv3 z *)
+ − 228
ML {*
+ − 229
fun mk_compound_fv fvs =
+ − 230
let
+ − 231
val nos = (length fvs - 1) downto 0;
+ − 232
val fvs_applied = map (fn (fv, no) => fv $ Bound no) (fvs ~~ nos);
+ − 233
val fvs_union = mk_union fvs_applied;
+ − 234
val (tyh :: tys) = rev (map (domain_type o fastype_of) fvs);
+ − 235
fun fold_fun ty t = HOLogic.mk_split (Abs ("", ty, t))
+ − 236
in
+ − 237
fold fold_fun tys (Abs ("", tyh, fvs_union))
+ − 238
end;
1175
+ − 239
*}
+ − 240
1468
+ − 241
(* Given [R1, R2, R3] creates %(x,x'). %(y,y'). %(z,z'). R x x' \<and> R y y' \<and> R z z' *)
+ − 242
ML {*
+ − 243
fun mk_compound_alpha Rs =
+ − 244
let
+ − 245
val nos = (length Rs - 1) downto 0;
+ − 246
val nos2 = (2 * length Rs - 1) downto length Rs;
+ − 247
val Rs_applied = map (fn (R, (no2, no)) => R $ Bound no2 $ Bound no) (Rs ~~ (nos2 ~~ nos));
+ − 248
val Rs_conj = mk_conjl Rs_applied;
+ − 249
val (tyh :: tys) = rev (map (domain_type o fastype_of) Rs);
+ − 250
fun fold_fun ty t = HOLogic.mk_split (Abs ("", ty, t))
+ − 251
val abs_rhs = fold fold_fun tys (Abs ("", tyh, Rs_conj))
+ − 252
in
+ − 253
fold fold_fun tys (Abs ("", tyh, abs_rhs))
+ − 254
end;
+ − 255
*}
+ − 256
1288
+ − 257
ML {* fun add_perm (p1, p2) = Const(@{const_name plus}, @{typ "perm \<Rightarrow> perm \<Rightarrow> perm"}) $ p1 $ p2 *}
+ − 258
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 259
ML {*
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 260
fun non_rec_binds l =
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 261
let
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 262
fun is_non_rec (SOME (f, false), _, _) = SOME f
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 263
| is_non_rec _ = NONE
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 264
in
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 265
distinct (op =) (map_filter is_non_rec (flat (flat l)))
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 266
end
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 267
*}
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 268
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 269
(* We assume no bindings in the type on which bn is defined *)
1505
+ − 270
(* TODO: currently works only with current fv_bn function *)
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 271
ML {*
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 272
fun fv_bn thy (dt_info : Datatype_Aux.info) fv_frees bn_fvbn (fvbn, (bn, ith_dtyp, args_in_bns)) =
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 273
let
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 274
val {descr, sorts, ...} = dt_info;
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 275
fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
1379
+ − 276
fun fv_bn_constr (cname, dts) args_in_bn =
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 277
let
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 278
val Ts = map (typ_of_dtyp descr sorts) dts;
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 279
val names = Datatype_Prop.make_tnames Ts;
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 280
val args = map Free (names ~~ Ts);
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 281
val c = Const (cname, Ts ---> (nth_dtyp ith_dtyp));
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 282
fun fv_arg ((dt, x), arg_no) =
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 283
let
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 284
val ty = fastype_of x
1622
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 285
(* val _ = tracing ("B 1" ^ PolyML.makestring args_in_bn);*)
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 286
(* val _ = tracing ("B 2" ^ PolyML.makestring bn_fvbn);*)
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 287
in
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 288
case AList.lookup (op=) args_in_bn arg_no of
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 289
SOME NONE => @{term "{} :: atom set"}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 290
| SOME (SOME (f : term)) => (the (AList.lookup (op=) bn_fvbn f)) $ x
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 291
| NONE =>
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 292
if is_atom thy ty then mk_single_atom x else
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 293
if is_atom_set thy ty then mk_atom_set x else
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 294
if is_atom_fset thy ty then mk_atom_fset x else
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 295
if is_rec_type dt then nth fv_frees (body_index dt) $ x else
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 296
@{term "{} :: atom set"}
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 297
end;
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 298
val arg_nos = 0 upto (length dts - 1)
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 299
in
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 300
HOLogic.mk_Trueprop (HOLogic.mk_eq
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 301
(fvbn $ list_comb (c, args), mk_union (map fv_arg (dts ~~ args ~~ arg_nos))))
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 302
end;
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 303
val (_, (_, _, constrs)) = nth descr ith_dtyp;
1379
+ − 304
val eqs = map2i fv_bn_constr constrs args_in_bns
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 305
in
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 306
((bn, fvbn), eqs)
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 307
end
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 308
*}
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 309
1385
+ − 310
ML {*
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 311
fun fv_bns thy dt_info fv_frees rel_bns =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 312
let
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 313
fun mk_fvbn_free (bn, ith, _) =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 314
let
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 315
val fvbn_name = "fv_" ^ (Long_Name.base_name (fst (dest_Const bn)));
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 316
in
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 317
(fvbn_name, Free (fvbn_name, fastype_of (nth fv_frees ith)))
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 318
end;
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 319
val (fvbn_names, fvbn_frees) = split_list (map mk_fvbn_free rel_bns);
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 320
val bn_fvbn = (map (fn (bn, _, _) => bn) rel_bns) ~~ fvbn_frees
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 321
val (l1, l2) = split_list (map (fv_bn thy dt_info fv_frees bn_fvbn) (fvbn_frees ~~ rel_bns));
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 322
in
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 323
(l1, (fvbn_names ~~ l2))
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 324
end
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 325
*}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 326
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 327
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 328
ML {*
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 329
fun alpha_bn thy (dt_info : Datatype_Aux.info) alpha_frees bn_alphabn ((bn, ith_dtyp, args_in_bns), (alpha_bn_free, is_rec)) =
1385
+ − 330
let
+ − 331
val {descr, sorts, ...} = dt_info;
+ − 332
fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
1457
91fe914e1bef
alpha_bn doesn't need the permutation in non-recursive case.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 333
val pi = Free("pi", @{typ perm})
1386
+ − 334
fun alpha_bn_constr (cname, dts) args_in_bn =
+ − 335
let
+ − 336
val Ts = map (typ_of_dtyp descr sorts) dts;
+ − 337
val names = Name.variant_list ["pi"] (Datatype_Prop.make_tnames Ts);
+ − 338
val names2 = Name.variant_list ("pi" :: names) (Datatype_Prop.make_tnames Ts);
+ − 339
val args = map Free (names ~~ Ts);
+ − 340
val args2 = map Free (names2 ~~ Ts);
+ − 341
val c = Const (cname, Ts ---> (nth_dtyp ith_dtyp));
1387
+ − 342
val rhs = HOLogic.mk_Trueprop
1462
+ − 343
(alpha_bn_free $ (list_comb (c, args)) $ (list_comb (c, args2)));
1387
+ − 344
fun lhs_arg ((dt, arg_no), (arg, arg2)) =
1388
+ − 345
let
+ − 346
val argty = fastype_of arg;
+ − 347
val permute = Const (@{const_name permute}, @{typ perm} --> argty --> argty);
+ − 348
in
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 349
case AList.lookup (op=) args_in_bn arg_no of
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 350
SOME NONE => @{term True}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 351
| SOME (SOME f) => (the (AList.lookup (op=) bn_alphabn f)) $ arg $ arg2
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 352
| NONE =>
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 353
if is_rec_type dt then (nth alpha_frees (body_index dt)) $ arg $ arg2
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 354
else HOLogic.mk_eq (arg, arg2)
1388
+ − 355
end
1387
+ − 356
val arg_nos = 0 upto (length dts - 1)
+ − 357
val lhss = mk_conjl (map lhs_arg (dts ~~ arg_nos ~~ (args ~~ args2)))
+ − 358
val eq = Logic.mk_implies (HOLogic.mk_Trueprop lhss, rhs)
1386
+ − 359
in
1387
+ − 360
eq
1386
+ − 361
end
1385
+ − 362
val (_, (_, _, constrs)) = nth descr ith_dtyp;
1386
+ − 363
val eqs = map2i alpha_bn_constr constrs args_in_bns
1385
+ − 364
in
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 365
((bn, alpha_bn_free), eqs)
1385
+ − 366
end
+ − 367
*}
+ − 368
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 369
ML {*
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 370
fun alpha_bns thy dt_info alpha_frees rel_bns bns_rec =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 371
let
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 372
val {descr, sorts, ...} = dt_info;
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 373
fun nth_dtyp i = typ_of_dtyp descr sorts (DtRec i);
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 374
fun mk_alphabn_free (bn, ith, _) =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 375
let
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 376
val alphabn_name = "alpha_" ^ (Long_Name.base_name (fst (dest_Const bn)));
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 377
val alphabn_type = nth_dtyp ith --> nth_dtyp ith --> @{typ bool};
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 378
val alphabn_free = Free(alphabn_name, alphabn_type);
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 379
in
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 380
(alphabn_name, alphabn_free)
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 381
end;
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 382
val (alphabn_names, alphabn_frees) = split_list (map mk_alphabn_free rel_bns);
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 383
val bn_alphabn = (map (fn (bn, _, _) => bn) rel_bns) ~~ alphabn_frees;
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 384
val pair = split_list (map (alpha_bn thy dt_info alpha_frees bn_alphabn)
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 385
(rel_bns ~~ (alphabn_frees ~~ bns_rec)))
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 386
in
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 387
(alphabn_names, pair)
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 388
end
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 389
*}
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 390
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 391
1397
+ − 392
(* Checks that a list of bindings contains only compatible ones *)
+ − 393
ML {*
+ − 394
fun bns_same l =
+ − 395
length (distinct (op =) (map (fn ((b, _, _), _) => b) l)) = 1
+ − 396
*}
+ − 397
1206
+ − 398
(* TODO: Notice datatypes without bindings and replace alpha with equality *)
1175
+ − 399
ML {*
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 400
fun define_fv_alpha (dt_info : Datatype_Aux.info) bindsall bns lthy =
1178
+ − 401
let
1366
+ − 402
val thy = ProofContext.theory_of lthy;
1277
+ − 403
val {descr, sorts, ...} = dt_info;
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 404
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
+ − 405
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
+ − 406
"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
+ − 407
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
+ − 408
val fv_frees = map Free (fv_names ~~ fv_types);
1622
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 409
(* TODO: We need a transitive closure, but instead we do this hack considering
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 410
all binding functions as recursive or not *)
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 411
val nr_bns =
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 412
if (non_rec_binds bindsall) = [] then []
006d81399f6a
Compute Fv for non-recursive bn functions calling other bn functions
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 413
else map (fn (bn, _, _) => bn) bns;
1464
1850361efb8f
Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 414
val rel_bns = filter (fn (bn, _, _) => bn mem nr_bns) bns;
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 415
val (bn_fv_bns, fv_bn_names_eqs) = fv_bns thy dt_info fv_frees rel_bns;
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 416
val fvbns = map snd bn_fv_bns;
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 417
val (fv_bn_names, fv_bn_eqs) = split_list fv_bn_names_eqs;
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 418
val alpha_names = Datatype_Prop.indexify_names (map (fn (i, _) =>
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 419
"alpha_" ^ name_of_typ (nth_dtyp i)) descr);
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 420
val alpha_types = map (fn (i, _) => nth_dtyp i --> nth_dtyp i --> @{typ bool}) descr;
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 421
val alpha_frees = map Free (alpha_names ~~ alpha_types);
1385
+ − 422
(* We assume that a bn is either recursive or not *)
+ − 423
val bns_rec = map (fn (bn, _, _) => not (bn mem nr_bns)) bns;
1615
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 424
val (alpha_bn_names, (bn_alpha_bns, alpha_bn_eqs)) =
0ea578c6dae3
Parsing bn functions that call other bn functions and transmitting this information to fv/alpha.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 425
alpha_bns thy dt_info alpha_frees bns bns_rec
1389
+ − 426
val alpha_bn_frees = map snd bn_alpha_bns;
+ − 427
val alpha_bn_types = map fastype_of alpha_bn_frees;
1288
+ − 428
fun fv_alpha_constr ith_dtyp (cname, dts) bindcs =
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 429
let
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 430
val Ts = map (typ_of_dtyp descr sorts) dts;
1288
+ − 431
val bindslen = length bindcs
1323
+ − 432
val pi_strs_same = replicate bindslen "pi"
+ − 433
val pi_strs = Name.variant_list [] pi_strs_same;
1288
+ − 434
val pis = map (fn ps => Free (ps, @{typ perm})) pi_strs;
1357
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 435
val bind_pis_gath = bindcs ~~ pis;
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 436
val bind_pis = un_gather_binds_cons bind_pis_gath;
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 437
val bindcs = map fst bind_pis;
1288
+ − 438
val names = Name.variant_list pi_strs (Datatype_Prop.make_tnames Ts);
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 439
val args = map Free (names ~~ Ts);
1288
+ − 440
val names2 = Name.variant_list (pi_strs @ names) (Datatype_Prop.make_tnames Ts);
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 441
val args2 = map Free (names2 ~~ Ts);
1288
+ − 442
val c = Const (cname, Ts ---> (nth_dtyp ith_dtyp));
+ − 443
val fv_c = nth fv_frees ith_dtyp;
+ − 444
val alpha = nth alpha_frees ith_dtyp;
+ − 445
val arg_nos = 0 upto (length dts - 1)
+ − 446
fun fv_bind args (NONE, i, _) =
1177
+ − 447
if is_rec_type (nth dts i) then (nth fv_frees (body_index (nth dts i))) $ (nth args i) else
1366
+ − 448
if ((is_atom thy) o fastype_of) (nth args i) then mk_single_atom (nth args i) else
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 449
if ((is_atom_set thy) o fastype_of) (nth args i) then mk_atom_set (nth args i) else
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 450
if ((is_atom_fset thy) o fastype_of) (nth args i) then mk_atom_fset (nth args i) else
1366
+ − 451
(* TODO we do not know what to do with non-atomizable things *)
+ − 452
@{term "{} :: atom set"}
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 453
| fv_bind args (SOME (f, _), i, _) = f $ (nth args i);
1288
+ − 454
fun fv_binds args relevant = mk_union (map (fv_bind args) relevant)
1464
1850361efb8f
Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 455
fun find_nonrec_binder j (SOME (f, false), i, _) = if i = j then SOME f else NONE
1850361efb8f
Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 456
| find_nonrec_binder _ _ = NONE
1288
+ − 457
fun fv_arg ((dt, x), arg_no) =
1464
1850361efb8f
Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 458
case get_first (find_nonrec_binder arg_no) bindcs of
1850361efb8f
Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 459
SOME f =>
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 460
(case get_first (fn (x, y) => if x = f then SOME y else NONE) bn_fv_bns of
1464
1850361efb8f
Revert 7c8cd6eae8e2, now all proofs in Term5 go through, both recursive and not.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 461
SOME fv_bn => fv_bn $ x
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 462
| NONE => error "bn specified in a non-rec binding but not in bn list")
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 463
| NONE =>
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 464
let
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 465
val arg =
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 466
if is_rec_type dt then nth fv_frees (body_index dt) $ x else
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 467
if ((is_atom thy) o fastype_of) x then mk_single_atom x else
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 468
if ((is_atom_set thy) o fastype_of) x then mk_atom_set x else
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 469
if ((is_atom_fset thy) o fastype_of) x then mk_atom_fset x else
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 470
(* TODO we do not know what to do with non-atomizable things *)
1454
7c8cd6eae8e2
FV_bn generated for recursive functions as well, and used in main fv for bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 471
@{term "{} :: atom set"};
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 472
(* If i = j then we generate it only once *)
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 473
val relevant = filter (fn (_, i, j) => ((i = arg_no) orelse (j = arg_no))) bindcs;
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 474
val sub = fv_binds args relevant
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 475
in
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 476
mk_diff arg sub
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 477
end;
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 478
val fv_eq = HOLogic.mk_Trueprop (HOLogic.mk_eq
1288
+ − 479
(fv_c $ list_comb (c, args), mk_union (map fv_arg (dts ~~ args ~~ arg_nos))))
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 480
val alpha_rhs =
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 481
HOLogic.mk_Trueprop (alpha $ (list_comb (c, args)) $ (list_comb (c, args2)));
1288
+ − 482
fun alpha_arg ((dt, arg_no), (arg, arg2)) =
+ − 483
let
1383
+ − 484
val rel_in_simp_binds = filter (fn ((NONE, i, _), _) => i = arg_no | _ => false) bind_pis;
+ − 485
val rel_in_comp_binds = filter (fn ((SOME _, i, _), _) => i = arg_no | _ => false) bind_pis;
1468
+ − 486
val rel_has_binds = filter (fn ((NONE, _, j), _) => j = arg_no
+ − 487
| ((SOME (_, false), _, j), _) => j = arg_no
+ − 488
| _ => false) bind_pis;
1472
+ − 489
val rel_has_rec_binds = filter
+ − 490
(fn ((SOME (_, true), _, j), _) => j = arg_no | _ => false) bind_pis;
1288
+ − 491
in
1472
+ − 492
case (rel_in_simp_binds, rel_in_comp_binds, rel_has_binds, rel_has_rec_binds) of
+ − 493
([], [], [], []) =>
1383
+ − 494
if is_rec_type dt then (nth alpha_frees (body_index dt) $ arg $ arg2)
+ − 495
else (HOLogic.mk_eq (arg, arg2))
1472
+ − 496
| (_, [], [], []) => @{term True}
+ − 497
| ([], [], [], _) => @{term True}
+ − 498
| ([], ((((SOME (bn, is_rec)), _, _), pi) :: _), [], []) =>
1462
+ − 499
if not (bns_same rel_in_comp_binds) then error "incompatible bindings for an argument" else
+ − 500
if is_rec then
+ − 501
let
+ − 502
val (rbinds, rpis) = split_list rel_in_comp_binds
1468
+ − 503
val bound_in_nos = map (fn (_, _, i) => i) rbinds
+ − 504
val bound_in_ty_nos = map (fn i => body_index (nth dts i)) bound_in_nos;
+ − 505
val bound_args = arg :: map (nth args) bound_in_nos;
+ − 506
val bound_args2 = arg2 :: map (nth args2) bound_in_nos;
+ − 507
fun bound_in args (_, _, i) = nth args i;
1462
+ − 508
val lhs_binds = fv_binds args rbinds
1468
+ − 509
val lhs_arg = foldr1 HOLogic.mk_prod bound_args
+ − 510
val lhs = mk_pair (lhs_binds, lhs_arg);
1462
+ − 511
val rhs_binds = fv_binds args2 rbinds;
1468
+ − 512
val rhs_arg = foldr1 HOLogic.mk_prod bound_args2;
+ − 513
val rhs = mk_pair (rhs_binds, rhs_arg);
+ − 514
val fvs = map (nth fv_frees) ((body_index dt) :: bound_in_ty_nos);
+ − 515
val fv = mk_compound_fv fvs;
+ − 516
val alphas = map (nth alpha_frees) ((body_index dt) :: bound_in_ty_nos);
+ − 517
val alpha = mk_compound_alpha alphas;
1462
+ − 518
val pi = foldr1 add_perm (distinct (op =) rpis);
+ − 519
val alpha_gen_pre = Const (@{const_name alpha_gen}, dummyT) $ lhs $ alpha $ fv $ pi $ rhs;
+ − 520
val alpha_gen = Syntax.check_term lthy alpha_gen_pre
+ − 521
in
+ − 522
alpha_gen
+ − 523
end
+ − 524
else
+ − 525
let
+ − 526
val alpha_bn_const =
+ − 527
nth alpha_bn_frees (find_index (fn (b, _, _) => b = bn) bns)
+ − 528
in
+ − 529
alpha_bn_const $ arg $ arg2
+ − 530
end
1472
+ − 531
| ([], [], relevant, []) =>
1383
+ − 532
let
1288
+ − 533
val (rbinds, rpis) = split_list relevant
+ − 534
val lhs_binds = fv_binds args rbinds
+ − 535
val lhs = mk_pair (lhs_binds, arg);
+ − 536
val rhs_binds = fv_binds args2 rbinds;
+ − 537
val rhs = mk_pair (rhs_binds, arg2);
+ − 538
val alpha = nth alpha_frees (body_index dt);
+ − 539
val fv = nth fv_frees (body_index dt);
1359
+ − 540
val pi = foldr1 add_perm (distinct (op =) rpis);
1288
+ − 541
val alpha_gen_pre = Const (@{const_name alpha_gen}, dummyT) $ lhs $ alpha $ fv $ pi $ rhs;
1325
+ − 542
val alpha_gen = Syntax.check_term lthy alpha_gen_pre
1288
+ − 543
in
1357
42b7abf779ec
Gather bindings with same binder, and generate only one permutation for them.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 544
alpha_gen
1383
+ − 545
end
1385
+ − 546
| _ => error "Fv.alpha: not supported binding structure"
1288
+ − 547
end
+ − 548
val alphas = map alpha_arg (dts ~~ arg_nos ~~ (args ~~ args2))
+ − 549
val alpha_lhss = mk_conjl alphas
+ − 550
val alpha_lhss_ex =
+ − 551
fold (fn pi_str => fn t => HOLogic.mk_exists (pi_str, @{typ perm}, t)) pi_strs alpha_lhss
+ − 552
val alpha_eq = Logic.mk_implies (HOLogic.mk_Trueprop alpha_lhss_ex, alpha_rhs)
1173
+ − 553
in
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 554
(fv_eq, alpha_eq)
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 555
end;
1302
+ − 556
fun fv_alpha_eq (i, (_, _, constrs)) binds = map2i (fv_alpha_constr i) constrs binds;
1376
+ − 557
val fveqs_alphaeqs = map2i fv_alpha_eq descr (gather_binds bindsall)
+ − 558
val (fv_eqs_perfv, alpha_eqs) = apsnd flat (split_list (map split_list fveqs_alphaeqs))
+ − 559
val rel_bns_nos = map (fn (_, i, _) => i) rel_bns;
1385
+ − 560
fun filter_fun (_, b) = b mem rel_bns_nos;
1376
+ − 561
val all_fvs = (fv_names ~~ fv_eqs_perfv) ~~ (0 upto (length fv_names - 1))
+ − 562
val (fv_names_fst, fv_eqs_fst) = apsnd flat (split_list (map fst (filter_out filter_fun all_fvs)))
+ − 563
val (fv_names_snd, fv_eqs_snd) = apsnd flat (split_list (map fst (filter filter_fun all_fvs)))
+ − 564
val fv_eqs_all = fv_eqs_fst @ (flat fv_bn_eqs);
+ − 565
val fv_names_all = fv_names_fst @ fv_bn_names;
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 566
val add_binds = map (fn x => (Attrib.empty_binding, x))
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 567
(* Function_Fun.add_fun Function_Common.default_config ... true *)
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 568
val (fvs, lthy') = (Primrec.add_primrec
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 569
(map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_all) (add_binds fv_eqs_all) lthy)
1376
+ − 570
val (fvs2, lthy'') =
+ − 571
if fv_eqs_snd = [] then (([], []), lthy') else
+ − 572
(Primrec.add_primrec
+ − 573
(map (fn s => (Binding.name s, NONE, NoSyn)) fv_names_snd) (add_binds fv_eqs_snd) lthy')
+ − 574
val (alphas, lthy''') = (Inductive.add_inductive_i
1325
+ − 575
{quiet_mode = true, verbose = false, alt_name = Binding.empty,
1193
a228acf2907e
Full alpha equivalence + testing in terms. Some differ but it seems the generated version is more correct.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 576
coind = false, no_elim = false, no_ind = false, skip_mono = true, fork_mono = false}
1389
+ − 577
(map2 (fn x => fn y => ((Binding.name x, y), NoSyn)) (alpha_names @ alpha_bn_names)
+ − 578
(alpha_types @ alpha_bn_types)) []
+ − 579
(add_binds (alpha_eqs @ flat alpha_bn_eqs)) [] lthy'')
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 580
val ordered_fvs = fv_frees @ fvbns;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 581
val exported_fvs = map (Morphism.term (ProofContext.export_morphism lthy''' lthy)) ordered_fvs;
1385
+ − 582
val all_fvs = (fst fvs @ fst fvs2, snd fvs @ snd fvs2)
1178
+ − 583
in
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 584
(((all_fvs, ordered_fvs), alphas), lthy''')
1178
+ − 585
end
1168
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 586
*}
5c1e16806901
Code for generating the fv function, no bindings yet.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff
changeset
+ − 587
1375
aa787c9b6955
A version of Fv that takes into account recursive and non-recursive bindings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 588
1196
+ − 589
1207
+ − 590
ML {*
1559
+ − 591
fun build_alpha_sym_trans_gl alphas (x, y, z) =
1207
+ − 592
let
+ − 593
fun build_alpha alpha =
+ − 594
let
+ − 595
val ty = domain_type (fastype_of alpha);
1214
+ − 596
val var = Free(x, ty);
+ − 597
val var2 = Free(y, ty);
+ − 598
val var3 = Free(z, ty);
1209
+ − 599
val symp = HOLogic.mk_imp (alpha $ var $ var2, alpha $ var2 $ var);
+ − 600
val transp = HOLogic.mk_imp (alpha $ var $ var2,
1214
+ − 601
HOLogic.mk_all (z, ty,
1209
+ − 602
HOLogic.mk_imp (alpha $ var2 $ var3, alpha $ var $ var3)))
1207
+ − 603
in
1559
+ − 604
(symp, transp)
1208
+ − 605
end;
1559
+ − 606
val eqs = map build_alpha alphas
1209
+ − 607
val (sym_eqs, trans_eqs) = split_list eqs
+ − 608
fun conj l = @{term Trueprop} $ foldr1 HOLogic.mk_conj l
1207
+ − 609
in
1559
+ − 610
(conj sym_eqs, conj trans_eqs)
1196
+ − 611
end
1207
+ − 612
*}
+ − 613
1213
+ − 614
ML {*
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 615
fun build_alpha_refl_gl fv_alphas_lst alphas =
1559
+ − 616
let
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 617
val (fvs_alphas, _) = split_list fv_alphas_lst;
1559
+ − 618
val (_, alpha_ts) = split_list fvs_alphas;
+ − 619
val tys = map (domain_type o fastype_of) alpha_ts;
+ − 620
val names = Datatype_Prop.make_tnames tys;
+ − 621
val args = map Free (names ~~ tys);
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 622
fun find_alphas ty x =
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 623
domain_type (fastype_of x) = ty;
1559
+ − 624
fun mk_alpha_refl arg (_, alpha) = alpha $ arg $ arg;
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 625
fun refl_eq_arg (ty, arg) =
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 626
let
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 627
val rel_alphas = filter (find_alphas ty) alphas;
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 628
in
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 629
map (fn x => x $ arg $ arg) rel_alphas
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 630
end;
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 631
(* Flattening loses the induction structure *)
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 632
val eqs = map (foldr1 HOLogic.mk_conj) (map refl_eq_arg (tys ~~ args))
1559
+ − 633
in
+ − 634
(names, HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj eqs))
+ − 635
end
+ − 636
*}
+ − 637
+ − 638
ML {*
+ − 639
fun reflp_tac induct eq_iff ctxt =
1213
+ − 640
rtac induct THEN_ALL_NEW
1656
+ − 641
simp_tac (HOL_basic_ss addsimps eq_iff) THEN_ALL_NEW
1653
+ − 642
split_conj_tac THEN_ALL_NEW REPEAT o rtac @{thm exI[of _ "0 :: perm"]}
+ − 643
THEN_ALL_NEW split_conj_tac THEN_ALL_NEW asm_full_simp_tac (HOL_ss addsimps
1333
+ − 644
@{thms alpha_gen fresh_star_def fresh_zero_perm permute_zero ball_triv
1482
+ − 645
add_0_left supp_zero_perm Int_empty_left split_conv})
1213
+ − 646
*}
+ − 647
1559
+ − 648
ML {*
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 649
fun build_alpha_refl fv_alphas_lst alphas induct eq_iff ctxt =
1559
+ − 650
let
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 651
val (names, gl) = build_alpha_refl_gl fv_alphas_lst alphas;
1559
+ − 652
val refl_conj = Goal.prove ctxt names [] gl (fn _ => reflp_tac induct eq_iff ctxt 1);
+ − 653
in
+ − 654
HOLogic.conj_elims refl_conj
+ − 655
end
+ − 656
*}
1333
+ − 657
1301
+ − 658
lemma exi_neg: "\<exists>(pi :: perm). P pi \<Longrightarrow> (\<And>(p :: perm). P p \<Longrightarrow> Q (- p)) \<Longrightarrow> \<exists>pi. Q pi"
+ − 659
apply (erule exE)
+ − 660
apply (rule_tac x="-pi" in exI)
+ − 661
by auto
+ − 662
1213
+ − 663
ML {*
1334
+ − 664
fun symp_tac induct inj eqvt ctxt =
1653
+ − 665
rel_indtac induct THEN_ALL_NEW
1656
+ − 666
simp_tac (HOL_basic_ss addsimps inj) THEN_ALL_NEW split_conj_tac
1334
+ − 667
THEN_ALL_NEW
+ − 668
REPEAT o etac @{thm exi_neg}
+ − 669
THEN_ALL_NEW
1653
+ − 670
split_conj_tac THEN_ALL_NEW
1334
+ − 671
asm_full_simp_tac (HOL_ss addsimps @{thms supp_minus_perm minus_add[symmetric]}) THEN_ALL_NEW
1487
+ − 672
TRY o (rtac @{thm alpha_gen_compose_sym2} ORELSE' rtac @{thm alpha_gen_compose_sym}) THEN_ALL_NEW
+ − 673
(asm_full_simp_tac (HOL_ss addsimps (eqvt @ all_eqvts ctxt)))
1213
+ − 674
*}
+ − 675
1301
+ − 676
+ − 677
lemma exi_sum: "\<exists>(pi :: perm). P pi \<Longrightarrow> \<exists>(pi :: perm). Q pi \<Longrightarrow> (\<And>(p :: perm) (pi :: perm). P p \<Longrightarrow> Q pi \<Longrightarrow> R (pi + p)) \<Longrightarrow> \<exists>pi. R pi"
+ − 678
apply (erule exE)+
+ − 679
apply (rule_tac x="pia + pi" in exI)
+ − 680
by auto
+ − 681
1339
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 682
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 683
ML {*
1656
+ − 684
fun eetac rule =
+ − 685
Subgoal.FOCUS_PARAMS (fn focus =>
+ − 686
let
+ − 687
val concl = #concl focus
+ − 688
val prems = Logic.strip_imp_prems (term_of concl)
+ − 689
val exs = filter (fn x => is_ex (HOLogic.dest_Trueprop x)) prems
+ − 690
val cexs = map (SOME o (cterm_of (ProofContext.theory_of (#context focus)))) exs
+ − 691
val thins = map (fn cex => Drule.instantiate' [] [cex] Drule.thin_rl) cexs
+ − 692
in
+ − 693
(etac rule THEN' RANGE[atac, eresolve_tac thins]) 1
+ − 694
end
1339
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 695
)
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 696
*}
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 697
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 698
ML {*
1217
+ − 699
fun transp_tac ctxt induct alpha_inj term_inj distinct cases eqvt =
1653
+ − 700
rel_indtac induct THEN_ALL_NEW
1217
+ − 701
(TRY o rtac allI THEN' imp_elim_tac cases ctxt) THEN_ALL_NEW
1656
+ − 702
asm_full_simp_tac (HOL_basic_ss addsimps alpha_inj) THEN_ALL_NEW
1653
+ − 703
split_conj_tac THEN_ALL_NEW REPEAT o (eetac @{thm exi_sum} ctxt) THEN_ALL_NEW split_conj_tac
1339
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 704
THEN_ALL_NEW (asm_full_simp_tac (HOL_ss addsimps (term_inj @ distinct)))
1653
+ − 705
THEN_ALL_NEW split_conj_tac THEN_ALL_NEW
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 706
TRY o (etac @{thm alpha_gen_compose_trans2} ORELSE' etac @{thm alpha_gen_compose_trans}) THEN_ALL_NEW
1339
5256f256edd8
Comment out Weird and Phd until we have an idea how to handle multiple permutations. Transp that works for multiple existentials.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 707
(asm_full_simp_tac (HOL_ss addsimps (all_eqvts ctxt @ eqvt @ term_inj @ distinct)))
1213
+ − 708
*}
+ − 709
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 710
lemma transpI:
1215
+ − 711
"(\<And>xa ya. R xa ya \<longrightarrow> (\<forall>z. R ya z \<longrightarrow> R xa z)) \<Longrightarrow> transp R"
+ − 712
unfolding transp_def
+ − 713
by blast
+ − 714
+ − 715
ML {*
+ − 716
fun equivp_tac reflps symps transps =
1609
c9bc3b61046c
Modification to Core Haskell to make it accepted with an empty binding function.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 717
(*let val _ = tracing (PolyML.makestring (reflps, symps, transps)) in *)
1215
+ − 718
simp_tac (HOL_ss addsimps @{thms equivp_reflp_symp_transp reflp_def symp_def})
1221
+ − 719
THEN' rtac conjI THEN' rtac allI THEN'
1215
+ − 720
resolve_tac reflps THEN'
1221
+ − 721
rtac conjI THEN' rtac allI THEN' rtac allI THEN'
1215
+ − 722
resolve_tac symps THEN'
1581
6b1eea8dcdc0
equivp_cheat can be removed for all one-permutation examples.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 723
rtac @{thm transpI} THEN' resolve_tac transps
1215
+ − 724
*}
+ − 725
1213
+ − 726
ML {*
1559
+ − 727
fun build_equivps alphas reflps alpha_induct term_inj alpha_inj distinct cases eqvt ctxt =
1213
+ − 728
let
1214
+ − 729
val ([x, y, z], ctxt') = Variable.variant_fixes ["x","y","z"] ctxt;
1559
+ − 730
val (symg, transg) = build_alpha_sym_trans_gl alphas (x, y, z)
1334
+ − 731
fun symp_tac' _ = symp_tac alpha_induct alpha_inj eqvt ctxt 1;
1217
+ − 732
fun transp_tac' _ = transp_tac ctxt alpha_induct alpha_inj term_inj distinct cases eqvt 1;
1559
+ − 733
val symp_loc = Goal.prove ctxt' [] [] symg symp_tac';
+ − 734
val transp_loc = Goal.prove ctxt' [] [] transg transp_tac';
+ − 735
val [symp, transp] = Variable.export ctxt' ctxt [symp_loc, transp_loc]
+ − 736
val symps = HOLogic.conj_elims symp
+ − 737
val transps = HOLogic.conj_elims transp
1214
+ − 738
fun equivp alpha =
+ − 739
let
1215
+ − 740
val equivp = Const (@{const_name equivp}, fastype_of alpha --> @{typ bool})
+ − 741
val goal = @{term Trueprop} $ (equivp $ alpha)
1559
+ − 742
fun tac _ = equivp_tac reflps symps transps 1
1215
+ − 743
in
+ − 744
Goal.prove ctxt [] [] goal tac
+ − 745
end
1213
+ − 746
in
1215
+ − 747
map equivp alphas
1213
+ − 748
end
+ − 749
*}
1207
+ − 750
1427
+ − 751
lemma not_in_union: "c \<notin> a \<union> b \<equiv> (c \<notin> a \<and> c \<notin> b)"
+ − 752
by auto
+ − 753
+ − 754
ML {*
+ − 755
fun supports_tac perm =
+ − 756
simp_tac (HOL_ss addsimps @{thms supports_def not_in_union} @ perm) THEN_ALL_NEW (
1653
+ − 757
REPEAT o rtac allI THEN' REPEAT o rtac impI THEN' split_conj_tac THEN'
1427
+ − 758
asm_full_simp_tac (HOL_ss addsimps @{thms fresh_def[symmetric]
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 759
swap_fresh_fresh fresh_atom swap_at_base_simps(3) swap_atom_image_fresh
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 760
supp_fset_to_set supp_fmap_atom}))
1427
+ − 761
*}
+ − 762
+ − 763
ML {*
1428
+ − 764
fun mk_supp ty x =
+ − 765
Const (@{const_name supp}, ty --> @{typ "atom set"}) $ x
+ − 766
*}
+ − 767
+ − 768
ML {*
+ − 769
fun mk_supports_eq thy cnstr =
1427
+ − 770
let
+ − 771
val (tys, ty) = (strip_type o fastype_of) cnstr
+ − 772
val names = Datatype_Prop.make_tnames tys
+ − 773
val frees = map Free (names ~~ tys)
+ − 774
val rhs = list_comb (cnstr, frees)
1428
+ − 775
1427
+ − 776
fun mk_supp_arg (x, ty) =
1428
+ − 777
if is_atom thy ty then mk_supp @{typ atom} (mk_atom ty $ x) else
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 778
if is_atom_set thy ty then mk_supp @{typ "atom set"} (mk_atom_set x) else
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 779
if is_atom_fset thy ty then mk_supp @{typ "atom set"} (mk_atom_fset x)
1427
+ − 780
else mk_supp ty x
+ − 781
val lhss = map mk_supp_arg (frees ~~ tys)
+ − 782
val supports = Const(@{const_name "supports"}, @{typ "atom set"} --> ty --> @{typ bool})
+ − 783
val eq = HOLogic.mk_Trueprop (supports $ mk_union lhss $ rhs)
+ − 784
in
+ − 785
(names, eq)
1422
+ − 786
end
1427
+ − 787
*}
+ − 788
1428
+ − 789
ML {*
+ − 790
fun prove_supports ctxt perms cnst =
+ − 791
let
+ − 792
val (names, eq) = mk_supports_eq (ProofContext.theory_of ctxt) cnst
+ − 793
in
+ − 794
Goal.prove ctxt names [] eq (fn _ => supports_tac perms 1)
1427
+ − 795
end
1428
+ − 796
*}
+ − 797
+ − 798
ML {*
+ − 799
fun mk_fs tys =
+ − 800
let
+ − 801
val names = Datatype_Prop.make_tnames tys
+ − 802
val frees = map Free (names ~~ tys)
+ − 803
val supps = map2 mk_supp tys frees
+ − 804
val fin_supps = map (fn x => @{term "finite :: atom set \<Rightarrow> bool"} $ x) supps
+ − 805
in
+ − 806
(names, HOLogic.mk_Trueprop (mk_conjl fin_supps))
+ − 807
end
+ − 808
*}
+ − 809
+ − 810
ML {*
1653
+ − 811
fun fs_tac induct supports = rel_indtac induct THEN_ALL_NEW (
1428
+ − 812
rtac @{thm supports_finite} THEN' resolve_tac supports) THEN_ALL_NEW
1534
984ea1299cd7
The nominal infrastructure for fset. 'fs' missing, but not needed so far.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 813
asm_full_simp_tac (HOL_ss addsimps @{thms supp_atom supp_atom_image supp_fset_to_set
1547
57f7af5d7564
Use fs typeclass in showing finite support + some cheat cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 814
supp_fmap_atom finite_insert finite.emptyI finite_Un finite_supp})
1428
+ − 815
*}
+ − 816
+ − 817
ML {*
+ − 818
fun prove_fs ctxt induct supports tys =
+ − 819
let
+ − 820
val (names, eq) = mk_fs tys
+ − 821
in
+ − 822
Goal.prove ctxt names [] eq (fn _ => fs_tac induct supports 1)
+ − 823
end
+ − 824
*}
+ − 825
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 826
ML {*
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 827
fun mk_supp x = Const (@{const_name supp}, fastype_of x --> @{typ "atom set"}) $ x;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 828
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 829
fun mk_supp_neq arg (fv, alpha) =
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 830
let
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 831
val collect = Const ("Collect", @{typ "(atom \<Rightarrow> bool) \<Rightarrow> atom \<Rightarrow> bool"});
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 832
val ty = fastype_of arg;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 833
val perm = Const ("Nominal2_Base.pt_class.permute", @{typ perm} --> ty --> ty);
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 834
val finite = @{term "finite :: atom set \<Rightarrow> bool"}
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 835
val rhs = collect $ Abs ("a", @{typ atom},
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 836
HOLogic.mk_not (finite $
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 837
(collect $ Abs ("b", @{typ atom},
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 838
HOLogic.mk_not (alpha $ (perm $ (@{term swap} $ Bound 1 $ Bound 0) $ arg) $ arg)))))
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 839
in
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 840
HOLogic.mk_eq (fv $ arg, rhs)
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 841
end;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 842
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 843
fun supp_eq fv_alphas_lst =
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 844
let
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 845
val (fvs_alphas, ls) = split_list fv_alphas_lst;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 846
val (fv_ts, _) = split_list fvs_alphas;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 847
val tys = map (domain_type o fastype_of) fv_ts;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 848
val names = Datatype_Prop.make_tnames tys;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 849
val args = map Free (names ~~ tys);
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 850
fun supp_eq_arg ((fv, arg), l) =
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 851
mk_conjl
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 852
((HOLogic.mk_eq (fv $ arg, mk_supp arg)) ::
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 853
(map (mk_supp_neq arg) l))
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 854
val eqs = mk_conjl (map supp_eq_arg ((fv_ts ~~ args) ~~ ls))
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 855
in
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 856
(names, HOLogic.mk_Trueprop eqs)
1428
+ − 857
end
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 858
*}
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 859
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 860
ML {*
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 861
fun combine_fv_alpha_bns (fv_ts_nobn, fv_ts_bn) (alpha_ts_nobn, alpha_ts_bn) bn_nos =
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 862
if length fv_ts_bn < length alpha_ts_bn then
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 863
(fv_ts_nobn ~~ alpha_ts_nobn) ~~ (replicate (length fv_ts_nobn) [])
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 864
else let
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 865
val fv_alpha_nos = 0 upto (length fv_ts_nobn - 1);
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 866
fun filter_fn i (x, j) = if j = i then SOME x else NONE;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 867
val fv_alpha_bn_nos = (fv_ts_bn ~~ alpha_ts_bn) ~~ bn_nos;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 868
val fv_alpha_bn_all = map (fn i => map_filter (filter_fn i) fv_alpha_bn_nos) fv_alpha_nos;
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 869
in
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 870
(fv_ts_nobn ~~ alpha_ts_nobn) ~~ fv_alpha_bn_all
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 871
end
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 872
*}
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 873
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 874
lemma supp_abs_sum: "supp (Abs x (a :: 'a :: fs)) \<union> supp (Abs x (b :: 'b :: fs)) = supp (Abs x (a, b))"
1658
+ − 875
apply (simp add: supp_abs supp_Pair)
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 876
apply blast
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 877
done
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 878
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 879
ML {*
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 880
fun supp_eq_tac ind fv perm eqiff ctxt =
1653
+ − 881
rel_indtac ind THEN_ALL_NEW
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 882
asm_full_simp_tac (HOL_basic_ss addsimps fv) THEN_ALL_NEW
1658
+ − 883
asm_full_simp_tac (HOL_basic_ss addsimps @{thms supp_abs[symmetric]}) THEN_ALL_NEW
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 884
simp_tac (HOL_basic_ss addsimps @{thms supp_abs_sum}) THEN_ALL_NEW
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 885
simp_tac (HOL_basic_ss addsimps @{thms supp_def}) THEN_ALL_NEW
1658
+ − 886
simp_tac (HOL_basic_ss addsimps (@{thm permute_Abs} :: perm)) THEN_ALL_NEW
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 887
simp_tac (HOL_basic_ss addsimps (@{thm Abs_eq_iff} :: eqiff)) THEN_ALL_NEW
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 888
simp_tac (HOL_basic_ss addsimps @{thms alpha_gen2}) THEN_ALL_NEW
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 889
simp_tac (HOL_basic_ss addsimps @{thms alpha_gen}) THEN_ALL_NEW
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 890
asm_full_simp_tac (HOL_basic_ss addsimps (@{thm supp_Pair} :: sym_eqvts ctxt)) THEN_ALL_NEW
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 891
asm_full_simp_tac (HOL_basic_ss addsimps (@{thm Pair_eq} :: all_eqvts ctxt)) THEN_ALL_NEW
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 892
simp_tac (HOL_basic_ss addsimps @{thms supp_at_base[symmetric,simplified supp_def]}) THEN_ALL_NEW
1625
+ − 893
simp_tac (HOL_basic_ss addsimps @{thms Collect_disj_eq[symmetric]}) THEN_ALL_NEW
+ − 894
simp_tac (HOL_basic_ss addsimps @{thms infinite_Un[symmetric]}) THEN_ALL_NEW
+ − 895
simp_tac (HOL_basic_ss addsimps @{thms Collect_disj_eq[symmetric]}) THEN_ALL_NEW
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 896
simp_tac (HOL_basic_ss addsimps @{thms de_Morgan_conj[symmetric]}) THEN_ALL_NEW
1625
+ − 897
simp_tac (HOL_basic_ss addsimps @{thms ex_simps(1,2)[symmetric]}) THEN_ALL_NEW
1553
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 898
simp_tac (HOL_ss addsimps @{thms Collect_const finite.emptyI})
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 899
*}
4355eb3b7161
Automatically derive support for datatypes with at-most one binding per constructor.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 900
1653
+ − 901
1650
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 902
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 903
ML {*
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 904
fun build_eqvt_gl pi frees fnctn ctxt =
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 905
let
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 906
val typ = domain_type (fastype_of fnctn);
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 907
val arg = the (AList.lookup (op=) frees typ);
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 908
in
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 909
([HOLogic.mk_eq ((perm_at $ pi $ (fnctn $ arg)), (fnctn $ (perm_arg arg $ pi $ arg)))], ctxt)
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 910
end
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 911
*}
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 912
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 913
ML {*
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 914
fun prove_eqvt tys ind simps funs ctxt =
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 915
let
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 916
val ([pi], ctxt') = Variable.variant_fixes ["p"] ctxt;
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 917
val pi = Free (pi, @{typ perm});
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 918
val tac = asm_full_simp_tac (HOL_ss addsimps (@{thm atom_eqvt} :: simps @ all_eqvts ctxt'))
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 919
val ths_loc = prove_by_induct tys (build_eqvt_gl pi) ind tac funs ctxt'
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 920
val ths = Variable.export ctxt' ctxt ths_loc
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 921
val add_eqvt = Attrib.internal (fn _ => Nominal_ThmDecls.eqvt_add)
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 922
in
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 923
(ths, snd (Local_Theory.note ((Binding.empty, [add_eqvt]), ths) ctxt))
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 924
end
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 925
*}
4b949985cf57
Gathering things to prove by induction together; removed cheat_bn_eqvt.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
+ − 926
1651
+ − 927
end