(* Title: HOL/SMT_Examples/SMT_Examples_Verit.thy Author: Sascha Boehme, TU Muenchen Author: Mathias Fleury, JKU Half of the examples come from the corresponding file for z3, the others come from the Isabelle distribution or the AFP. *)
section‹Examples for the (smt (verit)) binding›
theory SMT_Examples_Verit imports Complex_Main begin
lemma assumes"x ≥ (3::int)"and"y = x + 4" shows"y - x > 0" using assms by (smt (verit))
lemma"let x = (2 :: int) in x + x ≠ 5"by (smt (verit))
lemma fixes x :: int assumes"3 * x + 7 * a < 4"and"3 < 2 * x" shows"a < 0" using assms by (smt (verit))
lemma"(0 ≤ y + -1 * x ∨¬ 0 ≤ x ∨ 0 ≤ (x::int)) = (¬ False)"by (smt (verit))
lemma" (n < m ∧ m < n') ∨ (n < m ∧ m = n') ∨ (n < n' ∧ n' < m) ∨ (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 ∧ n < n') ∨ (m < n ∧ n' = n) ∨ (m < n' ∧ n' < n) ∨ (m = n ∧ n < n') ∨ (m = n' ∧ n' < n) ∨ (n' = m ∧ m = (n::int))" by (smt (verit))
text‹ 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 (verit)) is able to prove this within a fraction of one second. With proof reconstruction, it takes about 13 seconds on a Core2 processor. ›
lemma "eq_set (List.coset xs) (set ys) = rhs" if"∧ys. subset' (List.coset xs) (set ys) = (let n = card (UNIV::'a set) in 0 < n ∧ card (set (xs @ ys)) = n)" and"∧uu A. (uu::'a) ∈ - A ==> uu ∉ A" and"∧uu. card (set (uu::'a list)) = length (remdups uu)" and"∧uu. finite (set (uu::'a list))" and"∧uu. (uu::'a) ∈ UNIV" and"(UNIV::'a set) ≠ {}" and"∧c A B P. [(c::'a) ∈ A ∪ B; c ∈ A ==> P; c ∈ B ==> P]==> P" and"∧a b. (a::nat) + b = b + a" and"∧a b. ((a::nat) = a + b) = (b = 0)" and"card' (set xs) = length (remdups xs)" and"card' = (card :: 'a set ==> nat)" and"∧A B. [finite (A::'a set); finite B]==> card A + card B = card (A ∪ B) + card (A ∩ B)" and"∧A. (card (A::'a set) = 0) = (A = {} ∨ infinite A)" and"∧A. [finite (UNIV::'a set); card (A::'a set) = card (UNIV::'a set)]==> A = UNIV" and"∧xs. - List.coset (xs::'a list) = set xs" and"∧xs. - set (xs::'a list) = List.coset xs" and"∧A B. (A ∩ B = {}) = (∀x. (x::'a) ∈ A ⟶ x ∉ B)" and"eq_set = (=)" and"∧A. finite (A::'a set) ==> finite (- A) = finite (UNIV::'a set)" and"rhs ≡ let n = card (UNIV::'a set) in if n = 0 then False else let xs' = remdups xs; ys' = remdups ys in length xs' + length ys' = n ∧ (∀x∈set xs'. x ∉ set ys') ∧ (∀y∈set ys'. y ∉ set xs')" and"∧xs ys. set ((xs::'a list) @ ys) = set xs ∪ set ys" and"∧A B. ((A::'a set) = B) = (A ⊆ B ∧ B ⊆ A)" and"∧xs. set (remdups (xs::'a list)) = set xs" and"subset' = (⊆)" and"∧A B. (∧x. (x::'a) ∈ A ==> x ∈ B) ==> A ⊆ B" and"∧A B. [(A::'a set) ⊆ B; B ⊆ A]==> A = B" and"∧A ys. (A ⊆ List.coset ys) = (∀y∈set ys. (y::'a) ∉ A)" using that by (smt (verit, default))
notepad begin have"line_integral F {i, j} g = line_integral F {i} g + line_integral F {j} g" if‹(k, g) ∈ one_chain_typeI› ‹∧A b B. ({} = (A::(real × real) set) ∩ insert (b::real × real) (B::(real × real) set)) = (b ∉ A ∧ {} = A ∩ B)› ‹finite ({} :: (real × real) set)› ‹∧a A. finite (A::(real × real) set) ==> finite (insert (a::real × real) A)› ‹(i::real × real) = (1::real, 0::real)› ‹∧a A. (a::real × real) ∈ (A::(real × real) set) ==> insert a A = A›‹j = (0, 1)› ‹∧x. (x::(real × real) set) ∩ {} = {}› ‹∧y x A. insert (x::real × real) (insert (y::real × real) (A::(real × real) set)) = insert y (insert x A)› ‹∧a A. insert (a::real × real) (A::(real × real) set) = {a} ∪ A› ‹∧F u basis2 basis1 γ. finite (u :: (real × real) set) ==> line_integral_exists F basis1 γ ==> line_integral_exists F basis2 γ ==> basis1 ∪ basis2 = u ==> basis1 ∩ basis2 = {} ==> line_integral F u γ = line_integral F basis1 γ + line_integral F basis2 γ› ‹one_chain_line_integral F {i} one_chain_typeI = one_chain_line_integral F {i} one_chain_typeII ∧ (∀(k, γ)∈one_chain_typeI. line_integral_exists F {i} γ) ∧ (∀(k, γ)∈one_chain_typeII. line_integral_exists F {i} γ)› ‹ one_chain_line_integral (F::real × real ==> real × real) {j::real × real} (one_chain_typeII::(int × (real ==> real × real)) set) = one_chain_line_integral F {j} (one_chain_typeI::(int × (real ==> real × real)) set) ∧ (∀(k::int, γ::real ==> real × real)∈one_chain_typeII. line_integral_exists F {j} γ) ∧ (∀(k::int, γ::real ==> real × real)∈one_chain_typeI. line_integral_exists F {j} γ)› for F i j g one_chain_typeI one_chain_typeII and
line_integral :: ‹(real × real ==> real × real) ==> (real × real) set ==> (real ==> real × real) ==> real›and
line_integral_exists :: ‹(real × real ==> real × real) ==> (real × real) set ==> (real ==> real × real) ==> bool›and
one_chain_line_integral :: ‹(real × real ==> real × real) ==> (real × real) set ==> (int × (real ==> real × real)) set ==> real›and
k using prod.case_eq_if singleton_inject snd_conv
that by (smt (verit)) end
lemma fixes x y z :: real assumes‹x + 2 * y > 0›and ‹x - 2 * y > 0›and ‹x 🚫› shows False using assms by (smt (verit))
(*test for arith reconstruction*) lemma fixes d :: real assumes‹0 🚫› ‹diamond_y ≡ λt. d / 2 - ∣t∣› ‹∧a b c :: real. (a / c 🚫 / c) = ((0 🚫⟶ a 🚫) ∧ (c 🚫⟶ b 🚫) ∧ c ≠ 0)› ‹∧a b c :: real. (a / c 🚫 / c) = ((0 🚫⟶ a 🚫) ∧ (c 🚫⟶ b 🚫) ∧ c ≠ 0)› ‹∧a b :: real. - a / b = - (a / b)› ‹∧a b :: real. - a * b = - (a * b)› ‹∧(x1 :: real) x2 y1 y2 :: real. ((x1, x2) = (y1, y2)) = (x1 = y1 ∧ x2 = y2)› shows‹(λy. (d / 2, (2 * y - 1) * diamond_y (d / 2))) ≠ (λx. ((x - 1 / 2) * d, - diamond_y ((x - 1 / 2) * d))) ==> (λy. (- (d / 2), (2 * y - 1) * diamond_y (- (d / 2)))) = (λx. ((x - 1 / 2) * d, diamond_y ((x - 1 / 2) * d))) ==> False› using assms by (smt (verit,del_insts))
lemma fixes d :: real assumes‹0 🚫› ‹diamond_y ≡ λt. d / 2 - ∣t∣› ‹∧a b c :: real. (a / c 🚫 / c) = ((0 🚫⟶ a 🚫) ∧ (c 🚫⟶ b 🚫) ∧ c ≠ 0)› ‹∧a b c :: real. (a / c 🚫 / c) = ((0 🚫⟶ a 🚫) ∧ (c 🚫⟶ b 🚫) ∧ c ≠ 0)› ‹∧a b :: real. - a / b = - (a / b)› ‹∧a b :: real. - a * b = - (a * b)› ‹∧(x1 :: real) x2 y1 y2 :: real. ((x1, x2) = (y1, y2)) = (x1 = y1 ∧ x2 = y2)› shows‹(λy. (d / 2, (2 * y - 1) * diamond_y (d / 2))) ≠ (λx. ((x - 1 / 2) * d, - diamond_y ((x - 1 / 2) * d))) ==> (λy. (- (d / 2), (2 * y - 1) * diamond_y (- (d / 2)))) = (λx. ((x - 1 / 2) * d, diamond_y ((x - 1 / 2) * d))) ==> False› using assms by (smt (verit,ccfv_threshold))
(*qnt_rm_unused example*) lemma assumes‹∀z y x. P z y› ‹P z y ==> False› shows False using assms by (smt (verit))
lemma "max (x::int) y ≥ y"
supply [[smt_trace]] by (smt (verit))+
context begin abbreviation finite' :: "'a set ==> bool" where"finite' A ≡ finite A ∧ A ≠ {}"
lemma fixes f :: "'b ==> 'c :: linorder" assumes ‹∀(S::'b::type set) f::'b::type ==> 'c::linorder. finite' S ⟶ arg_min_on f S ∈ S› ‹∀(S::'a::type set) f::'a::type ==> 'c::linorder. finite' S ⟶ arg_min_on f S ∈ S› ‹∀(S::'b::type set) (y::'b::type) f::'b::type ==> 'c::linorder. finite S ∧ S ≠ {} ∧ y ∈ S ⟶ f (arg_min_on f S) ≤ f y› ‹∀(S::'a::type set) (y::'a::type) f::'a::type ==> 'c::linorder. finite S ∧ S ≠ {} ∧ y ∈ S ⟶ f (arg_min_on f S) ≤ f y› ‹∀(f::'b::type ==> 'c::linorder) (g::'a::type ==> 'b::type) x::'a::type. (f ∘ g) x = f (g x)› ‹∀(F::'b::type set) h::'b::type ==> 'a::type. finite F ⟶ finite (h ` F)› ‹∀(F::'b::type set) h::'b::type ==> 'b::type. finite F ⟶ finite (h ` F)› ‹∀(F::'a::type set) h::'a::type ==> 'b::type. finite F ⟶ finite (h ` F)› ‹∀(F::'a::type set) h::'a::type ==> 'a::type. finite F ⟶ finite (h ` F)› ‹∀(b::'a::type) (f::'b::type ==> 'a::type) A::'b::type set. b ∈ f ` A ∧ (∀x::'b::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'b::type) (f::'b::type ==> 'b::type) A::'b::type set. b ∈ f ` A ∧ (∀x::'b::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'b::type) (f::'a::type ==> 'b::type) A::'a::type set. b ∈ f ` A ∧ (∀x::'a::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'a::type) (f::'a::type ==> 'a::type) A::'a::type set. b ∈ f ` A ∧ (∀x::'a::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'a::type) (f::'b::type ==> 'a::type) (x::'b::type) A::'b::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(b::'b::type) (f::'b::type ==> 'b::type) (x::'b::type) A::'b::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(b::'b::type) (f::'a::type ==> 'b::type) (x::'a::type) A::'a::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(b::'a::type) (f::'a::type ==> 'a::type) (x::'a::type) A::'a::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(f::'b::type ==> 'a::type) A::'b::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'b::type ==> 'b::type) A::'b::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'a::type ==> 'b::type) A::'a::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'a::type ==> 'a::type) A::'a::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'b::type ==> 'c::linorder) (A::'b::type set) (x::'b::type) y::'b::type. inj_on f A ∧ f x = f y ∧ x ∈ A ∧ y ∈ A ⟶ x = y› ‹∀(x::'c::linorder) y::'c::linorder. (x 🚫) = (x ≤ y ∧ x ≠ y)› ‹inj_on (f::'b::type ==> 'c::linorder) ((g::'a::type ==> 'b::type) ` (B::'a::type set))› ‹finite (B::'a::type set)› ‹(B::'a::type set) ≠ {}› ‹arg_min_on ((f::'b::type ==> 'c::linorder) ∘ (g::'a::type ==> 'b::type)) (B::'a::type set) ∈ B› ‹∄x::'a::type. x ∈ (B::'a::type set) ∧ ((f::'b::type ==> 'c::linorder) ∘ (g::'a::type ==> 'b::type)) x 🚫f ∘ g) (arg_min_on (f ∘ g) B)› ‹∀(f::'b::type ==> 'c::linorder) (P::'b::type ==> bool) a::'b::type. inj_on f (Collect P) ∧ P a ∧ (∀y::'b::type. P y ⟶ f a ≤ f y) ⟶ arg_min f P = a› ‹∀(S::'b::type set) f::'b::type ==> 'c::linorder. finite' S ⟶ arg_min_on f S ∈ S› ‹∀(S::'a::type set) f::'a::type ==> 'c::linorder. finite' S ⟶ arg_min_on f S ∈ S› ‹∀(S::'b::type set) (y::'b::type) f::'b::type ==> 'c::linorder. finite S ∧ S ≠ {} ∧ y ∈ S ⟶ f (arg_min_on f S) ≤ f y› ‹∀(S::'a::type set) (y::'a::type) f::'a::type ==> 'c::linorder. finite S ∧ S ≠ {} ∧ y ∈ S ⟶ f (arg_min_on f S) ≤ f y› ‹∀(f::'b::type ==> 'c::linorder) (g::'a::type ==> 'b::type) x::'a::type. (f ∘ g) x = f (g x)› ‹∀(F::'b::type set) h::'b::type ==> 'a::type. finite F ⟶ finite (h ` F)› ‹∀(F::'b::type set) h::'b::type ==> 'b::type. finite F ⟶ finite (h ` F)› ‹∀(F::'a::type set) h::'a::type ==> 'b::type. finite F ⟶ finite (h ` F)› ‹∀(F::'a::type set) h::'a::type ==> 'a::type. finite F ⟶ finite (h ` F)› ‹∀(b::'a::type) (f::'b::type ==> 'a::type) A::'b::type set. b ∈ f ` A ∧ (∀x::'b::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'b::type) (f::'b::type ==> 'b::type) A::'b::type set. b ∈ f ` A ∧ (∀x::'b::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'b::type) (f::'a::type ==> 'b::type) A::'a::type set. b ∈ f ` A ∧ (∀x::'a::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'a::type) (f::'a::type ==> 'a::type) A::'a::type set. b ∈ f ` A ∧ (∀x::'a::type. b = f x ∧ x ∈ A ⟶ False) ⟶ False› ‹∀(b::'a::type) (f::'b::type ==> 'a::type) (x::'b::type) A::'b::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(b::'b::type) (f::'b::type ==> 'b::type) (x::'b::type) A::'b::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(b::'b::type) (f::'a::type ==> 'b::type) (x::'a::type) A::'a::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(b::'a::type) (f::'a::type ==> 'a::type) (x::'a::type) A::'a::type set. b = f x ∧ x ∈ A ⟶ b ∈ f ` A › ‹∀(f::'b::type ==> 'a::type) A::'b::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'b::type ==> 'b::type) A::'b::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'a::type ==> 'b::type) A::'a::type set. (f ` A = {}) = (A = {}) › ‹∀(f::'a::type ==> 'a::type) A::'a::type set. (f ` A = {}) = (A = {})› ‹∀(f::'b::type ==> 'c::linorder) (A::'b::type set) (x::'b::type) y::'b::type. inj_on f A ∧ f x = f y ∧ x ∈ A ∧ y ∈ A ⟶ x = y› ‹∀(x::'c::linorder) y::'c::linorder. (x 🚫) = (x ≤ y ∧ x ≠ y)› ‹arg_min_on (f::'b::type ==> 'c::linorder) ((g::'a::type ==> 'b::type) ` (B::'a::type set)) ≠ g (arg_min_on (f ∘ g) B) › shows False using assms by (smt (verit)) end
experiment begin
private datatype abort =
Rtype_error
| Rtimeout_error
private datatype ('a) error_result =
Rraise " 'a "🍋‹‹ Should only be a value of type exn ›\
| Rabort " abort "
private datatype( 'a, 'b) result =
Rval " 'a "
| Rerr " ('b) error_result "
lemma fixes clock :: ‹'astate ==> nat›and
fun_evaluate_match :: ‹'astate ==> 'vsemv_env ==> _ ==> ('pat × 'exp0) list ==> _ ==> 'astate*((('v)list),('v))result› assumes "fix_clock (st::'astate) (fun_evaluate st (env::'vsemv_env) [e::'exp0]) = (st'::'astate, r::('v list, 'v) result)" "clock (fst (fun_evaluate (st::'astate) (env::'vsemv_env) [e::'exp0])) ≤ clock st" "∀(b::nat) (a::nat) c::nat. b ≤ a ∧ c ≤ b ⟶ c ≤ a" "∀(a::'astate) p::'astate × ('v list, 'v) result. (a = fst p) = (∃b::('v list, 'v) result. p = (a, b))" "∀y::'v error_result. (∀x1::'v. y = Rraise x1 ⟶ False) ∧ (∀x2::abort. y = Rabort x2 ⟶ False) ⟶ False" "∀(f1::'v ==> 'astate × ('v list, 'v) result) (f2::abort ==> 'astate × ('v list, 'v) result) x1::'v. (case Rraise x1 of Rraise (x::'v) ==> f1 x | Rabort (x::abort) ==> f2 x) = f1 x1" "∀(f1::'v ==> 'astate × ('v list, 'v) result) (f2::abort ==> 'astate × ('v list, 'v) result) x2::abort. (case Rabort x2 of Rraise (x::'v) ==> f1 x | Rabort (x::abort) ==> f2 x) = f2 x2" "∀(s1::'astate) (s2::'astate) (x::('v list, 'v) result) s::'astate. fix_clock s1 (s2, x) = (s, x) ⟶ clock s ≤ clock s2" "∀(s::'astate) (s'::'astate) res::('v list, 'v) result. fix_clock s (s', res) = (update_clock (λ_::nat. if clock s' ≤ clock s then clock s' else clock s) s', res)" "∀(x2::'v error_result) x1::'v. (r::('v list, 'v) result) = Rerr x2 ∧ x2 = Rraise x1 ⟶ clock (fst (fun_evaluate_match (st'::'astate) (env::'vsemv_env) x1 (pes::('pat × 'exp0) list) x1)) ≤ clock st'" shows"((r::('v list, 'v) result) = Rerr (x2::'v error_result) ⟶ clock (fst (case x2 of Rraise (v2::'v) ==> fun_evaluate_match (st'::'astate) (env::'vsemv_env) v2 (pes::('pat × 'exp0) list) v2 | Rabort (abort::abort) ==> (st', Rerr (Rabort abort)))) ≤ clock (st::'astate))" using assms by (smt (verit)) end
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 und die Messung sind noch experimentell.