6 |
6 |
7 theory SMT_Examples |
7 theory SMT_Examples |
8 imports Complex_Main |
8 imports Complex_Main |
9 begin |
9 begin |
10 |
10 |
11 declare [[smt2_certificates = "SMT_Examples.certs2"]] |
11 declare [[smt_certificates = "SMT_Examples.certs2"]] |
12 declare [[smt2_read_only_certificates = true]] |
12 declare [[smt_read_only_certificates = true]] |
13 |
13 |
14 |
14 |
15 section {* Propositional and first-order logic *} |
15 section {* Propositional and first-order logic *} |
16 |
16 |
17 lemma "True" by smt2 |
17 lemma "True" by smt |
18 lemma "p \<or> \<not>p" by smt2 |
18 lemma "p \<or> \<not>p" by smt |
19 lemma "(p \<and> True) = p" by smt2 |
19 lemma "(p \<and> True) = p" by smt |
20 lemma "(p \<or> q) \<and> \<not>p \<Longrightarrow> q" by smt2 |
20 lemma "(p \<or> q) \<and> \<not>p \<Longrightarrow> q" by smt |
21 lemma "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)" by smt2 |
21 lemma "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)" by smt |
22 lemma "(p1 \<and> p2) \<or> p3 \<longrightarrow> (p1 \<longrightarrow> (p3 \<and> p2) \<or> (p1 \<and> p3)) \<or> p1" by smt2 |
22 lemma "(p1 \<and> p2) \<or> p3 \<longrightarrow> (p1 \<longrightarrow> (p3 \<and> p2) \<or> (p1 \<and> p3)) \<or> p1" by smt |
23 lemma "P = P = P = P = P = P = P = P = P = P" by smt2 |
23 lemma "P = P = P = P = P = P = P = P = P = P" by smt |
24 |
24 |
25 lemma |
25 lemma |
26 assumes "a \<or> b \<or> c \<or> d" |
26 assumes "a \<or> b \<or> c \<or> d" |
27 and "e \<or> f \<or> (a \<and> d)" |
27 and "e \<or> f \<or> (a \<and> d)" |
28 and "\<not> (a \<or> (c \<and> ~c)) \<or> b" |
28 and "\<not> (a \<or> (c \<and> ~c)) \<or> b" |
29 and "\<not> (b \<and> (x \<or> \<not> x)) \<or> c" |
29 and "\<not> (b \<and> (x \<or> \<not> x)) \<or> c" |
30 and "\<not> (d \<or> False) \<or> c" |
30 and "\<not> (d \<or> False) \<or> c" |
31 and "\<not> (c \<or> (\<not> p \<and> (p \<or> (q \<and> \<not> q))))" |
31 and "\<not> (c \<or> (\<not> p \<and> (p \<or> (q \<and> \<not> q))))" |
32 shows False |
32 shows False |
33 using assms by smt2 |
33 using assms by smt |
34 |
34 |
35 axiomatization symm_f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where |
35 axiomatization symm_f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where |
36 symm_f: "symm_f x y = symm_f y x" |
36 symm_f: "symm_f x y = symm_f y x" |
37 |
37 |
38 lemma "a = a \<and> symm_f a b = symm_f b a" by (smt2 symm_f) |
38 lemma "a = a \<and> symm_f a b = symm_f b a" by (smt symm_f) |
39 |
39 |
40 (* |
40 (* |
41 Taken from ~~/src/HOL/ex/SAT_Examples.thy. |
41 Taken from ~~/src/HOL/ex/SAT_Examples.thy. |
42 Translated from TPTP problem library: PUZ015-2.006.dimacs |
42 Translated from TPTP problem library: PUZ015-2.006.dimacs |
43 *) |
43 *) |
225 and "~x27 \<or> ~x57" |
225 and "~x27 \<or> ~x57" |
226 and "~x29 \<or> ~x28" |
226 and "~x29 \<or> ~x28" |
227 and "~x29 \<or> ~x58" |
227 and "~x29 \<or> ~x58" |
228 and "~x28 \<or> ~x58" |
228 and "~x28 \<or> ~x58" |
229 shows False |
229 shows False |
230 using assms by smt2 |
230 using assms by smt |
231 |
231 |
232 lemma "\<forall>x::int. P x \<longrightarrow> (\<forall>y::int. P x \<or> P y)" |
232 lemma "\<forall>x::int. P x \<longrightarrow> (\<forall>y::int. P x \<or> P y)" |
233 by smt2 |
233 by smt |
234 |
234 |
235 lemma |
235 lemma |
236 assumes "(\<forall>x y. P x y = x)" |
236 assumes "(\<forall>x y. P x y = x)" |
237 shows "(\<exists>y. P x y) = P x c" |
237 shows "(\<exists>y. P x y) = P x c" |
238 using assms by smt2 |
238 using assms by smt |
239 |
239 |
240 lemma |
240 lemma |
241 assumes "(\<forall>x y. P x y = x)" |
241 assumes "(\<forall>x y. P x y = x)" |
242 and "(\<forall>x. \<exists>y. P x y) = (\<forall>x. P x c)" |
242 and "(\<forall>x. \<exists>y. P x y) = (\<forall>x. P x c)" |
243 shows "(EX y. P x y) = P x c" |
243 shows "(EX y. P x y) = P x c" |
244 using assms by smt2 |
244 using assms by smt |
245 |
245 |
246 lemma |
246 lemma |
247 assumes "if P x then \<not>(\<exists>y. P y) else (\<forall>y. \<not>P y)" |
247 assumes "if P x then \<not>(\<exists>y. P y) else (\<forall>y. \<not>P y)" |
248 shows "P x \<longrightarrow> P y" |
248 shows "P x \<longrightarrow> P y" |
249 using assms by smt2 |
249 using assms by smt |
250 |
250 |
251 |
251 |
252 section {* Arithmetic *} |
252 section {* Arithmetic *} |
253 |
253 |
254 subsection {* Linear arithmetic over integers and reals *} |
254 subsection {* Linear arithmetic over integers and reals *} |
255 |
255 |
256 lemma "(3::int) = 3" by smt2 |
256 lemma "(3::int) = 3" by smt |
257 lemma "(3::real) = 3" by smt2 |
257 lemma "(3::real) = 3" by smt |
258 lemma "(3 :: int) + 1 = 4" by smt2 |
258 lemma "(3 :: int) + 1 = 4" by smt |
259 lemma "x + (y + z) = y + (z + (x::int))" by smt2 |
259 lemma "x + (y + z) = y + (z + (x::int))" by smt |
260 lemma "max (3::int) 8 > 5" by smt2 |
260 lemma "max (3::int) 8 > 5" by smt |
261 lemma "abs (x :: real) + abs y \<ge> abs (x + y)" by smt2 |
261 lemma "abs (x :: real) + abs y \<ge> abs (x + y)" by smt |
262 lemma "P ((2::int) < 3) = P True" by smt2 |
262 lemma "P ((2::int) < 3) = P True" by smt |
263 lemma "x + 3 \<ge> 4 \<or> x < (1::int)" by smt2 |
263 lemma "x + 3 \<ge> 4 \<or> x < (1::int)" by smt |
264 |
264 |
265 lemma |
265 lemma |
266 assumes "x \<ge> (3::int)" and "y = x + 4" |
266 assumes "x \<ge> (3::int)" and "y = x + 4" |
267 shows "y - x > 0" |
267 shows "y - x > 0" |
268 using assms by smt2 |
268 using assms by smt |
269 |
269 |
270 lemma "let x = (2 :: int) in x + x \<noteq> 5" by smt2 |
270 lemma "let x = (2 :: int) in x + x \<noteq> 5" by smt |
271 |
271 |
272 lemma |
272 lemma |
273 fixes x :: real |
273 fixes x :: real |
274 assumes "3 * x + 7 * a < 4" and "3 < 2 * x" |
274 assumes "3 * x + 7 * a < 4" and "3 < 2 * x" |
275 shows "a < 0" |
275 shows "a < 0" |
276 using assms by smt2 |
276 using assms by smt |
277 |
277 |
278 lemma "(0 \<le> y + -1 * x \<or> \<not> 0 \<le> x \<or> 0 \<le> (x::int)) = (\<not> False)" by smt2 |
278 lemma "(0 \<le> y + -1 * x \<or> \<not> 0 \<le> x \<or> 0 \<le> (x::int)) = (\<not> False)" by smt |
279 |
279 |
280 lemma " |
280 lemma " |
281 (n < m \<and> m < n') \<or> (n < m \<and> m = n') \<or> (n < n' \<and> n' < m) \<or> |
281 (n < m \<and> m < n') \<or> (n < m \<and> m = n') \<or> (n < n' \<and> n' < m) \<or> |
282 (n = n' \<and> n' < m) \<or> (n = m \<and> m < n') \<or> |
282 (n = n' \<and> n' < m) \<or> (n = m \<and> m < n') \<or> |
283 (n' < m \<and> m < n) \<or> (n' < m \<and> m = n) \<or> |
283 (n' < m \<and> m < n) \<or> (n' < m \<and> m = n) \<or> |
284 (n' < n \<and> n < m) \<or> (n' = n \<and> n < m) \<or> (n' = m \<and> m < n) \<or> |
284 (n' < n \<and> n < m) \<or> (n' = n \<and> n < m) \<or> (n' = m \<and> m < n) \<or> |
285 (m < n \<and> n < n') \<or> (m < n \<and> n' = n) \<or> (m < n' \<and> n' < n) \<or> |
285 (m < n \<and> n < n') \<or> (m < n \<and> n' = n) \<or> (m < n' \<and> n' < n) \<or> |
286 (m = n \<and> n < n') \<or> (m = n' \<and> n' < n) \<or> |
286 (m = n \<and> n < n') \<or> (m = n' \<and> n' < n) \<or> |
287 (n' = m \<and> m = (n::int))" |
287 (n' = m \<and> m = (n::int))" |
288 by smt2 |
288 by smt |
289 |
289 |
290 text{* |
290 text{* |
291 The following example was taken from HOL/ex/PresburgerEx.thy, where it says: |
291 The following example was taken from HOL/ex/PresburgerEx.thy, where it says: |
292 |
292 |
293 This following theorem proves that all solutions to the |
293 This following theorem proves that all solutions to the |
305 |
305 |
306 lemma "\<lbrakk> x3 = abs x2 - x1; x4 = abs x3 - x2; x5 = abs x4 - x3; |
306 lemma "\<lbrakk> x3 = abs x2 - x1; x4 = abs x3 - x2; x5 = abs x4 - x3; |
307 x6 = abs x5 - x4; x7 = abs x6 - x5; x8 = abs x7 - x6; |
307 x6 = abs x5 - x4; x7 = abs x6 - x5; x8 = abs x7 - x6; |
308 x9 = abs x8 - x7; x10 = abs x9 - x8; x11 = abs x10 - x9 \<rbrakk> |
308 x9 = abs x8 - x7; x10 = abs x9 - x8; x11 = abs x10 - x9 \<rbrakk> |
309 \<Longrightarrow> x1 = x10 \<and> x2 = (x11::int)" |
309 \<Longrightarrow> x1 = x10 \<and> x2 = (x11::int)" |
310 by smt2 |
310 by smt |
311 |
311 |
312 |
312 |
313 lemma "let P = 2 * x + 1 > x + (x::real) in P \<or> False \<or> P" by smt2 |
313 lemma "let P = 2 * x + 1 > x + (x::real) in P \<or> False \<or> P" by smt |
314 |
314 |
315 lemma "x + (let y = x mod 2 in 2 * y + 1) \<ge> x + (1::int)" |
315 lemma "x + (let y = x mod 2 in 2 * y + 1) \<ge> x + (1::int)" |
316 using [[z3_new_extensions]] by smt2 |
316 using [[z3_extensions]] by smt |
317 |
317 |
318 lemma "x + (let y = x mod 2 in y + y) < x + (3::int)" |
318 lemma "x + (let y = x mod 2 in y + y) < x + (3::int)" |
319 using [[z3_new_extensions]] by smt2 |
319 using [[z3_extensions]] by smt |
320 |
320 |
321 lemma |
321 lemma |
322 assumes "x \<noteq> (0::real)" |
322 assumes "x \<noteq> (0::real)" |
323 shows "x + x \<noteq> (let P = (abs x > 1) in if P \<or> \<not> P then 4 else 2) * x" |
323 shows "x + x \<noteq> (let P = (abs x > 1) in if P \<or> \<not> P then 4 else 2) * x" |
324 using assms [[z3_new_extensions]] by smt2 |
324 using assms [[z3_extensions]] by smt |
325 |
325 |
326 lemma |
326 lemma |
327 assumes "(n + m) mod 2 = 0" and "n mod 4 = 3" |
327 assumes "(n + m) mod 2 = 0" and "n mod 4 = 3" |
328 shows "n mod 2 = 1 \<and> m mod 2 = (1::int)" |
328 shows "n mod 2 = 1 \<and> m mod 2 = (1::int)" |
329 using assms [[z3_new_extensions]] by smt2 |
329 using assms [[z3_extensions]] by smt |
330 |
330 |
331 |
331 |
332 subsection {* Linear arithmetic with quantifiers *} |
332 subsection {* Linear arithmetic with quantifiers *} |
333 |
333 |
334 lemma "~ (\<exists>x::int. False)" by smt2 |
334 lemma "~ (\<exists>x::int. False)" by smt |
335 lemma "~ (\<exists>x::real. False)" by smt2 |
335 lemma "~ (\<exists>x::real. False)" by smt |
336 |
336 |
337 lemma "\<exists>x::int. 0 < x" by smt2 |
337 lemma "\<exists>x::int. 0 < x" by smt |
338 |
338 |
339 lemma "\<exists>x::real. 0 < x" |
339 lemma "\<exists>x::real. 0 < x" |
340 using [[smt2_oracle=true]] (* no Z3 proof *) |
340 using [[smt_oracle=true]] (* no Z3 proof *) |
341 by smt2 |
341 by smt |
342 |
342 |
343 lemma "\<forall>x::int. \<exists>y. y > x" by smt2 |
343 lemma "\<forall>x::int. \<exists>y. y > x" by smt |
344 |
344 |
345 lemma "\<forall>x y::int. (x = 0 \<and> y = 1) \<longrightarrow> x \<noteq> y" by smt2 |
345 lemma "\<forall>x y::int. (x = 0 \<and> y = 1) \<longrightarrow> x \<noteq> y" by smt |
346 lemma "\<exists>x::int. \<forall>y. x < y \<longrightarrow> y < 0 \<or> y >= 0" by smt2 |
346 lemma "\<exists>x::int. \<forall>y. x < y \<longrightarrow> y < 0 \<or> y >= 0" by smt |
347 lemma "\<forall>x y::int. x < y \<longrightarrow> (2 * x + 1) < (2 * y)" by smt2 |
347 lemma "\<forall>x y::int. x < y \<longrightarrow> (2 * x + 1) < (2 * y)" by smt |
348 lemma "\<forall>x y::int. (2 * x + 1) \<noteq> (2 * y)" by smt2 |
348 lemma "\<forall>x y::int. (2 * x + 1) \<noteq> (2 * y)" by smt |
349 lemma "\<forall>x y::int. x + y > 2 \<or> x + y = 2 \<or> x + y < 2" by smt2 |
349 lemma "\<forall>x y::int. x + y > 2 \<or> x + y = 2 \<or> x + y < 2" by smt |
350 lemma "\<forall>x::int. if x > 0 then x + 1 > 0 else 1 > x" by smt2 |
350 lemma "\<forall>x::int. if x > 0 then x + 1 > 0 else 1 > x" by smt |
351 lemma "if (ALL x::int. x < 0 \<or> x > 0) then False else True" by smt2 |
351 lemma "if (ALL x::int. x < 0 \<or> x > 0) then False else True" by smt |
352 lemma "(if (ALL x::int. x < 0 \<or> x > 0) then -1 else 3) > (0::int)" by smt2 |
352 lemma "(if (ALL x::int. x < 0 \<or> x > 0) then -1 else 3) > (0::int)" by smt |
353 lemma "~ (\<exists>x y z::int. 4 * x + -6 * y = (1::int))" by smt2 |
353 lemma "~ (\<exists>x y z::int. 4 * x + -6 * y = (1::int))" by smt |
354 lemma "\<exists>x::int. \<forall>x y. 0 < x \<and> 0 < y \<longrightarrow> (0::int) < x + y" by smt2 |
354 lemma "\<exists>x::int. \<forall>x y. 0 < x \<and> 0 < y \<longrightarrow> (0::int) < x + y" by smt |
355 lemma "\<exists>u::int. \<forall>(x::int) y::real. 0 < x \<and> 0 < y \<longrightarrow> -1 < x" by smt2 |
355 lemma "\<exists>u::int. \<forall>(x::int) y::real. 0 < x \<and> 0 < y \<longrightarrow> -1 < x" by smt |
356 lemma "\<exists>x::int. (\<forall>y. y \<ge> x \<longrightarrow> y > 0) \<longrightarrow> x > 0" by smt2 |
356 lemma "\<exists>x::int. (\<forall>y. y \<ge> x \<longrightarrow> y > 0) \<longrightarrow> x > 0" by smt |
357 lemma "\<forall>x::int. |
357 lemma "\<forall>x::int. |
358 SMT2.trigger (SMT2.Symb_Cons (SMT2.Symb_Cons (SMT2.pat x) SMT2.Symb_Nil) SMT2.Symb_Nil) |
358 SMT.trigger (SMT.Symb_Cons (SMT.Symb_Cons (SMT.pat x) SMT.Symb_Nil) SMT.Symb_Nil) |
359 (x < a \<longrightarrow> 2 * x < 2 * a)" by smt2 |
359 (x < a \<longrightarrow> 2 * x < 2 * a)" by smt |
360 lemma "\<forall>(a::int) b::int. 0 < b \<or> b < 1" by smt2 |
360 lemma "\<forall>(a::int) b::int. 0 < b \<or> b < 1" by smt |
361 |
361 |
362 |
362 |
363 subsection {* Non-linear arithmetic over integers and reals *} |
363 subsection {* Non-linear arithmetic over integers and reals *} |
364 |
364 |
365 lemma "a > (0::int) \<Longrightarrow> a*b > 0 \<Longrightarrow> b > 0" |
365 lemma "a > (0::int) \<Longrightarrow> a*b > 0 \<Longrightarrow> b > 0" |
366 using [[smt2_oracle, z3_new_extensions]] |
366 using [[smt_oracle, z3_extensions]] |
367 by smt2 |
367 by smt |
368 |
368 |
369 lemma "(a::int) * (x + 1 + y) = a * x + a * (y + 1)" |
369 lemma "(a::int) * (x + 1 + y) = a * x + a * (y + 1)" |
370 using [[z3_new_extensions]] |
370 using [[z3_extensions]] |
371 by smt2 |
371 by smt |
372 |
372 |
373 lemma "((x::real) * (1 + y) - x * (1 - y)) = (2 * x * y)" |
373 lemma "((x::real) * (1 + y) - x * (1 - y)) = (2 * x * y)" |
374 using [[z3_new_extensions]] |
374 using [[z3_extensions]] |
375 by smt2 |
375 by smt |
376 |
376 |
377 lemma |
377 lemma |
378 "(U::int) + (1 + p) * (b + e) + p * d = |
378 "(U::int) + (1 + p) * (b + e) + p * d = |
379 U + (2 * (1 + p) * (b + e) + (1 + p) * d + d * p) - (1 + p) * (b + d + e)" |
379 U + (2 * (1 + p) * (b + e) + (1 + p) * d + d * p) - (1 + p) * (b + d + e)" |
380 using [[z3_new_extensions]] by smt2 |
380 using [[z3_extensions]] by smt |
381 |
381 |
382 lemma [z3_new_rule]: |
382 lemma [z3_rule]: |
383 fixes x :: "int" |
383 fixes x :: "int" |
384 assumes "x * y \<le> 0" and "\<not> y \<le> 0" and "\<not> x \<le> 0" |
384 assumes "x * y \<le> 0" and "\<not> y \<le> 0" and "\<not> x \<le> 0" |
385 shows False |
385 shows False |
386 using assms by (metis mult_le_0_iff) |
386 using assms by (metis mult_le_0_iff) |
387 |
387 |
388 |
388 |
389 section {* Pairs *} |
389 section {* Pairs *} |
390 |
390 |
391 lemma "fst (x, y) = a \<Longrightarrow> x = a" |
391 lemma "fst (x, y) = a \<Longrightarrow> x = a" |
392 using fst_conv by smt2 |
392 using fst_conv by smt |
393 |
393 |
394 lemma "p1 = (x, y) \<and> p2 = (y, x) \<Longrightarrow> fst p1 = snd p2" |
394 lemma "p1 = (x, y) \<and> p2 = (y, x) \<Longrightarrow> fst p1 = snd p2" |
395 using fst_conv snd_conv by smt2 |
395 using fst_conv snd_conv by smt |
396 |
396 |
397 |
397 |
398 section {* Higher-order problems and recursion *} |
398 section {* Higher-order problems and recursion *} |
399 |
399 |
400 lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> (f (i1 := v1, i2 := v2)) i = f i" |
400 lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> (f (i1 := v1, i2 := v2)) i = f i" |
401 using fun_upd_same fun_upd_apply by smt2 |
401 using fun_upd_same fun_upd_apply by smt |
402 |
402 |
403 lemma "(f g (x::'a::type) = (g x \<and> True)) \<or> (f g x = True) \<or> (g x = True)" |
403 lemma "(f g (x::'a::type) = (g x \<and> True)) \<or> (f g x = True) \<or> (g x = True)" |
404 by smt2 |
404 by smt |
405 |
405 |
406 lemma "id x = x \<and> id True = True" |
406 lemma "id x = x \<and> id True = True" |
407 by (smt2 id_def) |
407 by (smt id_def) |
408 |
408 |
409 lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> ((f (i1 := v1)) (i2 := v2)) i = f i" |
409 lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> ((f (i1 := v1)) (i2 := v2)) i = f i" |
410 using fun_upd_same fun_upd_apply by smt2 |
410 using fun_upd_same fun_upd_apply by smt |
411 |
411 |
412 lemma |
412 lemma |
413 "f (\<exists>x. g x) \<Longrightarrow> True" |
413 "f (\<exists>x. g x) \<Longrightarrow> True" |
414 "f (\<forall>x. g x) \<Longrightarrow> True" |
414 "f (\<forall>x. g x) \<Longrightarrow> True" |
415 by smt2+ |
415 by smt+ |
416 |
416 |
417 lemma True using let_rsp by smt2 |
417 lemma True using let_rsp by smt |
418 lemma "le = op \<le> \<Longrightarrow> le (3::int) 42" by smt2 |
418 lemma "le = op \<le> \<Longrightarrow> le (3::int) 42" by smt |
419 lemma "map (\<lambda>i::int. i + 1) [0, 1] = [1, 2]" by (smt2 list.map) |
419 lemma "map (\<lambda>i::int. i + 1) [0, 1] = [1, 2]" by (smt list.map) |
420 lemma "(ALL x. P x) \<or> ~ All P" by smt2 |
420 lemma "(ALL x. P x) \<or> ~ All P" by smt |
421 |
421 |
422 fun dec_10 :: "int \<Rightarrow> int" where |
422 fun dec_10 :: "int \<Rightarrow> int" where |
423 "dec_10 n = (if n < 10 then n else dec_10 (n - 10))" |
423 "dec_10 n = (if n < 10 then n else dec_10 (n - 10))" |
424 |
424 |
425 lemma "dec_10 (4 * dec_10 4) = 6" by (smt2 dec_10.simps) |
425 lemma "dec_10 (4 * dec_10 4) = 6" by (smt dec_10.simps) |
426 |
426 |
427 axiomatization |
427 axiomatization |
428 eval_dioph :: "int list \<Rightarrow> int list \<Rightarrow> int" |
428 eval_dioph :: "int list \<Rightarrow> int list \<Rightarrow> int" |
429 where |
429 where |
430 eval_dioph_mod: "eval_dioph ks xs mod n = eval_dioph ks (map (\<lambda>x. x mod n) xs) mod n" |
430 eval_dioph_mod: "eval_dioph ks xs mod n = eval_dioph ks (map (\<lambda>x. x mod n) xs) mod n" |
435 |
435 |
436 lemma |
436 lemma |
437 "(eval_dioph ks xs = l) = |
437 "(eval_dioph ks xs = l) = |
438 (eval_dioph ks (map (\<lambda>x. x mod 2) xs) mod 2 = l mod 2 \<and> |
438 (eval_dioph ks (map (\<lambda>x. x mod 2) xs) mod 2 = l mod 2 \<and> |
439 eval_dioph ks (map (\<lambda>x. x div 2) xs) = (l - eval_dioph ks (map (\<lambda>x. x mod 2) xs)) div 2)" |
439 eval_dioph ks (map (\<lambda>x. x div 2) xs) = (l - eval_dioph ks (map (\<lambda>x. x mod 2) xs)) div 2)" |
440 using [[smt2_oracle = true]] (*FIXME*) |
440 using [[smt_oracle = true]] (*FIXME*) |
441 using [[z3_new_extensions]] |
441 using [[z3_extensions]] |
442 by (smt2 eval_dioph_mod[where n=2] eval_dioph_div_mult[where n=2]) |
442 by (smt eval_dioph_mod[where n=2] eval_dioph_div_mult[where n=2]) |
443 |
443 |
444 |
444 |
445 context complete_lattice |
445 context complete_lattice |
446 begin |
446 begin |
447 |
447 |
448 lemma |
448 lemma |
449 assumes "Sup {a | i::bool. True} \<le> Sup {b | i::bool. True}" |
449 assumes "Sup {a | i::bool. True} \<le> Sup {b | i::bool. True}" |
450 and "Sup {b | i::bool. True} \<le> Sup {a | i::bool. True}" |
450 and "Sup {b | i::bool. True} \<le> Sup {a | i::bool. True}" |
451 shows "Sup {a | i::bool. True} \<le> Sup {a | i::bool. True}" |
451 shows "Sup {a | i::bool. True} \<le> Sup {a | i::bool. True}" |
452 using assms by (smt2 order_trans) |
452 using assms by (smt order_trans) |
453 |
453 |
454 end |
454 end |
455 |
455 |
456 |
456 |
457 section {* Monomorphization examples *} |
457 section {* Monomorphization examples *} |
458 |
458 |
459 definition Pred :: "'a \<Rightarrow> bool" where "Pred x = True" |
459 definition Pred :: "'a \<Rightarrow> bool" where "Pred x = True" |
460 |
460 |
461 lemma poly_Pred: "Pred x \<and> (Pred [x] \<or> \<not> Pred [x])" by (simp add: Pred_def) |
461 lemma poly_Pred: "Pred x \<and> (Pred [x] \<or> \<not> Pred [x])" by (simp add: Pred_def) |
462 |
462 |
463 lemma "Pred (1::int)" by (smt2 poly_Pred) |
463 lemma "Pred (1::int)" by (smt poly_Pred) |
464 |
464 |
465 axiomatization g :: "'a \<Rightarrow> nat" |
465 axiomatization g :: "'a \<Rightarrow> nat" |
466 axiomatization where |
466 axiomatization where |
467 g1: "g (Some x) = g [x]" and |
467 g1: "g (Some x) = g [x]" and |
468 g2: "g None = g []" and |
468 g2: "g None = g []" and |
469 g3: "g xs = length xs" |
469 g3: "g xs = length xs" |
470 |
470 |
471 lemma "g (Some (3::int)) = g (Some True)" by (smt2 g1 g2 g3 list.size) |
471 lemma "g (Some (3::int)) = g (Some True)" by (smt g1 g2 g3 list.size) |
472 |
472 |
473 end |
473 end |