1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
1 |
(* Title: nominal_library.ML
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Christian Urban
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
3 |
|
1979
|
4 |
Basic functions for nominal.
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
*)
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
signature NOMINAL_LIBRARY =
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
8 |
sig
|
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
9 |
val is_true: term -> bool
|
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
10 |
|
2313
|
11 |
val last2: 'a list -> 'a * 'a
|
|
12 |
|
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
|
13 |
val dest_listT: typ -> typ
|
3b83960f9544
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
|
14 |
|
2399
|
15 |
val size_const: typ -> term
|
|
16 |
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
17 |
val sum_case_const: typ -> typ -> typ -> term
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
18 |
val mk_sum_case: term -> term -> term
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
19 |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
val mk_minus: term -> term
|
1896
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
21 |
val mk_plus: term -> term -> term
|
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
22 |
|
1899
|
23 |
val perm_ty: typ -> typ
|
1871
|
24 |
val mk_perm_ty: typ -> term -> term -> term
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
val mk_perm: term -> term -> term
|
1834
|
26 |
val dest_perm: term -> term * term
|
|
27 |
|
1962
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
28 |
val mk_sort_of: term -> term
|
1979
|
29 |
val atom_ty: typ -> typ
|
1962
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
30 |
val mk_atom_ty: typ -> term -> term
|
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
31 |
val mk_atom: term -> term
|
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
32 |
|
1979
|
33 |
val supp_ty: typ -> typ
|
2296
|
34 |
val supp_const: typ -> term
|
1979
|
35 |
val mk_supp_ty: typ -> term -> term
|
|
36 |
val mk_supp: term -> term
|
|
37 |
|
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
38 |
val supp_rel_ty: typ -> typ
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
39 |
val supp_rel_const: typ -> term
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
40 |
val mk_supp_rel_ty: typ -> term -> term -> term
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
41 |
val mk_supp_rel: term -> term -> term
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
42 |
|
2448
|
43 |
val supports_const: typ -> term
|
|
44 |
val mk_supports_ty: typ -> term -> term -> term
|
|
45 |
val mk_supports: term -> term -> term
|
|
46 |
|
2450
|
47 |
val finite_const: typ -> term
|
|
48 |
val mk_finite_ty: typ -> term -> term
|
|
49 |
val mk_finite: term -> term
|
|
50 |
|
|
51 |
|
1834
|
52 |
val mk_equiv: thm -> thm
|
|
53 |
val safe_mk_equiv: thm -> thm
|
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
|
54 |
|
2289
|
55 |
val mk_diff: term * term -> term
|
2296
|
56 |
val mk_append: term * term -> term
|
2289
|
57 |
val mk_union: term * term -> term
|
|
58 |
val fold_union: term list -> term
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
59 |
val fold_append: term list -> term
|
2389
|
60 |
val mk_conj: term * term -> term
|
|
61 |
val fold_conj: term list -> term
|
2289
|
62 |
|
2448
|
63 |
(* fresh arguments for a term *)
|
|
64 |
val fresh_args: Proof.context -> term -> term list
|
|
65 |
|
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
|
66 |
(* datatype operations *)
|
2407
|
67 |
type cns_info = (term * typ * typ list * bool list) list
|
|
68 |
|
2296
|
69 |
val all_dtyps: Datatype_Aux.descr -> (string * sort) list -> typ list
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
70 |
val nth_dtyp: Datatype_Aux.descr -> (string * sort) list -> int -> typ
|
2407
|
71 |
val all_dtyp_constrs_types: Datatype_Aux.descr -> (string * sort) list -> cns_info list
|
|
72 |
val nth_dtyp_constrs_types: Datatype_Aux.descr -> (string * sort) list -> int -> cns_info
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
73 |
val prefix_dt_names: Datatype_Aux.descr -> (string * sort) list -> string -> string list
|
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
74 |
|
2304
|
75 |
(* tactics for function package *)
|
|
76 |
val pat_completeness_simp: thm list -> Proof.context -> tactic
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
77 |
val prove_termination: thm list -> Proof.context -> Function.info * local_theory
|
2304
|
78 |
|
2311
|
79 |
(* transformations of premises in inductions *)
|
|
80 |
val transform_prem1: Proof.context -> string list -> thm -> thm
|
|
81 |
val transform_prem2: Proof.context -> string list -> thm -> thm
|
2397
|
82 |
|
|
83 |
(* transformation into the object logic *)
|
|
84 |
val atomize: thm -> thm
|
2398
|
85 |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
end
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
structure Nominal_Library: NOMINAL_LIBRARY =
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
struct
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
|
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
92 |
fun is_true @{term "Trueprop True"} = true
|
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
93 |
| is_true _ = false
|
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
94 |
|
2313
|
95 |
fun last2 [] = raise Empty
|
|
96 |
| last2 [_] = raise Empty
|
2375
|
97 |
| last2 [x, y] = (x, y)
|
2313
|
98 |
| last2 (_ :: xs) = last2 xs
|
|
99 |
|
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
|
100 |
fun dest_listT (Type (@{type_name list}, [T])) = 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
|
101 |
| dest_listT T = raise TYPE ("dest_listT: list type expected", [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
|
102 |
|
2399
|
103 |
fun size_const ty = Const (@{const_name size}, ty --> @{typ nat})
|
1979
|
104 |
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
105 |
fun sum_case_const ty1 ty2 ty3 =
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
106 |
Const (@{const_name sum_case}, [ty1 --> ty3, ty2 --> ty3, Type (@{type_name sum}, [ty1, ty2])] ---> ty3)
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
107 |
fun mk_sum_case trm1 trm2 =
|
2477
|
108 |
let
|
|
109 |
val ([ty1], ty3) = strip_type (fastype_of trm1)
|
|
110 |
val ty2 = domain_type (fastype_of trm2)
|
|
111 |
in
|
|
112 |
sum_case_const ty1 ty2 ty3 $ trm1 $ trm2
|
|
113 |
end
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
114 |
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
115 |
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
116 |
|
2399
|
117 |
fun mk_minus p = @{term "uminus::perm => perm"} $ p
|
1896
996d4411e95e
tuned; fleshed out some library functions about permutations; closed Datatype_Aux structure (increases readability)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
118 |
|
2399
|
119 |
fun mk_plus p q = @{term "plus::perm => perm => perm"} $ p $ q
|
|
120 |
|
|
121 |
fun perm_ty ty = @{typ "perm"} --> ty --> ty
|
|
122 |
fun mk_perm_ty ty p trm = Const (@{const_name "permute"}, perm_ty ty) $ p $ trm
|
|
123 |
fun mk_perm p trm = mk_perm_ty (fastype_of trm) p trm
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
|
1834
|
125 |
fun dest_perm (Const (@{const_name "permute"}, _) $ p $ t) = (p, t)
|
1979
|
126 |
| dest_perm t = raise TERM ("dest_perm", [t]);
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
|
1962
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
128 |
fun mk_sort_of t = @{term "sort_of"} $ t;
|
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
129 |
|
1979
|
130 |
fun atom_ty ty = ty --> @{typ "atom"};
|
1963
|
131 |
fun mk_atom_ty ty t = Const (@{const_name "atom"}, atom_ty ty) $ t;
|
1962
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
132 |
fun mk_atom t = mk_atom_ty (fastype_of t) t;
|
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
133 |
|
1979
|
134 |
|
|
135 |
fun supp_ty ty = ty --> @{typ "atom set"};
|
2450
|
136 |
fun supp_const ty = Const (@{const_name supp}, supp_ty ty)
|
2475
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
137 |
fun mk_supp_ty ty t = supp_const ty $ t
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
138 |
fun mk_supp t = mk_supp_ty (fastype_of t) t
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
139 |
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
140 |
fun supp_rel_ty ty = ([ty, ty] ---> @{typ bool}) --> ty --> @{typ "atom set"};
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
141 |
fun supp_rel_const ty = Const (@{const_name supp_rel}, supp_rel_ty ty)
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
142 |
fun mk_supp_rel_ty ty r t = supp_rel_const ty $ r $ t
|
486d4647bb37
supp-proofs work except for CoreHaskell and Modules (induct is probably not finding the correct instance)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
143 |
fun mk_supp_rel r t = mk_supp_rel_ty (fastype_of t) r t
|
1979
|
144 |
|
2450
|
145 |
fun supports_const ty = Const (@{const_name supports}, [@{typ "atom set"}, ty] ---> @{typ bool});
|
2448
|
146 |
fun mk_supports_ty ty t1 t2 = supports_const ty $ t1 $ t2;
|
|
147 |
fun mk_supports t1 t2 = mk_supports_ty (fastype_of t2) t1 t2;
|
1979
|
148 |
|
2450
|
149 |
fun finite_const ty = Const (@{const_name finite}, ty --> @{typ bool})
|
|
150 |
fun mk_finite_ty ty t = finite_const ty $ t
|
|
151 |
fun mk_finite t = mk_finite_ty (fastype_of t) t
|
|
152 |
|
|
153 |
|
1834
|
154 |
fun mk_equiv r = r RS @{thm eq_reflection};
|
|
155 |
fun safe_mk_equiv r = mk_equiv r handle Thm.THM _ => r;
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
|
1962
84a13d1e2511
moved mk_atom into the library; that meant that concrete atom classes need to be in Nominal2_Base
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
157 |
|
2296
|
158 |
(* functions that construct differences, appends and unions
|
|
159 |
but avoid producing empty atom sets or empty atom lists *)
|
2289
|
160 |
|
|
161 |
fun mk_diff (@{term "{}::atom set"}, _) = @{term "{}::atom set"}
|
|
162 |
| mk_diff (t1, @{term "{}::atom set"}) = t1
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
163 |
| mk_diff (@{term "set ([]::atom list)"}, _) = @{term "set ([]::atom list)"}
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
164 |
| mk_diff (t1, @{term "set ([]::atom list)"}) = t1
|
2289
|
165 |
| mk_diff (t1, t2) = HOLogic.mk_binop @{const_name minus} (t1, t2)
|
|
166 |
|
2389
|
167 |
fun mk_append (t1, @{term "[]::atom list"}) = t1
|
2296
|
168 |
| mk_append (@{term "[]::atom list"}, t2) = t2
|
|
169 |
| mk_append (t1, t2) = HOLogic.mk_binop @{const_name "append"} (t1, t2)
|
|
170 |
|
2389
|
171 |
fun mk_union (t1, @{term "{}::atom set"}) = t1
|
2289
|
172 |
| mk_union (@{term "{}::atom set"}, t2) = t2
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
173 |
| mk_union (t1, @{term "set ([]::atom list)"}) = t1
|
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
174 |
| mk_union (@{term "set ([]::atom list)"}, t2) = t2
|
2296
|
175 |
| mk_union (t1, t2) = HOLogic.mk_binop @{const_name "sup"} (t1, t2)
|
2289
|
176 |
|
2384
|
177 |
fun fold_union trms = fold_rev (curry mk_union) trms @{term "{}::atom set"}
|
2464
f4eba60cbd69
made the fv-definition aggree more with alpha (needed in the support proofs)
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
178 |
fun fold_append trms = fold_rev (curry mk_append) trms @{term "[]::atom list"}
|
2289
|
179 |
|
2389
|
180 |
fun mk_conj (t1, @{term "True"}) = t1
|
|
181 |
| mk_conj (@{term "True"}, t2) = t2
|
|
182 |
| mk_conj (t1, t2) = HOLogic.mk_conj (t1, t2)
|
2289
|
183 |
|
2389
|
184 |
fun fold_conj trms = fold_rev (curry mk_conj) trms @{term "True"}
|
2296
|
185 |
|
2448
|
186 |
|
|
187 |
(* produces fresh arguments for a term *)
|
|
188 |
|
|
189 |
fun fresh_args ctxt f =
|
|
190 |
f |> fastype_of
|
|
191 |
|> binder_types
|
|
192 |
|> map (pair "z")
|
|
193 |
|> Variable.variant_frees ctxt [f]
|
|
194 |
|> map Free
|
|
195 |
|
|
196 |
|
|
197 |
|
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
|
198 |
(** datatypes **)
|
3b83960f9544
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 |
|
2407
|
200 |
(* constructor infos *)
|
|
201 |
type cns_info = (term * typ * typ list * bool list) list
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
202 |
|
3b83960f9544
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
|
203 |
(* returns the type of the nth datatype *)
|
2296
|
204 |
fun all_dtyps descr sorts =
|
|
205 |
map (fn n => Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec n)) (0 upto (length descr - 1))
|
|
206 |
|
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 nth_dtyp descr sorts 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
|
208 |
Datatype_Aux.typ_of_dtyp descr sorts (Datatype_Aux.DtRec 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
|
209 |
|
3b83960f9544
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
|
210 |
(* returns info about constructors in a datatype *)
|
3b83960f9544
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 |
fun all_dtyp_constrs_info 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 |
map (fn (_, (ty, vs, constrs)) => map (pair (ty, vs)) constrs) 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
|
213 |
|
3b83960f9544
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 |
(* returns the constants of the constructors plus the
|
3b83960f9544
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
|
215 |
corresponding type and types of arguments *)
|
3b83960f9544
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 |
fun all_dtyp_constrs_types descr sorts =
|
3b83960f9544
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 |
let
|
2477
|
218 |
fun aux ((ty_name, vs), (cname, args)) =
|
|
219 |
let
|
|
220 |
val vs_tys = map (Datatype_Aux.typ_of_dtyp descr sorts) vs
|
|
221 |
val ty = Type (ty_name, vs_tys)
|
|
222 |
val arg_tys = map (Datatype_Aux.typ_of_dtyp descr sorts) args
|
|
223 |
val is_rec = map Datatype_Aux.is_rec_type args
|
|
224 |
in
|
|
225 |
(Const (cname, arg_tys ---> ty), ty, arg_tys, is_rec)
|
|
226 |
end
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
227 |
in
|
2477
|
228 |
map (map aux) (all_dtyp_constrs_info descr)
|
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
|
229 |
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
|
230 |
|
3b83960f9544
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 |
fun nth_dtyp_constrs_types descr sorts 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
|
232 |
nth (all_dtyp_constrs_types descr sorts) 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
|
233 |
|
3b83960f9544
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 |
|
3b83960f9544
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 |
(* generates for every datatype a name str ^ dt_name
|
3b83960f9544
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 |
plus and index for multiple occurences of a string *)
|
3b83960f9544
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
|
237 |
fun prefix_dt_names descr sorts str =
|
2477
|
238 |
let
|
|
239 |
fun get_nth_name (i, _) =
|
|
240 |
Datatype_Aux.name_of_typ (nth_dtyp descr sorts i)
|
|
241 |
in
|
|
242 |
Datatype_Prop.indexify_names
|
|
243 |
(map (prefix str o get_nth_name) descr)
|
|
244 |
end
|
2288
3b83960f9544
new fv/fv_bn function (supp breaks now); exported raw perms and raw funs into separate ML-files
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
245 |
|
3b83960f9544
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
|
246 |
|
2311
|
247 |
|
|
248 |
(** function package tactics **)
|
|
249 |
|
2304
|
250 |
fun pat_completeness_simp simps lthy =
|
2477
|
251 |
let
|
|
252 |
val simp_set = HOL_basic_ss addsimps (@{thms sum.inject sum.distinct} @ simps)
|
|
253 |
in
|
|
254 |
Pat_Completeness.pat_completeness_tac lthy 1
|
|
255 |
THEN ALLGOALS (asm_full_simp_tac simp_set)
|
|
256 |
end
|
2304
|
257 |
|
2557
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
258 |
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
259 |
(** FIX: my_relation is necessary because of problem in Function Package *)
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
260 |
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
261 |
fun inst_state_tac ctxt rel st =
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
262 |
let
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
263 |
val cert = Thm.cterm_of (ProofContext.theory_of ctxt)
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
264 |
val rel' = cert (singleton (Variable.polymorphic ctxt) rel)
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
265 |
val st' = Thm.incr_indexes (#maxidx (Thm.rep_cterm rel') + 1) st
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
266 |
in case Term.add_vars (prop_of st') [] of
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
267 |
[v] =>
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
268 |
PRIMITIVE (Drule.cterm_instantiate [(cert (Var v), rel')]) st'
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
269 |
| _ => Seq.empty
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
270 |
end
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
271 |
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
272 |
fun my_relation_tac ctxt rel i =
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
273 |
TRY (Function_Common.apply_termination_rule ctxt i)
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
274 |
THEN inst_state_tac ctxt rel
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
275 |
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
276 |
(** FIX: end *)
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
277 |
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
278 |
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
279 |
fun prove_termination_tac size_simps ctxt i st =
|
2477
|
280 |
let
|
|
281 |
fun mk_size_measure (Type (@{type_name Sum_Type.sum}, [fT, sT])) =
|
|
282 |
SumTree.mk_sumcase fT sT @{typ nat} (mk_size_measure fT) (mk_size_measure sT)
|
|
283 |
| mk_size_measure T = size_const T
|
2304
|
284 |
|
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
285 |
val ((_ $ (_ $ rel)) :: _) = prems_of st
|
2477
|
286 |
val measure_trm =
|
|
287 |
fastype_of rel
|
|
288 |
|> HOLogic.dest_setT
|
|
289 |
|> mk_size_measure
|
|
290 |
|> curry (op $) (Const (@{const_name measure}, dummyT))
|
|
291 |
|> Syntax.check_term ctxt
|
|
292 |
val ss = HOL_ss addsimps @{thms in_measure wf_measure sum.cases add_Suc_right add.right_neutral
|
|
293 |
zero_less_Suc} @ size_simps addsimprocs Nat_Numeral_Simprocs.cancel_numerals
|
2557
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
294 |
|
2477
|
295 |
in
|
2557
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
296 |
(*see above Function_Relation.relation_tac ctxt measure_trm*)
|
781fbc8c0591
fixed locally the problem with the function package; all tests work again
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
297 |
(my_relation_tac ctxt measure_trm
|
2477
|
298 |
THEN_ALL_NEW simp_tac ss) i st
|
|
299 |
end
|
2410
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
300 |
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
301 |
fun prove_termination size_simps ctxt =
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
302 |
Function.prove_termination NONE
|
2bbdb9c427b5
improved runtime slightly, by constructing an explicit size measure for the function definitions
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
303 |
(HEADGOAL (prove_termination_tac size_simps ctxt)) ctxt
|
2311
|
304 |
|
|
305 |
(** transformations of premises (in inductive proofs) **)
|
|
306 |
|
|
307 |
(*
|
|
308 |
given the theorem F[t]; proves the theorem F[f t]
|
|
309 |
|
|
310 |
- F needs to be monotone
|
|
311 |
- f returns either SOME for a term it fires on
|
|
312 |
and NONE elsewhere
|
|
313 |
*)
|
|
314 |
fun map_term f t =
|
|
315 |
(case f t of
|
|
316 |
NONE => map_term' f t
|
|
317 |
| x => x)
|
|
318 |
and map_term' f (t $ u) =
|
|
319 |
(case (map_term f t, map_term f u) of
|
|
320 |
(NONE, NONE) => NONE
|
|
321 |
| (SOME t'', NONE) => SOME (t'' $ u)
|
|
322 |
| (NONE, SOME u'') => SOME (t $ u'')
|
|
323 |
| (SOME t'', SOME u'') => SOME (t'' $ u''))
|
|
324 |
| map_term' f (Abs (s, T, t)) =
|
|
325 |
(case map_term f t of
|
|
326 |
NONE => NONE
|
|
327 |
| SOME t'' => SOME (Abs (s, T, t'')))
|
|
328 |
| map_term' _ _ = NONE;
|
|
329 |
|
|
330 |
fun map_thm_tac ctxt tac thm =
|
2477
|
331 |
let
|
|
332 |
val monos = Inductive.get_monos ctxt
|
|
333 |
val simps = HOL_basic_ss addsimps @{thms split_def}
|
|
334 |
in
|
|
335 |
EVERY [cut_facts_tac [thm] 1, etac rev_mp 1,
|
|
336 |
REPEAT_DETERM (FIRSTGOAL (simp_tac simps THEN' resolve_tac monos)),
|
|
337 |
REPEAT_DETERM (rtac impI 1 THEN (atac 1 ORELSE tac))]
|
|
338 |
end
|
2311
|
339 |
|
|
340 |
fun map_thm ctxt f tac thm =
|
2477
|
341 |
let
|
|
342 |
val opt_goal_trm = map_term f (prop_of thm)
|
|
343 |
in
|
|
344 |
case opt_goal_trm of
|
|
345 |
NONE => thm
|
|
346 |
| SOME goal =>
|
|
347 |
Goal.prove ctxt [] [] goal (fn _ => map_thm_tac ctxt tac thm)
|
|
348 |
end
|
2311
|
349 |
|
|
350 |
(*
|
|
351 |
inductive premises can be of the form
|
|
352 |
R ... /\ P ...; split_conj_i picks out
|
|
353 |
the part R or P part
|
|
354 |
*)
|
2480
ac7dff1194e8
introduced a general procedure for structural inductions; simplified reflexivity proof
Christian Urban <urbanc@in.tum.de>
diff
changeset
|
355 |
fun split_conj1 names (Const (@{const_name "conj"}, _) $ f1 $ _) =
|
2311
|
356 |
(case head_of f1 of
|
|
357 |
Const (name, _) => if member (op =) names name then SOME f1 else NONE
|
|
358 |
| _ => NONE)
|
|
359 |
| split_conj1 _ _ = NONE;
|
|
360 |
|
2446
|
361 |
fun split_conj2 names (Const (@{const_name "conj"}, _) $ f1 $ f2) =
|
2311
|
362 |
(case head_of f1 of
|
|
363 |
Const (name, _) => if member (op =) names name then SOME f2 else NONE
|
|
364 |
| _ => NONE)
|
|
365 |
| split_conj2 _ _ = NONE;
|
|
366 |
|
|
367 |
fun transform_prem1 ctxt names thm =
|
|
368 |
map_thm ctxt (split_conj1 names) (etac conjunct1 1) thm
|
|
369 |
|
|
370 |
fun transform_prem2 ctxt names thm =
|
|
371 |
map_thm ctxt (split_conj2 names) (etac conjunct2 1) thm
|
|
372 |
|
|
373 |
|
2397
|
374 |
(* transformes a theorem into one of the object logic *)
|
|
375 |
val atomize = Conv.fconv_rule Object_Logic.atomize o forall_intr_vars
|
|
376 |
|
1833
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
377 |
end (* structure *)
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
378 |
|
2050b5723c04
added a library for basic nominal functions; separated nominal_eqvt file
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
379 |
open Nominal_Library; |