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