author | Christian Urban <urbanc@in.tum.de> |
Thu, 19 Apr 2018 13:57:17 +0100 | |
changeset 3245 | 017e33849f4d |
parent 3229 | b52e8651591f |
permissions | -rw-r--r-- |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
1 |
(* Title: nominal_basics.ML |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
2 |
Author: Christian Urban |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
3 |
Author: Tjark Weber |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
4 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
5 |
Basic functions for nominal. |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
6 |
*) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
7 |
|
2962
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
8 |
infix 1 ||>>> |>>> |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
9 |
|
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
10 |
signature NOMINAL_BASIC = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
11 |
sig |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
12 |
val trace: bool Unsynchronized.ref |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
13 |
val trace_msg: (unit -> string) -> unit |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
14 |
|
2962
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
15 |
val |>>> : 'a * ('a -> 'b * 'c) -> 'b list * 'c |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
16 |
val ||>>> : ('a list * 'b) * ('b -> 'a * 'b) -> 'a list * 'b |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
17 |
|
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
18 |
val last2: 'a list -> 'a * 'a |
2959 | 19 |
val split_triples: ('a * 'b * 'c) list -> ('a list * 'b list * 'c list) |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
20 |
val split_last2: 'a list -> 'a list * 'a * 'a |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
21 |
val order: ('a * 'a -> bool) -> 'a list -> ('a * 'b) list -> 'b list |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
22 |
val order_default: ('a * 'a -> bool) -> 'b -> 'a list -> ('a * 'b) list -> 'b list |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
23 |
val remove_dups: ('a * 'a -> bool) -> 'a list -> 'a list |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
24 |
val map4: ('a -> 'b -> 'c -> 'd -> 'e) -> 'a list -> 'b list -> 'c list -> 'd list -> 'e list |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
25 |
val split_filter: ('a -> bool) -> 'a list -> 'a list * 'a list |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
26 |
val fold_left: ('a * 'a -> 'a) -> 'a list -> 'a -> 'a |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
27 |
|
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
28 |
val is_true: term -> bool |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
29 |
|
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
30 |
val dest_listT: typ -> typ |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
31 |
val dest_fsetT: typ -> typ |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
32 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
33 |
val mk_id: term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
34 |
val mk_all: (string * typ) -> term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
35 |
val mk_All: (string * typ) -> term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
36 |
val mk_exists: (string * typ) -> term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
37 |
|
3229
b52e8651591f
updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
3214
diff
changeset
|
38 |
val case_sum_const: typ -> typ -> typ -> term |
b52e8651591f
updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
3214
diff
changeset
|
39 |
val mk_case_sum: term -> term -> term |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
40 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
41 |
val mk_equiv: thm -> thm |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
42 |
val safe_mk_equiv: thm -> thm |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
43 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
44 |
val mk_minus: term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
45 |
val mk_plus: term -> term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
46 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
47 |
val perm_ty: typ -> typ |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
48 |
val perm_const: typ -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
49 |
val mk_perm_ty: typ -> term -> term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
50 |
val mk_perm: term -> term -> term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
51 |
val dest_perm: term -> term * term |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
52 |
|
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
53 |
(* functions to deal with constants in local contexts *) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
54 |
val long_name: Proof.context -> string -> string |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
55 |
val is_fixed: Proof.context -> term -> bool |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
56 |
val fixed_nonfixed_args: Proof.context -> term -> term * term list |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
57 |
end |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
58 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
59 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
60 |
structure Nominal_Basic: NOMINAL_BASIC = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
61 |
struct |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
62 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
63 |
val trace = Unsynchronized.ref false |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
64 |
fun trace_msg msg = if ! trace then tracing (msg ()) else () |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
65 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
66 |
|
2962
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
67 |
infix 1 ||>>> |>>> |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
68 |
|
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
69 |
fun (x |>>> f) = |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
70 |
let |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
71 |
val (x', y') = f x |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
72 |
in |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
73 |
([x'], y') |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
74 |
end |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
75 |
|
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
76 |
fun (([], y) ||>>> f) = ([], y) |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
77 |
| ((xs, y) ||>>> f) = |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
78 |
let |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
79 |
val (x', y') = f y |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
80 |
in |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
81 |
(xs @ [x'], y') |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
82 |
end |
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
83 |
|
7a24d827cba9
combinators for local theories and lists
Christian Urban <urbanc@in.tum.de>
parents:
2959
diff
changeset
|
84 |
|
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
85 |
(* orders an AList according to keys - every key needs to be there *) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
86 |
fun order eq keys list = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
87 |
map (the o AList.lookup eq list) keys |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
88 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
89 |
(* orders an AList according to keys - returns default for non-existing keys *) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
90 |
fun order_default eq default keys list = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
91 |
map (the_default default o AList.lookup eq list) keys |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
92 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
93 |
(* remove duplicates *) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
94 |
fun remove_dups eq [] = [] |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
95 |
| remove_dups eq (x :: xs) = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
96 |
if member eq xs x |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
97 |
then remove_dups eq xs |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
98 |
else x :: remove_dups eq xs |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
99 |
|
2959 | 100 |
fun split_triples xs = |
101 |
fold (fn (a, b, c) => fn (axs, bxs, cxs) => (a :: axs, b :: bxs, c :: cxs)) xs ([], [], []) |
|
102 |
||
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
103 |
fun last2 [] = raise Empty |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
104 |
| last2 [_] = raise Empty |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
105 |
| last2 [x, y] = (x, y) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
106 |
| last2 (_ :: xs) = last2 xs |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
107 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
108 |
fun split_last2 xs = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
109 |
let |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
110 |
val (xs', x) = split_last xs |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
111 |
val (xs'', y) = split_last xs' |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
112 |
in |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
113 |
(xs'', y, x) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
114 |
end |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
115 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
116 |
fun map4 _ [] [] [] [] = [] |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
117 |
| map4 f (x :: xs) (y :: ys) (z :: zs) (u :: us) = f x y z u :: map4 f xs ys zs us |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
118 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
119 |
fun split_filter f [] = ([], []) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
120 |
| split_filter f (x :: xs) = |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
121 |
let |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
122 |
val (r, l) = split_filter f xs |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
123 |
in |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
124 |
if f x |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
125 |
then (x :: r, l) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
126 |
else (r, x :: l) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
127 |
end |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
128 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
129 |
(* to be used with left-infix binop-operations *) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
130 |
fun fold_left f [] z = z |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
131 |
| fold_left f [x] z = x |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
132 |
| fold_left f (x :: y :: xs) z = fold_left f (f (x, y) :: xs) z |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
133 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
134 |
fun is_true @{term "Trueprop True"} = true |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
135 |
| is_true _ = false |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
136 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
137 |
fun dest_listT (Type (@{type_name list}, [T])) = T |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
138 |
| dest_listT T = raise TYPE ("dest_listT: list type expected", [T], []) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
139 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
140 |
fun dest_fsetT (Type (@{type_name fset}, [T])) = T |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
141 |
| dest_fsetT T = raise TYPE ("dest_fsetT: fset type expected", [T], []) |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
142 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
143 |
fun mk_id trm = HOLogic.id_const (fastype_of trm) $ trm |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
144 |
|
3108
61db5ad429bb
updated to Isabelle 16 January
Christian Urban <urbanc@in.tum.de>
parents:
2962
diff
changeset
|
145 |
fun mk_all (a, T) t = Logic.all_const T $ Abs (a, T, t) |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
146 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
147 |
fun mk_All (a, T) t = HOLogic.all_const T $ Abs (a, T, t) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
148 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
149 |
fun mk_exists (a, T) t = HOLogic.exists_const T $ Abs (a, T, t) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
150 |
|
3229
b52e8651591f
updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
3214
diff
changeset
|
151 |
fun case_sum_const ty1 ty2 ty3 = |
b52e8651591f
updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
3214
diff
changeset
|
152 |
Const (@{const_name case_sum}, [ty1 --> ty3, ty2 --> ty3, Type (@{type_name sum}, [ty1, ty2])] ---> ty3) |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
153 |
|
3229
b52e8651591f
updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
3214
diff
changeset
|
154 |
fun mk_case_sum trm1 trm2 = |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
155 |
let |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
156 |
val ([ty1], ty3) = strip_type (fastype_of trm1) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
157 |
val ty2 = domain_type (fastype_of trm2) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
158 |
in |
3229
b52e8651591f
updated to Isabelle changes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
3214
diff
changeset
|
159 |
case_sum_const ty1 ty2 ty3 $ trm1 $ trm2 |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
160 |
end |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
161 |
|
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
162 |
fun mk_equiv r = r RS @{thm eq_reflection} |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
163 |
fun safe_mk_equiv r = mk_equiv r handle Thm.THM _ => r |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
164 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
165 |
fun mk_minus p = @{term "uminus::perm => perm"} $ p |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
166 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
167 |
fun mk_plus p q = @{term "plus::perm => perm => perm"} $ p $ q |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
168 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
169 |
fun perm_ty ty = @{typ "perm"} --> ty --> ty |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
170 |
fun perm_const ty = Const (@{const_name "permute"}, perm_ty ty) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
171 |
fun mk_perm_ty ty p trm = perm_const ty $ p $ trm |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
172 |
fun mk_perm p trm = mk_perm_ty (fastype_of trm) p trm |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
173 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
174 |
fun dest_perm (Const (@{const_name "permute"}, _) $ p $ t) = (p, t) |
3214
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
175 |
| dest_perm t = raise TERM ("dest_perm", [t]) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
176 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
177 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
178 |
(** functions to deal with constants in local contexts **) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
179 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
180 |
(* returns the fully qualified name of a constant *) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
181 |
fun long_name ctxt name = |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
182 |
case head_of (Syntax.read_term ctxt name) of |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
183 |
Const (s, _) => s |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
184 |
| _ => error ("Undeclared constant: " ^ quote name) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
185 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
186 |
(* returns true iff the argument term is a fixed Free *) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
187 |
fun is_fixed_Free ctxt (Free (s, _)) = Variable.is_fixed ctxt s |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
188 |
| is_fixed_Free _ _ = false |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
189 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
190 |
(* returns true iff c is a constant or fixed Free applied to |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
191 |
fixed parameters *) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
192 |
fun is_fixed ctxt c = |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
193 |
let |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
194 |
val (c, args) = strip_comb c |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
195 |
in |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
196 |
(is_Const c orelse is_fixed_Free ctxt c) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
197 |
andalso List.all (is_fixed_Free ctxt) args |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
198 |
end |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
199 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
200 |
(* splits a list into the longest prefix containing only elements |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
201 |
that satisfy p, and the rest of the list *) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
202 |
fun chop_while p = |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
203 |
let |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
204 |
fun chop_while_aux acc [] = |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
205 |
(rev acc, []) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
206 |
| chop_while_aux acc (x::xs) = |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
207 |
if p x then chop_while_aux (x::acc) xs else (rev acc, x::xs) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
208 |
in |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
209 |
chop_while_aux [] |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
210 |
end |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
211 |
|
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
212 |
(* takes a combination "c $ fixed1 $ ... $ fixedN $ not-fixed $ ..." |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
213 |
to the pair ("c $ fixed1 $ ... $ fixedN", ["not-fixed", ...]). *) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
214 |
fun fixed_nonfixed_args ctxt c_args = |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
215 |
let |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
216 |
val (c, args) = strip_comb c_args |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
217 |
val (frees, args) = chop_while (is_fixed_Free ctxt) args |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
218 |
val c_frees = list_comb (c, frees) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
219 |
in |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
220 |
(c_frees, args) |
13ab4f0a0b0e
Various changes to support Nominal2 commands in local contexts.
webertj
parents:
3108
diff
changeset
|
221 |
end |
2733
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
222 |
|
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
223 |
end (* structure *) |
5f6fefdbf055
split the library into a basics file; merged Nominal_Eqvt into Nominal_Base
Christian Urban <urbanc@in.tum.de>
parents:
diff
changeset
|
224 |
|
3245
017e33849f4d
updated to Isabelle 2016-1
Christian Urban <urbanc@in.tum.de>
parents:
3229
diff
changeset
|
225 |
open Nominal_Basic; |