author | haftmann |
Thu, 01 Jul 2010 16:54:44 +0200 | |
changeset 37678 | 0040bafffdef |
parent 37155 | e3f18cfc9829 |
child 37786 | 4eb98849c5c0 |
permissions | -rw-r--r-- |
36898 | 1 |
(* Title: HOL/Tools/SMT/smtlib_interface.ML |
2 |
Author: Sascha Boehme, TU Muenchen |
|
3 |
||
4 |
Interface to SMT solvers based on the SMT-LIB format. |
|
5 |
*) |
|
6 |
||
7 |
signature SMTLIB_INTERFACE = |
|
8 |
sig |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
9 |
type builtins = { |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
10 |
builtin_typ: typ -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
11 |
builtin_num: typ -> int -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
12 |
builtin_func: string * typ -> term list -> (string * term list) option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
13 |
builtin_pred: string * typ -> term list -> (string * term list) option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
14 |
is_builtin_pred: string -> typ -> bool } |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
15 |
val add_builtins: builtins -> Context.generic -> Context.generic |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
16 |
val add_logic: (term list -> string option) -> Context.generic -> |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
17 |
Context.generic |
36898 | 18 |
val interface: SMT_Solver.interface |
19 |
end |
|
20 |
||
21 |
structure SMTLIB_Interface: SMTLIB_INTERFACE = |
|
22 |
struct |
|
23 |
||
24 |
structure N = SMT_Normalize |
|
25 |
structure T = SMT_Translate |
|
26 |
||
27 |
||
28 |
||
29 |
(** facts about uninterpreted constants **) |
|
30 |
||
31 |
infix 2 ?? |
|
32 |
fun (ex ?? f) thms = if exists (ex o Thm.prop_of) thms then f thms else thms |
|
33 |
||
34 |
||
35 |
(* pairs *) |
|
36 |
||
37 |
val pair_rules = [@{thm fst_conv}, @{thm snd_conv}, @{thm pair_collapse}] |
|
38 |
||
37678
0040bafffdef
"prod" and "sum" replace "*" and "+" respectively
haftmann
parents:
37155
diff
changeset
|
39 |
val pair_type = (fn Type (@{type_name Product_Type.prod}, _) => true | _ => false) |
36898 | 40 |
val exists_pair_type = Term.exists_type (Term.exists_subtype pair_type) |
41 |
||
42 |
val add_pair_rules = exists_pair_type ?? append pair_rules |
|
43 |
||
44 |
||
45 |
(* function update *) |
|
46 |
||
47 |
val fun_upd_rules = [@{thm fun_upd_same}, @{thm fun_upd_apply}] |
|
48 |
||
49 |
val is_fun_upd = (fn Const (@{const_name fun_upd}, _) => true | _ => false) |
|
50 |
val exists_fun_upd = Term.exists_subterm is_fun_upd |
|
51 |
||
52 |
val add_fun_upd_rules = exists_fun_upd ?? append fun_upd_rules |
|
53 |
||
54 |
||
55 |
(* abs/min/max *) |
|
56 |
||
57 |
val exists_abs_min_max = Term.exists_subterm (fn |
|
58 |
Const (@{const_name abs}, _) => true |
|
59 |
| Const (@{const_name min}, _) => true |
|
60 |
| Const (@{const_name max}, _) => true |
|
61 |
| _ => false) |
|
62 |
||
63 |
val unfold_abs_conv = Conv.rewr_conv @{thm abs_if[THEN eq_reflection]} |
|
64 |
val unfold_min_conv = Conv.rewr_conv @{thm min_def[THEN eq_reflection]} |
|
65 |
val unfold_max_conv = Conv.rewr_conv @{thm max_def[THEN eq_reflection]} |
|
66 |
||
67 |
fun expand_conv cv = N.eta_expand_conv (K cv) |
|
68 |
fun expand2_conv cv = N.eta_expand_conv (N.eta_expand_conv (K cv)) |
|
69 |
||
70 |
fun unfold_def_conv ctxt ct = |
|
71 |
(case Thm.term_of ct of |
|
72 |
Const (@{const_name abs}, _) $ _ => unfold_abs_conv |
|
73 |
| Const (@{const_name abs}, _) => expand_conv unfold_abs_conv ctxt |
|
74 |
| Const (@{const_name min}, _) $ _ $ _ => unfold_min_conv |
|
75 |
| Const (@{const_name min}, _) $ _ => expand_conv unfold_min_conv ctxt |
|
76 |
| Const (@{const_name min}, _) => expand2_conv unfold_min_conv ctxt |
|
77 |
| Const (@{const_name max}, _) $ _ $ _ => unfold_max_conv |
|
78 |
| Const (@{const_name max}, _) $ _ => expand_conv unfold_max_conv ctxt |
|
79 |
| Const (@{const_name max}, _) => expand2_conv unfold_max_conv ctxt |
|
80 |
| _ => Conv.all_conv) ct |
|
81 |
||
82 |
fun unfold_abs_min_max_defs ctxt thm = |
|
83 |
if exists_abs_min_max (Thm.prop_of thm) |
|
36936
c52d1c130898
incorporated further conversions and conversionals, after some minor tuning;
wenzelm
parents:
36899
diff
changeset
|
84 |
then Conv.fconv_rule (Conv.top_conv unfold_def_conv ctxt) thm |
36898 | 85 |
else thm |
86 |
||
87 |
||
88 |
(* include additional facts *) |
|
89 |
||
90 |
fun extra_norm thms ctxt = |
|
91 |
thms |
|
92 |
|> add_pair_rules |
|
93 |
|> add_fun_upd_rules |
|
94 |
|> map (unfold_abs_min_max_defs ctxt) |
|
95 |
|> rpair ctxt |
|
96 |
||
97 |
||
98 |
||
99 |
(** builtins **) |
|
100 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
101 |
(* additional builtins *) |
36898 | 102 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
103 |
type builtins = { |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
104 |
builtin_typ: typ -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
105 |
builtin_num: typ -> int -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
106 |
builtin_func: string * typ -> term list -> (string * term list) option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
107 |
builtin_pred: string * typ -> term list -> (string * term list) option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
108 |
is_builtin_pred: string -> typ -> bool } |
36898 | 109 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
110 |
fun chained _ [] = NONE |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
111 |
| chained f (b :: bs) = (case f b of SOME y => SOME y | NONE => chained f bs) |
36898 | 112 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
113 |
fun chained' _ [] = false |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
114 |
| chained' f (b :: bs) = f b orelse chained' f bs |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
115 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
116 |
fun chained_builtin_typ bs T = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
117 |
chained (fn {builtin_typ, ...} : builtins => builtin_typ T) bs |
36898 | 118 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
119 |
fun chained_builtin_num bs T i = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
120 |
chained (fn {builtin_num, ...} : builtins => builtin_num T i) bs |
36898 | 121 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
122 |
fun chained_builtin_func bs c ts = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
123 |
chained (fn {builtin_func, ...} : builtins => builtin_func c ts) bs |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
124 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
125 |
fun chained_builtin_pred bs c ts = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
126 |
chained (fn {builtin_pred, ...} : builtins => builtin_pred c ts) bs |
36898 | 127 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
128 |
fun chained_is_builtin_pred bs n T = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
129 |
chained' (fn {is_builtin_pred, ...} : builtins => is_builtin_pred n T) bs |
36898 | 130 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
131 |
fun fst_int_ord ((s1, _), (s2, _)) = int_ord (s1, s2) |
36898 | 132 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
133 |
structure Builtins = Generic_Data |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
134 |
( |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
135 |
type T = (int * builtins) list |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
136 |
val empty = [] |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
137 |
val extend = I |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
138 |
fun merge (bs1, bs2) = OrdList.union fst_int_ord bs2 bs1 |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
139 |
) |
36898 | 140 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
141 |
fun add_builtins bs = Builtins.map (OrdList.insert fst_int_ord (serial (), bs)) |
36898 | 142 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
143 |
fun get_builtins ctxt = map snd (Builtins.get (Context.Proof ctxt)) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
144 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
145 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
146 |
(* basic builtins combined with additional builtins *) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
147 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
148 |
fun builtin_typ _ @{typ int} = SOME "Int" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
149 |
| builtin_typ ctxt T = chained_builtin_typ (get_builtins ctxt) T |
36898 | 150 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
151 |
fun builtin_num _ @{typ int} i = SOME (string_of_int i) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
152 |
| builtin_num ctxt T i = chained_builtin_num (get_builtins ctxt) T i |
36898 | 153 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
154 |
fun if_int_type T n = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
155 |
(case try Term.domain_type T of |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
156 |
SOME @{typ int} => SOME n |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
157 |
| _ => NONE) |
36898 | 158 |
|
159 |
fun conn @{const_name True} = SOME "true" |
|
160 |
| conn @{const_name False} = SOME "false" |
|
161 |
| conn @{const_name Not} = SOME "not" |
|
162 |
| conn @{const_name "op &"} = SOME "and" |
|
163 |
| conn @{const_name "op |"} = SOME "or" |
|
164 |
| conn @{const_name "op -->"} = SOME "implies" |
|
165 |
| conn @{const_name "op ="} = SOME "iff" |
|
166 |
| conn @{const_name If} = SOME "if_then_else" |
|
167 |
| conn _ = NONE |
|
168 |
||
169 |
fun pred @{const_name distinct} _ = SOME "distinct" |
|
170 |
| pred @{const_name "op ="} _ = SOME "=" |
|
171 |
| pred @{const_name term_eq} _ = SOME "=" |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
172 |
| pred @{const_name less} T = if_int_type T "<" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
173 |
| pred @{const_name less_eq} T = if_int_type T "<=" |
36898 | 174 |
| pred _ _ = NONE |
175 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
176 |
fun func @{const_name If} _ = SOME "ite" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
177 |
| func @{const_name uminus} T = if_int_type T "~" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
178 |
| func @{const_name plus} T = if_int_type T "+" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
179 |
| func @{const_name minus} T = if_int_type T "-" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
180 |
| func @{const_name times} T = if_int_type T "*" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
181 |
| func _ _ = NONE |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
182 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
183 |
val is_propT = (fn @{typ prop} => true | _ => false) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
184 |
fun is_connT T = Term.strip_type T |> (fn (Us, U) => forall is_propT (U :: Us)) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
185 |
fun is_predT T = is_propT (Term.body_type T) |
36898 | 186 |
|
187 |
fun is_builtin_conn (n, T) = is_connT T andalso is_some (conn n) |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
188 |
fun is_builtin_pred ctxt (n, T) = is_predT T andalso |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
189 |
(is_some (pred n T) orelse chained_is_builtin_pred (get_builtins ctxt) n T) |
36898 | 190 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
191 |
fun builtin_fun ctxt (c as (n, T)) ts = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
192 |
let |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
193 |
val builtin_func' = chained_builtin_func (get_builtins ctxt) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
194 |
val builtin_pred' = chained_builtin_pred (get_builtins ctxt) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
195 |
in |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
196 |
if is_connT T then conn n |> Option.map (rpair ts) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
197 |
else if is_predT T then |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
198 |
(case pred n T of SOME c' => SOME (c', ts) | NONE => builtin_pred' c ts) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
199 |
else |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
200 |
(case func n T of SOME c' => SOME (c', ts) | NONE => builtin_func' c ts) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
201 |
end |
36898 | 202 |
|
203 |
||
204 |
||
205 |
(** serialization **) |
|
206 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
207 |
(* header *) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
208 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
209 |
structure Logics = Generic_Data |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
210 |
( |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
211 |
type T = (int * (term list -> string option)) list |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
212 |
val empty = [] |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
213 |
val extend = I |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
214 |
fun merge (bs1, bs2) = OrdList.union fst_int_ord bs2 bs1 |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
215 |
) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
216 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
217 |
fun add_logic l = Logics.map (OrdList.insert fst_int_ord (serial (), l)) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
218 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
219 |
fun choose_logic ctxt ts = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
220 |
let |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
221 |
fun choose [] = "AUFLIA" |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
222 |
| choose ((_, l) :: ls) = (case l ts of SOME s => s | NONE => choose ls) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
223 |
in [":logic " ^ choose (rev (Logics.get (Context.Proof ctxt)))] end |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
224 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
225 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
226 |
(* serialization *) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
227 |
|
36898 | 228 |
val add = Buffer.add |
229 |
fun sep f = add " " #> f |
|
230 |
fun enclose l r f = sep (add l #> f #> add r) |
|
231 |
val par = enclose "(" ")" |
|
232 |
fun app n f = (fn [] => sep (add n) | xs => par (add n #> fold f xs)) |
|
233 |
fun line f = f #> add "\n" |
|
234 |
||
235 |
fun var i = add "?v" #> add (string_of_int i) |
|
236 |
||
237 |
fun sterm l (T.SVar i) = sep (var (l - i - 1)) |
|
238 |
| sterm l (T.SApp (n, ts)) = app n (sterm l) ts |
|
239 |
| sterm _ (T.SLet _) = raise Fail "SMT-LIB: unsupported let expression" |
|
240 |
| sterm l (T.SQua (q, ss, ps, t)) = |
|
241 |
let |
|
242 |
val quant = add o (fn T.SForall => "forall" | T.SExists => "exists") |
|
243 |
val vs = map_index (apfst (Integer.add l)) ss |
|
244 |
fun var_decl (i, s) = par (var i #> sep (add s)) |
|
245 |
val sub = sterm (l + length ss) |
|
246 |
fun pat kind ts = sep (add kind #> enclose "{" " }" (fold sub ts)) |
|
247 |
fun pats (T.SPat ts) = pat ":pat" ts |
|
248 |
| pats (T.SNoPat ts) = pat ":nopat" ts |
|
249 |
in par (quant q #> fold var_decl vs #> sub t #> fold pats ps) end |
|
250 |
||
37155
e3f18cfc9829
sort signature in SMT-LIB output (improves sharing of SMT certificates: goals of the same logical structure are translated into equal SMT-LIB benchmarks)
boehmes
parents:
36936
diff
changeset
|
251 |
fun ssort sorts = sort fast_string_ord sorts |
e3f18cfc9829
sort signature in SMT-LIB output (improves sharing of SMT certificates: goals of the same logical structure are translated into equal SMT-LIB benchmarks)
boehmes
parents:
36936
diff
changeset
|
252 |
fun fsort funcs = sort (prod_ord fast_string_ord (K EQUAL)) funcs |
e3f18cfc9829
sort signature in SMT-LIB output (improves sharing of SMT certificates: goals of the same logical structure are translated into equal SMT-LIB benchmarks)
boehmes
parents:
36936
diff
changeset
|
253 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
254 |
fun serialize comments {header, sorts, funcs} ts = |
36898 | 255 |
Buffer.empty |
256 |
|> line (add "(benchmark Isabelle") |
|
257 |
|> line (add ":status unknown") |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
258 |
|> fold (line o add) header |
36898 | 259 |
|> length sorts > 0 ? |
37155
e3f18cfc9829
sort signature in SMT-LIB output (improves sharing of SMT certificates: goals of the same logical structure are translated into equal SMT-LIB benchmarks)
boehmes
parents:
36936
diff
changeset
|
260 |
line (add ":extrasorts" #> par (fold (sep o add) (ssort sorts))) |
36898 | 261 |
|> length funcs > 0 ? ( |
262 |
line (add ":extrafuns" #> add " (") #> |
|
263 |
fold (fn (f, (ss, s)) => |
|
37155
e3f18cfc9829
sort signature in SMT-LIB output (improves sharing of SMT certificates: goals of the same logical structure are translated into equal SMT-LIB benchmarks)
boehmes
parents:
36936
diff
changeset
|
264 |
line (sep (app f (sep o add) (ss @ [s])))) (fsort funcs) #> |
36898 | 265 |
line (add ")")) |
266 |
|> fold (fn t => line (add ":assumption" #> sterm 0 t)) ts |
|
267 |
|> line (add ":formula true)") |
|
268 |
|> fold (fn str => line (add "; " #> add str)) comments |
|
269 |
|> Buffer.content |
|
270 |
||
271 |
||
272 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
273 |
(** interfaces **) |
36898 | 274 |
|
275 |
val interface = { |
|
276 |
extra_norm = extra_norm, |
|
277 |
translate = { |
|
278 |
prefixes = { |
|
279 |
sort_prefix = "S", |
|
280 |
func_prefix = "f"}, |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
281 |
header = choose_logic, |
36898 | 282 |
strict = SOME { |
283 |
is_builtin_conn = is_builtin_conn, |
|
284 |
is_builtin_pred = is_builtin_pred, |
|
285 |
is_builtin_distinct = true}, |
|
286 |
builtins = { |
|
287 |
builtin_typ = builtin_typ, |
|
288 |
builtin_num = builtin_num, |
|
289 |
builtin_fun = builtin_fun}, |
|
290 |
serialize = serialize}} |
|
291 |
||
292 |
end |