section \<open>Propositional and first-order logic\<close>
lemma"True"by smt lemma"p \ \p" by smt lemma"(p \ True) = p" by smt lemma"(p \ q) \ \p \ q" by smt lemma"(a \ b) \ (c \ d) \ (a \ b) \ (c \ d)" by smt lemma"(p1 \ p2) \ p3 \ (p1 \ (p3 \ p2) \ (p1 \ p3)) \ p1" by smt lemma"P = P = P = P = P = P = P = P = P = P"by smt
lemma assumes"a \ b \ c \ d" and"e \ f \ (a \ d)" and"\ (a \ (c \ ~c)) \ b" and"\ (b \ (x \ \ x)) \ c" and"\ (d \ False) \ c" and"\ (c \ (\ p \ (p \ (q \ \ q))))" shows False using assms by smt
axiomatization symm_f :: "'a \ 'a \ 'a" where
symm_f: "symm_f x y = symm_f y x"
lemma"a = a \ symm_f a b = symm_f b a" by (smt symm_f)
lemma assumes"x \ (3::int)" and "y = x + 4" shows"y - x > 0" using assms by smt
lemma"let x = (2 :: int) in x + x \ 5" by smt
lemma fixes x :: real assumes"3 * x + 7 * a < 4"and"3 < 2 * x" shows"a < 0" using assms by smt
lemma"(0 \ y + -1 * x \ \ 0 \ x \ 0 \ (x::int)) = (\ False)" by smt
lemma"
(n < m \<and> m < n') \<or> (n < m \<and> m = n') \<or> (n < n' \<and> n' < m) \<or>
(n = n' \ n' < m) \ (n = m \ m < n') \
(n' < m \ m < n) \ (n' < m \ m = n) \
(n' < n \ n < m) \ (n' = n \ n < m) \ (n' = m \ m < n) \
(m < n \<and> n < n') \<or> (m < n \<and> n' = n) \<or> (m < n' \<and> n' < n) \<or>
(m = n \<and> n < n') \<or> (m = n' \<and> n' < n) \<or>
(n' = m \ m = (n::int))" by smt
text\<open>
The following example was taken from HOL/ex/PresburgerEx.thy, where it says:
This following theorem proves that all solutions to the
recurrence relation $x_{i+2} = |x_{i+1}| - x_i$ are periodic with
period 9. The example was brought to our attention by John
Harrison. It does does not require Presburger arithmetic but merely
quantifier-free linear arithmetic and holds for the rationals as well.
Warning: it takes (in 2006) over 4.2 minutes!
There, it is proved by"arith". SMT is able to prove this within a fraction
of one second. Withproof reconstruction, it takes about 13 seconds on a Core2
processor. \<close>
lemma"let P = 2 * x + 1 > x + (x::real) in P \ False \ P" by smt
lemma"x + (let y = x mod 2 in 2 * y + 1) \ x + (1::int)" using [[z3_extensions]] by smt
lemma"x + (let y = x mod 2 in y + y) < x + (3::int)" using [[z3_extensions]] by smt
lemma assumes"x \ (0::real)" shows"x + x \ (let P = (\x\ > 1) in if P \ \ P then 4 else 2) * x" using assms [[z3_extensions]] by smt
subsection \<open>Linear arithmetic with quantifiers\<close>
lemma"~ (\x::int. False)" by smt lemma"~ (\x::real. False)" by smt
lemma"\x::int. 0 < x" by smt
lemma"\x::real. 0 < x" using [[smt_oracle=true]] (* no Z3 proof *) by smt
lemma"\x::int. \y. y > x" by smt
lemma"\x y::int. (x = 0 \ y = 1) \ x \ y" by smt lemma"\x::int. \y. x < y \ y < 0 \ y >= 0" by smt lemma"\x y::int. x < y \ (2 * x + 1) < (2 * y)" by smt lemma"\x y::int. (2 * x + 1) \ (2 * y)" by smt lemma"\x y::int. x + y > 2 \ x + y = 2 \ x + y < 2" by smt lemma"\x::int. if x > 0 then x + 1 > 0 else 1 > x" by smt lemma"if (\x::int. x < 0 \ x > 0) then False else True" by smt lemma"(if (\x::int. x < 0 \ x > 0) then -1 else 3) > (0::int)" by smt lemma"~ (\x y z::int. 4 * x + -6 * y = (1::int))" by smt lemma"\x::int. \x y. 0 < x \ 0 < y \ (0::int) < x + y" by smt lemma"\u::int. \(x::int) y::real. 0 < x \ 0 < y \ -1 < x" by smt lemma"\x::int. (\y. y \ x \ y > 0) \ x > 0" by smt lemma"\(a::int) b::int. 0 < b \ b < 1" by smt
subsection \<open>Non-linear arithmetic over integers and reals\<close>
lemma"a > (0::int) \ a*b > 0 \ b > 0" using [[smt_oracle, z3_extensions]] by smt
lemma"(a::int) * (x + 1 + y) = a * x + a * (y + 1)" using [[z3_extensions]] by smt
lemma"((x::real) * (1 + y) - x * (1 - y)) = (2 * x * y)" using [[z3_extensions]] by smt
lemma "(U::int) + (1 + p) * (b + e) + p * d =
U + (2 * (1 + p) * (b + e) + (1 + p) * d + d * p) - (1 + p) * (b + d + e)" using [[z3_extensions]] by smt
lemma [z3_rule]: fixes x :: "int" assumes"x * y \ 0" and "\ y \ 0" and "\ x \ 0" shows False using assms by (metis mult_le_0_iff)
subsection \<open>Linear arithmetic for natural numbers\<close>
declare [[smt_nat_as_int]]
lemma"2 * (x::nat) \ 1" by smt
lemma"a < 3 \ (7::nat) > 2 * a" by smt
lemma"let x = (1::nat) + y in x - y > 0 * x"by smt
lemma "let x = (1::nat) + y in let P = (if x > 0 then True else False) in
False \<or> P = (x - 1 = y) \<or> (\<not>P \<longrightarrow> False)" by smt
lemma"int (nat \x::int\) = \x\" by (smt int_nat_eq)
definition prime_nat :: "nat \ bool" where "prime_nat p = (1 < p \ (\m. m dvd p --> m = 1 \ m = p))"
lemma"prime_nat (4*m + 1) \ m \ (1::nat)" by (smt prime_nat_def)
declare [[smt_nat_as_int = false]]
section \<open>Pairs\<close>
lemma"fst (x, y) = a \ x = a" using fst_conv by smt
lemma"p1 = (x, y) \ p2 = (y, x) \ fst p1 = snd p2" using fst_conv snd_conv by smt
section \<open>Higher-order problems and recursion\<close>
lemma"i \ i1 \ i \ i2 \ (f (i1 := v1, i2 := v2)) i = f i" using fun_upd_same fun_upd_apply by smt
lemma"(f g (x::'a::type) = (g x \ True)) \ (f g x = True) \ (g x = True)" by smt
lemma"id x = x \ id True = True" by (smt id_def)
lemma"i \ i1 \ i \ i2 \ ((f (i1 := v1)) (i2 := v2)) i = f i" using fun_upd_same fun_upd_apply by smt
lemma "f (\x. g x) \ True" "f (\x. g x) \ True" by smt+
lemma True using let_rsp by smt lemma"le = (\) \ le (3::int) 42" by smt lemma"map (\i::int. i + 1) [0, 1] = [1, 2]" by (smt list.map) lemma"(\x. P x) \ \ All P" by smt
fun dec_10 :: "int \ int" where "dec_10 n = (if n < 10 then n else dec_10 (n - 10))"
axiomatization
eval_dioph :: "int list \ int list \ int" where
eval_dioph_mod: "eval_dioph ks xs mod n = eval_dioph ks (map (\x. x mod n) xs) mod n" and
eval_dioph_div_mult: "eval_dioph ks (map (\x. x div n) xs) * n +
eval_dioph ks (map (\<lambda>x. x mod n) xs) = eval_dioph ks xs"
lemma "(eval_dioph ks xs = l) =
(eval_dioph ks (map (\<lambda>x. x mod 2) xs) mod 2 = l mod 2 \<and>
eval_dioph ks (map (\<lambda>x. x div 2) xs) = (l - eval_dioph ks (map (\<lambda>x. x mod 2) xs)) div 2)" using [[smt_oracle = true]] (*FIXME*) using [[z3_extensions]] by (smt eval_dioph_mod[where n=2] eval_dioph_div_mult[where n=2])
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.