author | boehmes |
Sun, 19 Dec 2010 18:54:29 +0100 | |
changeset 41281 | 679118e35378 |
parent 41172 | a17c2d669c40 |
child 41328 | 6792a5c92a58 |
permissions | -rw-r--r-- |
36898 | 1 |
(* Title: HOL/Tools/SMT/z3_proof_tools.ML |
2 |
Author: Sascha Boehme, TU Muenchen |
|
3 |
||
4 |
Helper functions required for Z3 proof reconstruction. |
|
5 |
*) |
|
6 |
||
7 |
signature Z3_PROOF_TOOLS = |
|
8 |
sig |
|
41172
a17c2d669c40
the functions term_of and prop_of are also needed in earlier stages, not only for Z3 proof reconstruction, so they really belong in SMT_Utils
boehmes
parents:
41123
diff
changeset
|
9 |
(*modifying terms*) |
36898 | 10 |
val as_meta_eq: cterm -> cterm |
11 |
||
41123 | 12 |
(*theorem nets*) |
40164
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
13 |
val thm_net_of: ('a -> thm) -> 'a list -> 'a Net.net |
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
14 |
val net_instance': ((thm -> thm option) -> 'a -> 'a option) -> 'a Net.net -> |
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
15 |
cterm -> 'a option |
36898 | 16 |
val net_instance: thm Net.net -> cterm -> thm option |
17 |
||
41123 | 18 |
(*proof combinators*) |
36898 | 19 |
val under_assumption: (thm -> thm) -> cterm -> thm |
20 |
val with_conv: conv -> (cterm -> thm) -> cterm -> thm |
|
21 |
val discharge: thm -> thm -> thm |
|
22 |
val varify: string list -> thm -> thm |
|
23 |
val unfold_eqs: Proof.context -> thm list -> conv |
|
24 |
val match_instantiate: (cterm -> cterm) -> cterm -> thm -> thm |
|
25 |
val by_tac: (int -> tactic) -> cterm -> thm |
|
26 |
val make_hyp_def: thm -> Proof.context -> thm * Proof.context |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
27 |
val by_abstraction: bool * bool -> Proof.context -> thm list -> |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
28 |
(Proof.context -> cterm -> thm) -> cterm -> thm |
36898 | 29 |
|
41123 | 30 |
(*a faster COMP*) |
36898 | 31 |
type compose_data |
32 |
val precompose: (cterm -> cterm list) -> thm -> compose_data |
|
33 |
val precompose2: (cterm -> cterm * cterm) -> thm -> compose_data |
|
34 |
val compose: compose_data -> thm -> thm |
|
35 |
||
41123 | 36 |
(*unfolding of 'distinct'*) |
36898 | 37 |
val unfold_distinct_conv: conv |
38 |
||
41123 | 39 |
(*simpset*) |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
40 |
val add_simproc: Simplifier.simproc -> Context.generic -> Context.generic |
36898 | 41 |
val make_simpset: Proof.context -> thm list -> simpset |
42 |
end |
|
43 |
||
44 |
structure Z3_Proof_Tools: Z3_PROOF_TOOLS = |
|
45 |
struct |
|
46 |
||
40662
798aad2229c0
added prove reconstruction for injective functions;
boehmes
parents:
40579
diff
changeset
|
47 |
structure U = SMT_Utils |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
48 |
structure I = Z3_Interface |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
49 |
|
36898 | 50 |
|
51 |
||
41172
a17c2d669c40
the functions term_of and prop_of are also needed in earlier stages, not only for Z3 proof reconstruction, so they really belong in SMT_Utils
boehmes
parents:
41123
diff
changeset
|
52 |
(* modifying terms *) |
36898 | 53 |
|
40663 | 54 |
fun as_meta_eq ct = uncurry U.mk_cequals (Thm.dest_binop (U.dest_cprop ct)) |
36898 | 55 |
|
56 |
||
57 |
||
58 |
(* theorem nets *) |
|
59 |
||
40164
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
60 |
fun thm_net_of f xthms = |
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
61 |
let fun insert xthm = Net.insert_term (K false) (Thm.prop_of (f xthm), xthm) |
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
62 |
in fold insert xthms Net.empty end |
36898 | 63 |
|
64 |
fun maybe_instantiate ct thm = |
|
65 |
try Thm.first_order_match (Thm.cprop_of thm, ct) |
|
66 |
|> Option.map (fn inst => Thm.instantiate inst thm) |
|
67 |
||
40164
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
68 |
fun net_instance' f net ct = |
40806
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
69 |
let |
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
70 |
val xthms = Net.match_term net (Thm.term_of ct) |
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
71 |
fun first_of f ct = get_first (f (maybe_instantiate ct)) xthms |
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
72 |
fun first_of' f ct = |
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
73 |
let val thm = Thm.trivial ct |
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
74 |
in get_first (f (try (fn rule => rule COMP thm))) xthms end |
59d96f777da3
also support higher-order rules for Z3 proof reconstruction
boehmes
parents:
40681
diff
changeset
|
75 |
in (case first_of f ct of NONE => first_of' f ct | some_thm => some_thm) end |
40164
57f5db2a48a3
added a mode to only filter assumptions used in a Z3 proof (in which no proof reconstruction is performed)
boehmes
parents:
38864
diff
changeset
|
76 |
val net_instance = net_instance' I |
36898 | 77 |
|
78 |
||
79 |
||
80 |
(* proof combinators *) |
|
81 |
||
82 |
fun under_assumption f ct = |
|
40663 | 83 |
let val ct' = U.mk_cprop ct |
36898 | 84 |
in Thm.implies_intr ct' (f (Thm.assume ct')) end |
85 |
||
86 |
fun with_conv conv prove ct = |
|
87 |
let val eq = Thm.symmetric (conv ct) |
|
88 |
in Thm.equal_elim eq (prove (Thm.lhs_of eq)) end |
|
89 |
||
90 |
fun discharge p pq = Thm.implies_elim pq p |
|
91 |
||
92 |
fun varify vars = Drule.generalize ([], vars) |
|
93 |
||
94 |
fun unfold_eqs _ [] = Conv.all_conv |
|
95 |
| unfold_eqs ctxt eqs = |
|
36936
c52d1c130898
incorporated further conversions and conversionals, after some minor tuning;
wenzelm
parents:
36899
diff
changeset
|
96 |
Conv.top_sweep_conv (K (Conv.rewrs_conv eqs)) ctxt |
36898 | 97 |
|
98 |
fun match_instantiate f ct thm = |
|
99 |
Thm.instantiate (Thm.match (f (Thm.cprop_of thm), ct)) thm |
|
100 |
||
101 |
fun by_tac tac ct = Goal.norm_result (Goal.prove_internal [] ct (K (tac 1))) |
|
102 |
||
41123 | 103 |
(* |
104 |
|- c x == t x ==> P (c x) |
|
105 |
--------------------------- |
|
106 |
c == t |- P (c x) |
|
107 |
*) |
|
36898 | 108 |
fun make_hyp_def thm ctxt = |
109 |
let |
|
110 |
val (lhs, rhs) = Thm.dest_binop (Thm.cprem_of thm 1) |
|
111 |
val (cf, cvs) = Drule.strip_comb lhs |
|
40662
798aad2229c0
added prove reconstruction for injective functions;
boehmes
parents:
40579
diff
changeset
|
112 |
val eq = U.mk_cequals cf (fold_rev Thm.cabs cvs rhs) |
36898 | 113 |
fun apply cv th = |
114 |
Thm.combination th (Thm.reflexive cv) |
|
115 |
|> Conv.fconv_rule (Conv.arg_conv (Thm.beta_conversion false)) |
|
116 |
in |
|
117 |
yield_singleton Assumption.add_assumes eq ctxt |
|
118 |
|>> Thm.implies_elim thm o fold apply cvs |
|
119 |
end |
|
120 |
||
121 |
||
122 |
||
123 |
(* abstraction *) |
|
124 |
||
125 |
local |
|
126 |
||
127 |
fun abs_context ctxt = (ctxt, Termtab.empty, 1, false) |
|
128 |
||
129 |
fun context_of (ctxt, _, _, _) = ctxt |
|
130 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
131 |
fun replace (_, (cv, ct)) = Thm.forall_elim ct o Thm.forall_intr cv |
36898 | 132 |
|
133 |
fun abs_instantiate (_, tab, _, beta_norm) = |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
134 |
fold replace (Termtab.dest tab) #> |
36898 | 135 |
beta_norm ? Conv.fconv_rule (Thm.beta_conversion true) |
136 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
137 |
fun lambda_abstract cvs t = |
36898 | 138 |
let |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
139 |
val frees = map Free (Term.add_frees t []) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
140 |
val cvs' = filter (fn cv => member (op aconv) frees (Thm.term_of cv)) cvs |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
141 |
val vs = map (Term.dest_Free o Thm.term_of) cvs' |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
142 |
in (Term.list_abs_free (vs, t), cvs') end |
36898 | 143 |
|
144 |
fun fresh_abstraction cvs ct (cx as (ctxt, tab, idx, beta_norm)) = |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
145 |
let val (t, cvs') = lambda_abstract cvs (Thm.term_of ct) |
36898 | 146 |
in |
147 |
(case Termtab.lookup tab t of |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
148 |
SOME (cv, _) => (Drule.list_comb (cv, cvs'), cx) |
36898 | 149 |
| NONE => |
150 |
let |
|
151 |
val (n, ctxt') = yield_singleton Variable.variant_fixes "x" ctxt |
|
40663 | 152 |
val cv = U.certify ctxt' |
153 |
(Free (n, map U.typ_of cvs' ---> U.typ_of ct)) |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
154 |
val cu = Drule.list_comb (cv, cvs') |
36898 | 155 |
val e = (t, (cv, fold_rev Thm.cabs cvs' ct)) |
156 |
val beta_norm' = beta_norm orelse not (null cvs') |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
157 |
in (cu, (ctxt', Termtab.update e tab, idx + 1, beta_norm')) end) |
36898 | 158 |
end |
159 |
||
160 |
fun abs_comb f g cvs ct = |
|
161 |
let val (cf, cu) = Thm.dest_comb ct |
|
162 |
in f cvs cf ##>> g cvs cu #>> uncurry Thm.capply end |
|
163 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
164 |
fun abs_arg f = abs_comb (K pair) f |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
165 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
166 |
fun abs_args f cvs ct = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
167 |
(case Thm.term_of ct of |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
168 |
_ $ _ => abs_comb (abs_args f) f cvs ct |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
169 |
| _ => pair ct) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
170 |
|
36898 | 171 |
fun abs_list f g cvs ct = |
172 |
(case Thm.term_of ct of |
|
173 |
Const (@{const_name Nil}, _) => pair ct |
|
174 |
| Const (@{const_name Cons}, _) $ _ $ _ => |
|
175 |
abs_comb (abs_arg f) (abs_list f g) cvs ct |
|
176 |
| _ => g cvs ct) |
|
177 |
||
178 |
fun abs_abs f cvs ct = |
|
179 |
let val (cv, cu) = Thm.dest_abs NONE ct |
|
180 |
in f (cv :: cvs) cu #>> Thm.cabs cv end |
|
181 |
||
182 |
val is_atomic = (fn _ $ _ => false | Abs _ => false | _ => true) |
|
183 |
||
184 |
fun abstract (ext_logic, with_theories) = |
|
185 |
let |
|
186 |
fun abstr1 cvs ct = abs_arg abstr cvs ct |
|
187 |
and abstr2 cvs ct = abs_comb abstr1 abstr cvs ct |
|
188 |
and abstr3 cvs ct = abs_comb abstr2 abstr cvs ct |
|
189 |
and abstr_abs cvs ct = abs_arg (abs_abs abstr) cvs ct |
|
190 |
||
191 |
and abstr cvs ct = |
|
192 |
(case Thm.term_of ct of |
|
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
|
193 |
@{const Trueprop} $ _ => abstr1 cvs ct |
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
|
194 |
| @{const "==>"} $ _ $ _ => abstr2 cvs ct |
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
|
195 |
| @{const True} => pair ct |
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
|
196 |
| @{const False} => pair ct |
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
|
197 |
| @{const Not} $ _ => abstr1 cvs ct |
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
|
198 |
| @{const HOL.conj} $ _ $ _ => abstr2 cvs ct |
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
|
199 |
| @{const HOL.disj} $ _ $ _ => abstr2 cvs ct |
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
|
200 |
| @{const HOL.implies} $ _ $ _ => abstr2 cvs ct |
38864
4abe644fcea5
formerly unnamed infix equality now named HOL.eq
haftmann
parents:
38795
diff
changeset
|
201 |
| Const (@{const_name HOL.eq}, _) $ _ $ _ => abstr2 cvs ct |
40681
872b08416fb4
be more precise: only treat constant 'distinct' applied to an explicit list as built-in
boehmes
parents:
40663
diff
changeset
|
202 |
| Const (@{const_name distinct}, _) $ _ => |
36898 | 203 |
if ext_logic then abs_arg (abs_list abstr fresh_abstraction) cvs ct |
204 |
else fresh_abstraction cvs ct |
|
205 |
| Const (@{const_name If}, _) $ _ $ _ $ _ => |
|
206 |
if ext_logic then abstr3 cvs ct else fresh_abstraction cvs ct |
|
207 |
| Const (@{const_name All}, _) $ _ => |
|
208 |
if ext_logic then abstr_abs cvs ct else fresh_abstraction cvs ct |
|
209 |
| Const (@{const_name Ex}, _) $ _ => |
|
210 |
if ext_logic then abstr_abs cvs ct else fresh_abstraction cvs ct |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
211 |
| t => (fn cx => |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
212 |
if is_atomic t orelse can HOLogic.dest_number t then (ct, cx) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
213 |
else if with_theories andalso |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
214 |
I.is_builtin_theory_term (context_of cx) t |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
215 |
then abs_args abstr cvs ct cx |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
216 |
else fresh_abstraction cvs ct cx)) |
36898 | 217 |
in abstr [] end |
218 |
||
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
|
219 |
val cimp = Thm.cterm_of @{theory} @{const "==>"} |
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
|
220 |
|
36898 | 221 |
fun with_prems thms f ct = |
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
|
222 |
fold_rev (Thm.mk_binop cimp o Thm.cprop_of) thms ct |
36898 | 223 |
|> f |
224 |
|> fold (fn prem => fn th => Thm.implies_elim th prem) thms |
|
225 |
||
226 |
in |
|
227 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
228 |
fun by_abstraction mode ctxt thms prove = with_prems thms (fn ct => |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
229 |
let val (cu, cx) = abstract mode ct (abs_context ctxt) |
36898 | 230 |
in abs_instantiate cx (prove (context_of cx) cu) end) |
231 |
||
232 |
end |
|
233 |
||
234 |
||
235 |
||
236 |
(* a faster COMP *) |
|
237 |
||
238 |
type compose_data = cterm list * (cterm -> cterm list) * thm |
|
239 |
||
240 |
fun list2 (x, y) = [x, y] |
|
241 |
||
242 |
fun precompose f rule = (f (Thm.cprem_of rule 1), f, rule) |
|
243 |
fun precompose2 f rule = precompose (list2 o f) rule |
|
244 |
||
245 |
fun compose (cvs, f, rule) thm = |
|
246 |
discharge thm (Thm.instantiate ([], cvs ~~ f (Thm.cprop_of thm)) rule) |
|
247 |
||
248 |
||
249 |
||
250 |
(* unfolding of 'distinct' *) |
|
251 |
||
252 |
local |
|
253 |
val set1 = @{lemma "x ~: set [] == ~False" by simp} |
|
254 |
val set2 = @{lemma "x ~: set [x] == False" by simp} |
|
255 |
val set3 = @{lemma "x ~: set [y] == x ~= y" by simp} |
|
256 |
val set4 = @{lemma "x ~: set (x # ys) == False" by simp} |
|
257 |
val set5 = @{lemma "x ~: set (y # ys) == x ~= y & x ~: set ys" by simp} |
|
258 |
||
259 |
fun set_conv ct = |
|
36936
c52d1c130898
incorporated further conversions and conversionals, after some minor tuning;
wenzelm
parents:
36899
diff
changeset
|
260 |
(Conv.rewrs_conv [set1, set2, set3, set4] else_conv |
36898 | 261 |
(Conv.rewr_conv set5 then_conv Conv.arg_conv set_conv)) ct |
262 |
||
40681
872b08416fb4
be more precise: only treat constant 'distinct' applied to an explicit list as built-in
boehmes
parents:
40663
diff
changeset
|
263 |
val dist1 = @{lemma "distinct [] == ~False" by (simp add: distinct_def)} |
872b08416fb4
be more precise: only treat constant 'distinct' applied to an explicit list as built-in
boehmes
parents:
40663
diff
changeset
|
264 |
val dist2 = @{lemma "distinct [x] == ~False" by (simp add: distinct_def)} |
872b08416fb4
be more precise: only treat constant 'distinct' applied to an explicit list as built-in
boehmes
parents:
40663
diff
changeset
|
265 |
val dist3 = @{lemma "distinct (x # xs) == x ~: set xs & distinct xs" |
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:
40164
diff
changeset
|
266 |
by (simp add: distinct_def)} |
36898 | 267 |
|
268 |
fun binop_conv cv1 cv2 = Conv.combination_conv (Conv.arg_conv cv1) cv2 |
|
269 |
in |
|
270 |
fun unfold_distinct_conv ct = |
|
36936
c52d1c130898
incorporated further conversions and conversionals, after some minor tuning;
wenzelm
parents:
36899
diff
changeset
|
271 |
(Conv.rewrs_conv [dist1, dist2] else_conv |
36898 | 272 |
(Conv.rewr_conv dist3 then_conv binop_conv set_conv unfold_distinct_conv)) ct |
273 |
end |
|
274 |
||
275 |
||
276 |
||
277 |
(* simpset *) |
|
278 |
||
279 |
local |
|
280 |
val antisym_le1 = mk_meta_eq @{thm order_class.antisym_conv} |
|
281 |
val antisym_le2 = mk_meta_eq @{thm linorder_class.antisym_conv2} |
|
282 |
val antisym_less1 = mk_meta_eq @{thm linorder_class.antisym_conv1} |
|
283 |
val antisym_less2 = mk_meta_eq @{thm linorder_class.antisym_conv3} |
|
284 |
||
285 |
fun eq_prop t thm = HOLogic.mk_Trueprop t aconv Thm.prop_of thm |
|
286 |
fun dest_binop ((c as Const _) $ t $ u) = (c, t, u) |
|
287 |
| dest_binop t = raise TERM ("dest_binop", [t]) |
|
288 |
||
289 |
fun prove_antisym_le ss t = |
|
290 |
let |
|
291 |
val (le, r, s) = dest_binop t |
|
292 |
val less = Const (@{const_name less}, Term.fastype_of le) |
|
293 |
val prems = Simplifier.prems_of_ss ss |
|
294 |
in |
|
295 |
(case find_first (eq_prop (le $ s $ r)) prems of |
|
296 |
NONE => |
|
297 |
find_first (eq_prop (HOLogic.mk_not (less $ r $ s))) prems |
|
298 |
|> Option.map (fn thm => thm RS antisym_less1) |
|
299 |
| SOME thm => SOME (thm RS antisym_le1)) |
|
300 |
end |
|
301 |
handle THM _ => NONE |
|
302 |
||
303 |
fun prove_antisym_less ss t = |
|
304 |
let |
|
305 |
val (less, r, s) = dest_binop (HOLogic.dest_not t) |
|
306 |
val le = Const (@{const_name less_eq}, Term.fastype_of less) |
|
307 |
val prems = prems_of_ss ss |
|
308 |
in |
|
309 |
(case find_first (eq_prop (le $ r $ s)) prems of |
|
310 |
NONE => |
|
311 |
find_first (eq_prop (HOLogic.mk_not (less $ s $ r))) prems |
|
312 |
|> Option.map (fn thm => thm RS antisym_less2) |
|
313 |
| SOME thm => SOME (thm RS antisym_le2)) |
|
314 |
end |
|
315 |
handle THM _ => NONE |
|
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
316 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
317 |
val basic_simpset = HOL_ss addsimps @{thms field_simps} |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
318 |
addsimps [@{thm times_divide_eq_right}, @{thm times_divide_eq_left}] |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
319 |
addsimps @{thms arith_special} addsimps @{thms less_bin_simps} |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
320 |
addsimps @{thms le_bin_simps} addsimps @{thms eq_bin_simps} |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
321 |
addsimps @{thms add_bin_simps} addsimps @{thms succ_bin_simps} |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
322 |
addsimps @{thms minus_bin_simps} addsimps @{thms pred_bin_simps} |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
323 |
addsimps @{thms mult_bin_simps} addsimps @{thms iszero_simps} |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
324 |
addsimps @{thms array_rules} |
41281
679118e35378
removed odd decoration of built-in symbols as Vars (instead provide built-in desctructor functions along with their inverse functions);
boehmes
parents:
41172
diff
changeset
|
325 |
addsimps @{thms term_true_def} addsimps @{thms term_false_def} |
37151 | 326 |
addsimps @{thms z3div_def} addsimps @{thms z3mod_def} |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
327 |
addsimprocs [ |
38715
6513ea67d95d
renamed Simplifier.simproc(_i) to Simplifier.simproc_global(_i) to emphasize that this is not the real thing;
wenzelm
parents:
37151
diff
changeset
|
328 |
Simplifier.simproc_global @{theory} "fast_int_arith" [ |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
329 |
"(m::int) < n", "(m::int) <= n", "(m::int) = n"] (K Lin_Arith.simproc), |
38715
6513ea67d95d
renamed Simplifier.simproc(_i) to Simplifier.simproc_global(_i) to emphasize that this is not the real thing;
wenzelm
parents:
37151
diff
changeset
|
330 |
Simplifier.simproc_global @{theory} "antisym_le" ["(x::'a::order) <= y"] |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
331 |
(K prove_antisym_le), |
38715
6513ea67d95d
renamed Simplifier.simproc(_i) to Simplifier.simproc_global(_i) to emphasize that this is not the real thing;
wenzelm
parents:
37151
diff
changeset
|
332 |
Simplifier.simproc_global @{theory} "antisym_less" ["~ (x::'a::linorder) < y"] |
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
333 |
(K prove_antisym_less)] |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
334 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
335 |
structure Simpset = Generic_Data |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
336 |
( |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
337 |
type T = simpset |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
338 |
val empty = basic_simpset |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
339 |
val extend = I |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
340 |
val merge = Simplifier.merge_ss |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
341 |
) |
36898 | 342 |
in |
343 |
||
36899
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
344 |
fun add_simproc simproc = Simpset.map (fn ss => ss addsimprocs [simproc]) |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
345 |
|
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
346 |
fun make_simpset ctxt rules = |
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
boehmes
parents:
36898
diff
changeset
|
347 |
Simplifier.context ctxt (Simpset.get (Context.Proof ctxt)) addsimps rules |
36898 | 348 |
|
349 |
end |
|
350 |
||
351 |
end |