1960
|
1 |
theory NewFv
|
1981
|
2 |
imports "../Nominal-General/Nominal2_Atoms"
|
|
3 |
"Abs" "Perm" "Nominal2_FSet"
|
1960
|
4 |
begin
|
|
5 |
|
|
6 |
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>
diff
changeset
|
7 |
(* binding modes and binding clauses *)
|
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
8 |
|
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>
diff
changeset
|
9 |
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>
diff
changeset
|
10 |
|
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>
diff
changeset
|
11 |
datatype bclause =
|
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>
diff
changeset
|
12 |
BC of bmode * (term option * int) list * int list
|
1960
|
13 |
*}
|
|
14 |
|
|
15 |
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>
diff
changeset
|
16 |
fun mk_diff (@{term "{}::atom set"}, _) = @{term "{}::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>
diff
changeset
|
17 |
| mk_diff (t1, @{term "{}::atom set"}) = t1
|
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>
diff
changeset
|
18 |
| mk_diff (t1, t2) = HOLogic.mk_binop @{const_name minus} (t1, t2)
|
1963
|
19 |
|
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>
diff
changeset
|
20 |
fun mk_union (@{term "{}::atom set"}, @{term "{}::atom set"}) = @{term "{}::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>
diff
changeset
|
21 |
| mk_union (t1 , @{term "{}::atom set"}) = t1
|
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>
diff
changeset
|
22 |
| mk_union (@{term "{}::atom set"}, t2) = t2
|
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>
diff
changeset
|
23 |
| mk_union (t1, t2) = HOLogic.mk_binop @{const_name sup} (t1, t2)
|
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>
diff
changeset
|
24 |
|
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>
diff
changeset
|
25 |
fun fold_union trms = fold (curry mk_union) trms @{term "{}::atom set"}
|
1960
|
26 |
*}
|
|
27 |
|
|
28 |
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>
diff
changeset
|
29 |
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>
diff
changeset
|
30 |
Sign.of_sort (ProofContext.theory_of ctxt) (ty, @{sort at_base})
|
1960
|
31 |
|
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>
diff
changeset
|
32 |
fun is_atom_set ctxt (Type ("fun", [t, @{typ bool}])) = is_atom ctxt t
|
1960
|
33 |
| is_atom_set _ _ = false;
|
|
34 |
|
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>
diff
changeset
|
35 |
fun is_atom_fset ctxt (Type (@{type_name "fset"}, [t])) = is_atom ctxt t
|
1960
|
36 |
| is_atom_fset _ _ = false;
|
|
37 |
|
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>
diff
changeset
|
38 |
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>
diff
changeset
|
39 |
| 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>
diff
changeset
|
40 |
*}
|
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>
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>
diff
changeset
|
42 |
ML {*
|
1960
|
43 |
fun mk_atom_set t =
|
|
44 |
let
|
|
45 |
val ty = fastype_of t;
|
|
46 |
val atom_ty = HOLogic.dest_setT ty --> @{typ atom};
|
|
47 |
val img_ty = atom_ty --> ty --> @{typ "atom set"};
|
|
48 |
in
|
1963
|
49 |
(Const (@{const_name image}, img_ty) $ mk_atom_ty atom_ty t)
|
1960
|
50 |
end;
|
|
51 |
|
|
52 |
fun mk_atom_fset t =
|
|
53 |
let
|
|
54 |
val ty = fastype_of t;
|
|
55 |
val atom_ty = dest_fsetT ty --> @{typ atom};
|
|
56 |
val fmap_ty = atom_ty --> ty --> @{typ "atom fset"};
|
|
57 |
val fset_to_set = @{term "fset_to_set :: atom fset \<Rightarrow> atom set"}
|
|
58 |
in
|
1984
|
59 |
fset_to_set $ (Const (@{const_name fmap}, fmap_ty) $ Const (@{const_name atom}, atom_ty) $ t)
|
1960
|
60 |
end;
|
|
61 |
|
1989
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
62 |
fun mk_atom_list t =
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
63 |
let
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
64 |
val ty = fastype_of t;
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
65 |
val atom_ty = dest_listT ty --> @{typ atom};
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
66 |
val map_ty = atom_ty --> ty --> @{typ "atom list"};
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
67 |
in
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
68 |
(Const (@{const_name map}, map_ty) $ mk_atom_ty atom_ty t)
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
69 |
end;
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
70 |
*}
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
71 |
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
72 |
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>
diff
changeset
|
73 |
fun setify ctxt t =
|
1960
|
74 |
let
|
1963
|
75 |
val ty = fastype_of t;
|
1960
|
76 |
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>
diff
changeset
|
77 |
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>
diff
changeset
|
78 |
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>
diff
changeset
|
79 |
else if is_atom_set ctxt ty
|
1983
4538d63ecc9b
Support in positive position and atoms in negative positions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
80 |
then mk_atom_set 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>
diff
changeset
|
81 |
else if is_atom_fset ctxt ty
|
1983
4538d63ecc9b
Support in positive position and atoms in negative positions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
82 |
then mk_atom_fset t
|
1989
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
83 |
else error ("setify" ^ (PolyML.makestring (t, ty)))
|
1960
|
84 |
end
|
|
85 |
*}
|
|
86 |
|
|
87 |
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>
diff
changeset
|
88 |
fun listify ctxt t =
|
1989
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
89 |
let
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
90 |
val ty = fastype_of t;
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
91 |
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>
diff
changeset
|
92 |
if is_atom ctxt ty
|
1989
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
93 |
then HOLogic.mk_list @{typ atom} [mk_atom 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>
diff
changeset
|
94 |
else if is_atom_list ctxt ty
|
1989
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
95 |
then mk_atom_set t
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
96 |
else error "listify"
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
97 |
end
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
98 |
*}
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
99 |
|
45721f92e471
Unify and give only one name to 'setify', 'listify' and 'set'
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
100 |
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>
diff
changeset
|
101 |
fun to_set x =
|
1983
4538d63ecc9b
Support in positive position and atoms in negative positions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
102 |
if fastype_of x = @{typ "atom list"}
|
4538d63ecc9b
Support in positive position and atoms in negative positions.
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
103 |
then @{term "set::atom list \<Rightarrow> atom set"} $ x
|
1969
|
104 |
else x
|
1960
|
105 |
*}
|
|
106 |
|
|
107 |
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>
diff
changeset
|
108 |
fun make_body fv_map args i =
|
1986
|
109 |
let
|
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>
diff
changeset
|
110 |
val arg = nth args i
|
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>
diff
changeset
|
111 |
val ty = fastype_of arg
|
1986
|
112 |
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>
diff
changeset
|
113 |
case (AList.lookup (op=) fv_map ty) of
|
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>
diff
changeset
|
114 |
NONE => mk_supp arg
|
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>
diff
changeset
|
115 |
| SOME fv => fv $ arg
|
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>
diff
changeset
|
116 |
end
|
1986
|
117 |
*}
|
|
118 |
|
|
119 |
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>
diff
changeset
|
120 |
fun make_binder lthy fv_bn_map args (bn_option, i) =
|
1960
|
121 |
let
|
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>
diff
changeset
|
122 |
val arg = nth args i
|
1960
|
123 |
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>
diff
changeset
|
124 |
case bn_option of
|
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>
diff
changeset
|
125 |
NONE => (setify lthy arg, @{term "{}::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>
diff
changeset
|
126 |
| SOME bn => (to_set (bn $ arg), the (AList.lookup (op=) fv_bn_map bn) $ arg)
|
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>
diff
changeset
|
127 |
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>
diff
changeset
|
128 |
*}
|
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>
diff
changeset
|
129 |
|
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>
diff
changeset
|
130 |
ML {*
|
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>
diff
changeset
|
131 |
fun make_fv_rhs lthy fv_map fv_bn_map args (BC (_, binders, bodies)) =
|
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>
diff
changeset
|
132 |
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>
diff
changeset
|
133 |
val t1 = map (make_body fv_map args) bodies
|
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>
diff
changeset
|
134 |
val (t2, t3) = split_list (map (make_binder lthy fv_bn_map args) binders)
|
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>
diff
changeset
|
135 |
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>
diff
changeset
|
136 |
fold_union (mk_diff (fold_union t1, fold_union t2)::t3)
|
1960
|
137 |
end
|
|
138 |
*}
|
|
139 |
|
|
140 |
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>
diff
changeset
|
141 |
fun make_fv_eq lthy fv_map fv_bn_map (constr, ty, arg_tys) bclauses =
|
1960
|
142 |
let
|
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>
diff
changeset
|
143 |
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>
diff
changeset
|
144 |
val args = map Free (arg_names ~~ arg_tys)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
145 |
val fv = the (AList.lookup (op=) fv_map 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>
diff
changeset
|
146 |
val lhs = fv $ list_comb (constr, args)
|
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>
diff
changeset
|
147 |
val rhs_trms = map (make_fv_rhs lthy fv_map fv_bn_map args) bclauses
|
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>
diff
changeset
|
148 |
val rhs = fold_union rhs_trms
|
1960
|
149 |
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>
diff
changeset
|
150 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
1960
|
151 |
end
|
|
152 |
*}
|
|
153 |
|
|
154 |
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>
diff
changeset
|
155 |
fun make_bn_body fv_map fv_bn_map bn_args args i =
|
1960
|
156 |
let
|
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>
diff
changeset
|
157 |
val arg = nth args i
|
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>
diff
changeset
|
158 |
val ty = fastype_of arg
|
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>
diff
changeset
|
159 |
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>
diff
changeset
|
160 |
case AList.lookup (op=) bn_args i of
|
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>
diff
changeset
|
161 |
NONE => (case (AList.lookup (op=) fv_map ty) of
|
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>
diff
changeset
|
162 |
NONE => mk_supp arg
|
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>
diff
changeset
|
163 |
| SOME fv => fv $ arg)
|
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>
diff
changeset
|
164 |
| SOME (NONE) => @{term "{}::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>
diff
changeset
|
165 |
| SOME (SOME bn) => the (AList.lookup (op=) fv_bn_map bn) $ arg
|
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>
diff
changeset
|
166 |
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>
diff
changeset
|
167 |
*}
|
2146
|
168 |
|
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>
diff
changeset
|
169 |
ML {*
|
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>
diff
changeset
|
170 |
fun make_fv_bn_rhs lthy fv_map fv_bn_map bn_args args bclause =
|
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>
diff
changeset
|
171 |
case bclause of
|
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>
diff
changeset
|
172 |
BC (_, [], bodies) => fold_union (map (make_bn_body fv_map fv_bn_map bn_args args) bodies)
|
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>
diff
changeset
|
173 |
| BC (_, binders, bodies) =>
|
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>
diff
changeset
|
174 |
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>
diff
changeset
|
175 |
val t1 = map (make_body fv_map args) bodies
|
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>
diff
changeset
|
176 |
val (t2, t3) = split_list (map (make_binder lthy fv_bn_map args) binders)
|
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>
diff
changeset
|
177 |
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>
diff
changeset
|
178 |
fold_union (mk_diff (fold_union t1, fold_union t2)::t3)
|
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>
diff
changeset
|
179 |
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>
diff
changeset
|
180 |
*}
|
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>
diff
changeset
|
181 |
|
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>
diff
changeset
|
182 |
ML {*
|
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>
diff
changeset
|
183 |
fun make_fv_bn_eq lthy bn_trm fv_map fv_bn_map (bn_args, (constr, ty, arg_tys)) bclauses =
|
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>
diff
changeset
|
184 |
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>
diff
changeset
|
185 |
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>
diff
changeset
|
186 |
val args = map Free (arg_names ~~ arg_tys)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
187 |
val fv_bn = the (AList.lookup (op=) fv_bn_map bn_trm)
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
188 |
val lhs = fv_bn $ list_comb (constr, args)
|
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>
diff
changeset
|
189 |
val rhs_trms = map (make_fv_bn_rhs lthy fv_map fv_bn_map bn_args args) bclauses
|
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>
diff
changeset
|
190 |
val rhs = fold_union rhs_trms
|
1960
|
191 |
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>
diff
changeset
|
192 |
HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs))
|
1960
|
193 |
end
|
|
194 |
*}
|
|
195 |
|
|
196 |
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>
diff
changeset
|
197 |
fun make_fv_bn_eqs lthy fv_map fv_bn_map constrs_info bclausesss (bn_trm, bn_n, bn_argss) =
|
1960
|
198 |
let
|
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>
diff
changeset
|
199 |
val nth_constrs_info = nth constrs_info bn_n
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
200 |
val nth_bclausess = nth bclausesss bn_n
|
1960
|
201 |
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>
diff
changeset
|
202 |
map2 (make_fv_bn_eq lthy bn_trm fv_map fv_bn_map) (bn_argss ~~ nth_constrs_info) nth_bclausess
|
1960
|
203 |
end
|
|
204 |
*}
|
1963
|
205 |
|
1960
|
206 |
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>
diff
changeset
|
207 |
fun define_raw_fvs dt_descr sorts bn_funs bn_funs2 bclausesss lthy =
|
1960
|
208 |
let
|
1965
4a3c05fe2bc5
closed Datatype_Aux; replaced nth_dtyp by the function used in Perm.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
209 |
|
1967
|
210 |
val fv_names = prefix_dt_names dt_descr sorts "fv_"
|
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>
diff
changeset
|
211 |
val fv_arg_tys = map (fn (i, _) => nth_dtyp dt_descr sorts i) dt_descr;
|
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>
diff
changeset
|
212 |
val fv_tys = map (fn ty => ty --> @{typ "atom set"}) fv_arg_tys;
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
213 |
val fv_frees = map Free (fv_names ~~ fv_tys);
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
214 |
val fv_map = fv_arg_tys ~~ fv_frees
|
1967
|
215 |
|
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>
diff
changeset
|
216 |
val (bns, bn_tys) = split_list (map (fn (bn, i, _) => (bn, i)) bn_funs)
|
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>
diff
changeset
|
217 |
val (bns2, bn_tys2) = split_list (map (fn (bn, i, _) => (bn, i)) bn_funs2)
|
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>
diff
changeset
|
218 |
val bn_args2 = map (fn (_, _, arg) => arg) bn_funs2
|
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>
diff
changeset
|
219 |
val fv_bn_names2 = map (fn bn => "fv_" ^ (fst (dest_Free bn))) bns2
|
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>
diff
changeset
|
220 |
val fv_bn_arg_tys2 = map (fn i => nth_dtyp dt_descr sorts i) bn_tys2
|
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>
diff
changeset
|
221 |
val fv_bn_tys2 = map (fn ty => ty --> @{typ "atom set"}) fv_bn_arg_tys2
|
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>
diff
changeset
|
222 |
val fv_bn_frees2 = map Free (fv_bn_names2 ~~ fv_bn_tys2)
|
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>
diff
changeset
|
223 |
val fv_bn_map2 = bns ~~ fv_bn_frees2
|
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>
diff
changeset
|
224 |
val fv_bn_map3 = bns2 ~~ fv_bn_frees2
|
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>
diff
changeset
|
225 |
|
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>
diff
changeset
|
226 |
val constrs_info = all_dtyp_constrs_types dt_descr sorts
|
1965
4a3c05fe2bc5
closed Datatype_Aux; replaced nth_dtyp by the function used in Perm.thy
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
227 |
|
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>
diff
changeset
|
228 |
val fv_eqs2 = map2 (map2 (make_fv_eq lthy fv_map fv_bn_map2)) constrs_info bclausesss
|
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>
diff
changeset
|
229 |
val fv_bn_eqs2 = map (make_fv_bn_eqs lthy fv_map fv_bn_map3 constrs_info bclausesss) bn_funs2
|
2046
73c50e913db6
tuned and added some comments to the code; added also an exception for early exit of the nominal2_cmd function
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
230 |
|
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>
diff
changeset
|
231 |
val all_fv_names = map (fn s => (Binding.name s, NONE, NoSyn)) (fv_names @ fv_bn_names2)
|
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>
diff
changeset
|
232 |
val all_fv_eqs = map (pair Attrib.empty_binding) (flat fv_eqs2 @ flat fv_bn_eqs2)
|
1981
|
233 |
|
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>
diff
changeset
|
234 |
fun pat_completeness_auto lthy =
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
235 |
Pat_Completeness.pat_completeness_tac lthy 1
|
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>
diff
changeset
|
236 |
THEN auto_tac (clasimpset_of lthy)
|
1981
|
237 |
|
|
238 |
fun prove_termination lthy =
|
|
239 |
Function.prove_termination NONE
|
|
240 |
(Lexicographic_Order.lexicographic_order_tac true lthy) lthy
|
|
241 |
|
2000
|
242 |
val (_, lthy') = Function.add_function all_fv_names all_fv_eqs
|
1981
|
243 |
Function_Common.default_config pat_completeness_auto lthy
|
|
244 |
|
2000
|
245 |
val (info, lthy'') = prove_termination (Local_Theory.restore lthy')
|
|
246 |
|
|
247 |
val {fs, simps, ...} = info;
|
1986
|
248 |
|
|
249 |
val morphism = ProofContext.export_morphism lthy'' lthy
|
2000
|
250 |
val fs_exp = map (Morphism.term morphism) fs
|
1986
|
251 |
|
2000
|
252 |
val (fv_frees_exp, fv_bns_exp) = chop (length fv_frees) fs_exp
|
|
253 |
val simps_exp = Morphism.fact morphism (the simps)
|
1960
|
254 |
in
|
2146
|
255 |
(fv_frees_exp, fv_bns_exp, simps_exp, lthy'')
|
1960
|
256 |
end
|
|
257 |
*}
|
|
258 |
|
2163
|
259 |
|
|
260 |
|
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>
diff
changeset
|
261 |
|
2163
|
262 |
|
|
263 |
end
|