author | boehmes |
Mon, 22 Nov 2010 23:37:00 +0100 | |
changeset 40664 | e023788a91a1 |
parent 40663 | e080c9e68752 |
child 40681 | 872b08416fb4 |
permissions | -rw-r--r-- |
36898 | 1 |
(* Title: HOL/Tools/SMT/smt_translate.ML |
2 |
Author: Sascha Boehme, TU Muenchen |
|
3 |
||
4 |
Translate theorems into an SMT intermediate format and serialize them. |
|
5 |
*) |
|
6 |
||
7 |
signature SMT_TRANSLATE = |
|
8 |
sig |
|
9 |
(* intermediate term structure *) |
|
10 |
datatype squant = SForall | SExists |
|
11 |
datatype 'a spattern = SPat of 'a list | SNoPat of 'a list |
|
12 |
datatype sterm = |
|
13 |
SVar of int | |
|
14 |
SApp of string * sterm list | |
|
15 |
SLet of string * sterm * sterm | |
|
40664 | 16 |
SQua of squant * string list * sterm spattern list * int option * sterm |
36898 | 17 |
|
18 |
(* configuration options *) |
|
19 |
type prefixes = {sort_prefix: string, func_prefix: string} |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
20 |
type header = Proof.context -> term list -> string list |
36898 | 21 |
type strict = { |
22 |
is_builtin_conn: string * typ -> bool, |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
23 |
is_builtin_pred: Proof.context -> string * typ -> bool, |
36898 | 24 |
is_builtin_distinct: bool} |
25 |
type builtins = { |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
26 |
builtin_typ: Proof.context -> typ -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
27 |
builtin_num: Proof.context -> typ -> int -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
28 |
builtin_fun: Proof.context -> string * typ -> term list -> |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
29 |
(string * term list) option, |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
30 |
has_datatypes: bool } |
36898 | 31 |
type sign = { |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
32 |
header: string list, |
36898 | 33 |
sorts: string list, |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
34 |
dtyps: (string * (string * (string * string) list) list) list list, |
36898 | 35 |
funcs: (string * (string list * string)) list } |
36 |
type config = { |
|
37 |
prefixes: prefixes, |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
38 |
header: header, |
36898 | 39 |
strict: strict option, |
40 |
builtins: builtins, |
|
41 |
serialize: string list -> sign -> sterm list -> string } |
|
42 |
type recon = { |
|
43 |
typs: typ Symtab.table, |
|
44 |
terms: term Symtab.table, |
|
45 |
unfolds: thm list, |
|
40161
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
46 |
assms: (int * thm) list } |
36898 | 47 |
|
40161
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
48 |
val translate: config -> Proof.context -> string list -> (int * thm) list -> |
36898 | 49 |
string * recon |
50 |
end |
|
51 |
||
52 |
structure SMT_Translate: SMT_TRANSLATE = |
|
53 |
struct |
|
54 |
||
40663 | 55 |
structure U = SMT_Utils |
56 |
||
57 |
||
36898 | 58 |
(* intermediate term structure *) |
59 |
||
60 |
datatype squant = SForall | SExists |
|
61 |
||
62 |
datatype 'a spattern = SPat of 'a list | SNoPat of 'a list |
|
63 |
||
64 |
datatype sterm = |
|
65 |
SVar of int | |
|
66 |
SApp of string * sterm list | |
|
67 |
SLet of string * sterm * sterm | |
|
40664 | 68 |
SQua of squant * string list * sterm spattern list * int option * sterm |
36898 | 69 |
|
70 |
||
71 |
||
72 |
(* configuration options *) |
|
73 |
||
74 |
type prefixes = {sort_prefix: string, func_prefix: string} |
|
75 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
76 |
type header = Proof.context -> term list -> string list |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
77 |
|
36898 | 78 |
type strict = { |
79 |
is_builtin_conn: string * typ -> bool, |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
80 |
is_builtin_pred: Proof.context -> string * typ -> bool, |
36898 | 81 |
is_builtin_distinct: bool} |
82 |
||
83 |
type builtins = { |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
84 |
builtin_typ: Proof.context -> typ -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
85 |
builtin_num: Proof.context -> typ -> int -> string option, |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
86 |
builtin_fun: Proof.context -> string * typ -> term list -> |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
87 |
(string * term list) option, |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
88 |
has_datatypes: bool } |
36898 | 89 |
|
90 |
type sign = { |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
91 |
header: string list, |
36898 | 92 |
sorts: string list, |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
93 |
dtyps: (string * (string * (string * string) list) list) list list, |
36898 | 94 |
funcs: (string * (string list * string)) list } |
95 |
||
96 |
type config = { |
|
97 |
prefixes: prefixes, |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
98 |
header: header, |
36898 | 99 |
strict: strict option, |
100 |
builtins: builtins, |
|
101 |
serialize: string list -> sign -> sterm list -> string } |
|
102 |
||
103 |
type recon = { |
|
104 |
typs: typ Symtab.table, |
|
105 |
terms: term Symtab.table, |
|
106 |
unfolds: thm list, |
|
40161
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
107 |
assms: (int * thm) list } |
36898 | 108 |
|
109 |
||
110 |
||
111 |
(* utility functions *) |
|
112 |
||
113 |
val quantifier = (fn |
|
114 |
@{const_name All} => SOME SForall |
|
115 |
| @{const_name Ex} => SOME SExists |
|
116 |
| _ => NONE) |
|
117 |
||
118 |
fun group_quant qname Ts (t as Const (q, _) $ Abs (_, T, u)) = |
|
119 |
if q = qname then group_quant qname (T :: Ts) u else (Ts, t) |
|
120 |
| group_quant _ Ts t = (Ts, t) |
|
121 |
||
40664 | 122 |
fun dest_weight (@{const SMT.weight} $ w $ t) = |
123 |
(SOME (snd (HOLogic.dest_number w)), t) |
|
124 |
| dest_weight t = (NONE, t) |
|
125 |
||
37124 | 126 |
fun dest_pat (Const (@{const_name pat}, _) $ t) = (t, true) |
127 |
| dest_pat (Const (@{const_name nopat}, _) $ t) = (t, false) |
|
128 |
| dest_pat t = raise TERM ("dest_pat", [t]) |
|
129 |
||
130 |
fun dest_pats [] = I |
|
131 |
| dest_pats ts = |
|
132 |
(case map dest_pat ts |> split_list ||> distinct (op =) of |
|
133 |
(ps, [true]) => cons (SPat ps) |
|
134 |
| (ps, [false]) => cons (SNoPat ps) |
|
135 |
| _ => raise TERM ("dest_pats", ts)) |
|
36898 | 136 |
|
40579
98ebd2300823
use the const antiquotation for constants (this checks that the constant is declared, whereas the more general term antiquotation treats undeclared names as free variable)
boehmes
parents:
40274
diff
changeset
|
137 |
fun dest_trigger (@{const trigger} $ tl $ t) = |
37124 | 138 |
(rev (fold (dest_pats o HOLogic.dest_list) (HOLogic.dest_list tl) []), t) |
36898 | 139 |
| dest_trigger t = ([], t) |
140 |
||
141 |
fun dest_quant qn T t = quantifier qn |> Option.map (fn q => |
|
142 |
let |
|
143 |
val (Ts, u) = group_quant qn [T] t |
|
40664 | 144 |
val (ps, p) = dest_trigger u |
145 |
val (w, b) = dest_weight p |
|
146 |
in (q, rev Ts, ps, w, b) end) |
|
36898 | 147 |
|
148 |
fun fold_map_pat f (SPat ts) = fold_map f ts #>> SPat |
|
149 |
| fold_map_pat f (SNoPat ts) = fold_map f ts #>> SNoPat |
|
150 |
||
151 |
fun prop_of thm = HOLogic.dest_Trueprop (Thm.prop_of thm) |
|
152 |
||
153 |
||
154 |
||
155 |
(* enforce a strict separation between formulas and terms *) |
|
156 |
||
37124 | 157 |
val term_eq_rewr = @{lemma "term_eq x y == x = y" by (simp add: term_eq_def)} |
36898 | 158 |
|
37124 | 159 |
val term_bool = @{lemma "~(term_eq True False)" by (simp add: term_eq_def)} |
36898 | 160 |
val term_bool' = Simplifier.rewrite_rule [term_eq_rewr] term_bool |
161 |
||
162 |
||
163 |
val needs_rewrite = Thm.prop_of #> Term.exists_subterm (fn |
|
164 |
Const (@{const_name Let}, _) => true |
|
40579
98ebd2300823
use the const antiquotation for constants (this checks that the constant is declared, whereas the more general term antiquotation treats undeclared names as free variable)
boehmes
parents:
40274
diff
changeset
|
165 |
| @{const HOL.eq (bool)} $ _ $ @{const True} => true |
98ebd2300823
use the const antiquotation for constants (this checks that the constant is declared, whereas the more general term antiquotation treats undeclared names as free variable)
boehmes
parents:
40274
diff
changeset
|
166 |
| Const (@{const_name If}, _) $ _ $ @{const True} $ @{const False} => true |
36898 | 167 |
| _ => false) |
168 |
||
169 |
val rewrite_rules = [ |
|
170 |
Let_def, |
|
171 |
@{lemma "P = True == P" by (rule eq_reflection) simp}, |
|
172 |
@{lemma "if P then True else False == P" by (rule eq_reflection) simp}] |
|
173 |
||
174 |
fun rewrite ctxt = Simplifier.full_rewrite |
|
175 |
(Simplifier.context ctxt empty_ss addsimps rewrite_rules) |
|
176 |
||
177 |
fun normalize ctxt thm = |
|
178 |
if needs_rewrite thm then Conv.fconv_rule (rewrite ctxt) thm else thm |
|
179 |
||
180 |
val unfold_rules = term_eq_rewr :: rewrite_rules |
|
181 |
||
182 |
||
183 |
val revert_types = |
|
184 |
let |
|
185 |
fun revert @{typ prop} = @{typ bool} |
|
186 |
| revert (Type (n, Ts)) = Type (n, map revert Ts) |
|
187 |
| revert T = T |
|
188 |
in Term.map_types revert end |
|
189 |
||
190 |
||
191 |
fun strictify {is_builtin_conn, is_builtin_pred, is_builtin_distinct} ctxt = |
|
192 |
let |
|
193 |
fun is_builtin_conn' (@{const_name True}, _) = false |
|
194 |
| is_builtin_conn' (@{const_name False}, _) = false |
|
195 |
| is_builtin_conn' c = is_builtin_conn c |
|
196 |
||
197 |
val propT = @{typ prop} and boolT = @{typ bool} |
|
198 |
val as_propT = (fn @{typ bool} => propT | T => T) |
|
199 |
fun mapTs f g = Term.strip_type #> (fn (Ts, T) => map f Ts ---> g T) |
|
200 |
fun conn (n, T) = (n, mapTs as_propT as_propT T) |
|
201 |
fun pred (n, T) = (n, mapTs I as_propT T) |
|
202 |
||
40579
98ebd2300823
use the const antiquotation for constants (this checks that the constant is declared, whereas the more general term antiquotation treats undeclared names as free variable)
boehmes
parents:
40274
diff
changeset
|
203 |
val term_eq = @{const HOL.eq (bool)} |> Term.dest_Const |> pred |
98ebd2300823
use the const antiquotation for constants (this checks that the constant is declared, whereas the more general term antiquotation treats undeclared names as free variable)
boehmes
parents:
40274
diff
changeset
|
204 |
fun as_term t = Const term_eq $ t $ @{const True} |
36898 | 205 |
|
206 |
val if_term = Const (@{const_name If}, [propT, boolT, boolT] ---> boolT) |
|
40579
98ebd2300823
use the const antiquotation for constants (this checks that the constant is declared, whereas the more general term antiquotation treats undeclared names as free variable)
boehmes
parents:
40274
diff
changeset
|
207 |
fun wrap_in_if t = if_term $ t $ @{const True} $ @{const False} |
36898 | 208 |
|
209 |
fun in_list T f t = HOLogic.mk_list T (map f (HOLogic.dest_list t)) |
|
210 |
||
211 |
fun in_term t = |
|
212 |
(case Term.strip_comb t of |
|
213 |
(c as Const (@{const_name If}, _), [t1, t2, t3]) => |
|
214 |
c $ in_form t1 $ in_term t2 $ in_term t3 |
|
215 |
| (h as Const c, ts) => |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
216 |
if is_builtin_conn' (conn c) orelse is_builtin_pred ctxt (pred c) |
36898 | 217 |
then wrap_in_if (in_form t) |
218 |
else Term.list_comb (h, map in_term ts) |
|
219 |
| (h as Free _, ts) => Term.list_comb (h, map in_term ts) |
|
220 |
| _ => t) |
|
221 |
||
40664 | 222 |
and in_weight ((c as @{const SMT.weight}) $ w $ t) = c $ w $ in_form t |
223 |
| in_weight t = in_form t |
|
224 |
||
36898 | 225 |
and in_pat ((c as Const (@{const_name pat}, _)) $ t) = c $ in_term t |
226 |
| in_pat ((c as Const (@{const_name nopat}, _)) $ t) = c $ in_term t |
|
227 |
| in_pat t = raise TERM ("in_pat", [t]) |
|
228 |
||
37124 | 229 |
and in_pats ps = |
230 |
in_list @{typ "pattern list"} (in_list @{typ pattern} in_pat) ps |
|
36898 | 231 |
|
40664 | 232 |
and in_trig ((c as @{const trigger}) $ p $ t) = c $ in_pats p $ in_weight t |
233 |
| in_trig t = in_weight t |
|
36898 | 234 |
|
235 |
and in_form t = |
|
236 |
(case Term.strip_comb t of |
|
237 |
(q as Const (qn, _), [Abs (n, T, t')]) => |
|
238 |
if is_some (quantifier qn) then q $ Abs (n, T, in_trig t') |
|
239 |
else as_term (in_term t) |
|
40274
6486c610a549
introduced SMT.distinct as a representation of the solvers' built-in predicate; check that SMT.distinct is always applied to an explicit list
boehmes
parents:
40161
diff
changeset
|
240 |
| (Const (c as (@{const_name SMT.distinct}, T)), [t']) => |
36898 | 241 |
if is_builtin_distinct then Const (pred c) $ in_list T in_term t' |
242 |
else as_term (in_term t) |
|
243 |
| (Const c, ts) => |
|
244 |
if is_builtin_conn (conn c) |
|
245 |
then Term.list_comb (Const (conn c), map in_form ts) |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
246 |
else if is_builtin_pred ctxt (pred c) |
36898 | 247 |
then Term.list_comb (Const (pred c), map in_term ts) |
248 |
else as_term (in_term t) |
|
249 |
| _ => as_term (in_term t)) |
|
250 |
in |
|
40161
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
251 |
map (apsnd (normalize ctxt)) #> (fn irules => |
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
252 |
((unfold_rules, (~1, term_bool') :: irules), |
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
253 |
map (in_form o prop_of o snd) ((~1, term_bool) :: irules))) |
36898 | 254 |
end |
255 |
||
256 |
||
257 |
||
258 |
(* translation from Isabelle terms into SMT intermediate terms *) |
|
259 |
||
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
260 |
val empty_context = (1, Typtab.empty, [], 1, Termtab.empty) |
36898 | 261 |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
262 |
fun make_sign header (_, typs, dtyps, _, terms) = { |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
263 |
header = header, |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
264 |
sorts = Typtab.fold (fn (_, (n, true)) => cons n | _ => I) typs [], |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
265 |
funcs = Termtab.fold (fn (_, (n, SOME ss)) => cons (n,ss) | _ => I) terms [], |
39435
5d18f4c00c07
reverse order of datatype declarations so that declarations only depend on already declared datatypes
boehmes
parents:
39298
diff
changeset
|
266 |
dtyps = rev dtyps } |
36898 | 267 |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
268 |
fun make_recon (unfolds, assms) (_, typs, _, _, terms) = { |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
269 |
typs = Symtab.make (map (apfst fst o swap) (Typtab.dest typs)), |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
270 |
(*FIXME: don't drop the datatype information! *) |
36898 | 271 |
terms = Symtab.make (map (fn (t, (n, _)) => (n, t)) (Termtab.dest terms)), |
272 |
unfolds = unfolds, |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
273 |
assms = assms } |
36898 | 274 |
|
275 |
fun string_of_index pre i = pre ^ string_of_int i |
|
276 |
||
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
277 |
fun new_typ sort_prefix proper T (Tidx, typs, dtyps, idx, terms) = |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
278 |
let val s = string_of_index sort_prefix Tidx |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
279 |
in (s, (Tidx+1, Typtab.update (T, (s, proper)) typs, dtyps, idx, terms)) end |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
280 |
|
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
281 |
fun lookup_typ (_, typs, _, _, _) = Typtab.lookup typs |
36898 | 282 |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
283 |
fun fresh_typ T f cx = |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
284 |
(case lookup_typ cx T of |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
285 |
SOME (s, _) => (s, cx) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
286 |
| NONE => f T cx) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
287 |
|
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
288 |
fun new_fun func_prefix t ss (Tidx, typs, dtyps, idx, terms) = |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
289 |
let |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
290 |
val f = string_of_index func_prefix idx |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
291 |
val terms' = Termtab.update (revert_types t, (f, ss)) terms |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
292 |
in (f, (Tidx, typs, dtyps, idx+1, terms')) end |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
293 |
|
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
294 |
fun fresh_fun func_prefix t ss (cx as (_, _, _, _, terms)) = |
36898 | 295 |
(case Termtab.lookup terms t of |
296 |
SOME (f, _) => (f, cx) |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
297 |
| NONE => new_fun func_prefix t ss cx) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
298 |
|
39483
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
299 |
fun mk_type (_, Tfs) (d as Datatype.DtTFree _) = the (AList.lookup (op =) Tfs d) |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
300 |
| mk_type Ts (Datatype.DtType (n, ds)) = Type (n, map (mk_type Ts) ds) |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
301 |
| mk_type (Tds, _) (Datatype.DtRec i) = nth Tds i |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
302 |
|
39483
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
303 |
fun mk_selector ctxt Ts T n (i, d) = |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
304 |
(case Datatype_Selectors.lookup_selector ctxt (n, i+1) of |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
305 |
NONE => raise Fail ("missing selector for datatype constructor " ^ quote n) |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
306 |
| SOME m => mk_type Ts d |> (fn U => (Const (m, T --> U), U))) |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
307 |
|
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
308 |
fun mk_constructor ctxt Ts T (n, args) = |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
309 |
let val (sels, Us) = split_list (map_index (mk_selector ctxt Ts T n) args) |
9f0e5684f04b
add full support for datatypes to the SMT interface (only used by Z3 in oracle mode so far); added store to keep track of datatype selector functions
boehmes
parents:
39435
diff
changeset
|
310 |
in (Const (n, Us ---> T), sels) end |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
311 |
|
39535
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
312 |
fun lookup_datatype ctxt n Ts = |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
313 |
if member (op =) [@{type_name bool}, @{type_name nat}] n then NONE |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
314 |
else |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
315 |
Datatype.get_info (ProofContext.theory_of ctxt) n |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
316 |
|> Option.map (fn {descr, ...} => |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
317 |
let |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
318 |
val Tds = map (fn (_, (tn, _, _)) => Type (tn, Ts)) |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
319 |
(sort (int_ord o pairself fst) descr) |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
320 |
val Tfs = (case hd descr of (_, (_, tfs, _)) => tfs ~~ Ts) |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
321 |
in |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
322 |
descr |> map (fn (i, (_, _, cs)) => |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
323 |
(nth Tds i, map (mk_constructor ctxt (Tds, Tfs) (nth Tds i)) cs)) |
cd1bb7125d8a
do not treat natural numbers as a datatype (natural numbers are considered an abstract type with a coercion to integers)
boehmes
parents:
39483
diff
changeset
|
324 |
end) |
36898 | 325 |
|
40161
539d07b00e5f
keep track of theorems initially given to SMT (even if they are rewritten); provide interface to filter theorems necessary for SMT proofs
boehmes
parents:
39535
diff
changeset
|
326 |
fun relaxed irules = (([], irules), map (prop_of o snd) irules) |
36898 | 327 |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
328 |
fun with_context header f (ths, ts) = |
36898 | 329 |
let val (us, context) = fold_map f ts empty_context |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
330 |
in ((make_sign (header ts) context, us), make_recon ths context) end |
36898 | 331 |
|
332 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
333 |
fun translate {prefixes, strict, header, builtins, serialize} ctxt comments = |
36898 | 334 |
let |
335 |
val {sort_prefix, func_prefix} = prefixes |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
336 |
val {builtin_typ, builtin_num, builtin_fun, has_datatypes} = builtins |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
337 |
|
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
338 |
fun transT (T as TFree _) = fresh_typ T (new_typ sort_prefix true) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
339 |
| transT (T as TVar _) = (fn _ => raise TYPE ("smt_translate", [T], [])) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
340 |
| transT (T as Type (n, Ts)) = |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
341 |
(case builtin_typ ctxt T of |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
342 |
SOME n => pair n |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
343 |
| NONE => fresh_typ T (fn _ => fn cx => |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
344 |
if not has_datatypes then new_typ sort_prefix true T cx |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
345 |
else |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
346 |
(case lookup_datatype ctxt n Ts of |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
347 |
NONE => new_typ sort_prefix true T cx |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
348 |
| SOME dts => |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
349 |
let val cx' = new_dtyps dts cx |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
350 |
in (fst (the (lookup_typ cx' T)), cx') end))) |
36898 | 351 |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
352 |
and new_dtyps dts cx = |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
353 |
let |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
354 |
fun new_decl i t = |
40663 | 355 |
let val (Ts, T) = U.dest_funT i (Term.fastype_of t) |
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
356 |
in |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
357 |
fold_map transT Ts ##>> transT T ##>> |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
358 |
new_fun func_prefix t NONE #>> swap |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
359 |
end |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
360 |
fun new_dtyp_decl (con, sels) = |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
361 |
new_decl (length sels) con ##>> fold_map (new_decl 1) sels #>> |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
362 |
(fn ((con', _), sels') => (con', map (apsnd snd) sels')) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
363 |
in |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
364 |
cx |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
365 |
|> fold_map (new_typ sort_prefix false o fst) dts |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
366 |
||>> fold_map (fold_map new_dtyp_decl o snd) dts |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
367 |
|-> (fn (ss, decls) => fn (Tidx, typs, dtyps, idx, terms) => |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
368 |
(Tidx, typs, (ss ~~ decls) :: dtyps, idx, terms)) |
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
369 |
end |
36898 | 370 |
|
371 |
fun app n ts = SApp (n, ts) |
|
372 |
||
373 |
fun trans t = |
|
374 |
(case Term.strip_comb t of |
|
375 |
(Const (qn, _), [Abs (_, T, t1)]) => |
|
376 |
(case dest_quant qn T t1 of |
|
40664 | 377 |
SOME (q, Ts, ps, w, b) => |
36898 | 378 |
fold_map transT Ts ##>> fold_map (fold_map_pat trans) ps ##>> |
40664 | 379 |
trans b #>> (fn ((Ts', ps'), b') => SQua (q, Ts', ps', w, b')) |
36898 | 380 |
| NONE => raise TERM ("intermediate", [t])) |
381 |
| (Const (@{const_name Let}, _), [t1, Abs (_, T, t2)]) => |
|
382 |
transT T ##>> trans t1 ##>> trans t2 #>> |
|
383 |
(fn ((U, u1), u2) => SLet (U, u1, u2)) |
|
40274
6486c610a549
introduced SMT.distinct as a representation of the solvers' built-in predicate; check that SMT.distinct is always applied to an explicit list
boehmes
parents:
40161
diff
changeset
|
384 |
| (h as Const (c as (@{const_name SMT.distinct}, T)), [t1]) => |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
385 |
(case builtin_fun ctxt c (HOLogic.dest_list t1) of |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
386 |
SOME (n, ts) => fold_map trans ts #>> app n |
36898 | 387 |
| NONE => transs h T [t1]) |
388 |
| (h as Const (c as (_, T)), ts) => |
|
389 |
(case try HOLogic.dest_number t of |
|
390 |
SOME (T, i) => |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
391 |
(case builtin_num ctxt T i of |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
392 |
SOME n => pair (SApp (n, [])) |
36898 | 393 |
| NONE => transs t T []) |
394 |
| NONE => |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
395 |
(case builtin_fun ctxt c ts of |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
396 |
SOME (n, ts') => fold_map trans ts' #>> app n |
36898 | 397 |
| NONE => transs h T ts)) |
398 |
| (h as Free (_, T), ts) => transs h T ts |
|
399 |
| (Bound i, []) => pair (SVar i) |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
400 |
| _ => raise TERM ("smt_translate", [t])) |
36898 | 401 |
|
402 |
and transs t T ts = |
|
40663 | 403 |
let val (Us, U) = U.dest_funT (length ts) T |
36898 | 404 |
in |
405 |
fold_map transT Us ##>> transT U #-> (fn Up => |
|
39298
5aefb5bc8a93
added preliminary support for SMT datatypes (for now restricted to tuples and lists); only the Z3 interface (in oracle mode) makes use of it, there is especially no Z3 proof reconstruction support for datatypes yet
boehmes
parents:
37124
diff
changeset
|
406 |
fresh_fun func_prefix t (SOME Up) ##>> fold_map trans ts #>> SApp) |
36898 | 407 |
end |
408 |
in |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
409 |
(case strict of SOME strct => strictify strct ctxt | NONE => relaxed) #> |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
410 |
with_context (header ctxt) trans #>> uncurry (serialize comments) |
36898 | 411 |
end |
412 |
||
413 |
end |