equal
deleted
inserted
replaced
1 (* Title: HOL/SMT_Examples/SMT_Tests.thy |
1 (* Title: HOL/SMT_Examples/SMT_Tests.thy |
2 Author: Sascha Boehme, TU Muenchen |
2 Author: Sascha Boehme, TU Muenchen |
3 *) |
3 *) |
4 |
4 |
5 section {* Tests for the SMT binding *} |
5 section \<open>Tests for the SMT binding\<close> |
6 |
6 |
7 theory SMT_Tests |
7 theory SMT_Tests |
8 imports Complex_Main |
8 imports Complex_Main |
9 begin |
9 begin |
10 |
10 |
11 smt_status |
11 smt_status |
12 |
12 |
13 text {* Most examples are taken from various Isabelle theories and from HOL4. *} |
13 text \<open>Most examples are taken from various Isabelle theories and from HOL4.\<close> |
14 |
14 |
15 |
15 |
16 section {* Propositional logic *} |
16 section \<open>Propositional logic\<close> |
17 |
17 |
18 lemma |
18 lemma |
19 "True" |
19 "True" |
20 "\<not> False" |
20 "\<not> False" |
21 "\<not> \<not> True" |
21 "\<not> \<not> True" |
79 "case \<not> P of True \<Rightarrow> \<not> P | False \<Rightarrow> P" |
79 "case \<not> P of True \<Rightarrow> \<not> P | False \<Rightarrow> P" |
80 "case P of True \<Rightarrow> (Q \<longrightarrow> P) | False \<Rightarrow> (P \<longrightarrow> Q)" |
80 "case P of True \<Rightarrow> (Q \<longrightarrow> P) | False \<Rightarrow> (P \<longrightarrow> Q)" |
81 by smt+ |
81 by smt+ |
82 |
82 |
83 |
83 |
84 section {* First-order logic with equality *} |
84 section \<open>First-order logic with equality\<close> |
85 |
85 |
86 lemma |
86 lemma |
87 "x = x" |
87 "x = x" |
88 "x = y \<longrightarrow> y = x" |
88 "x = y \<longrightarrow> y = x" |
89 "x = y \<and> y = z \<longrightarrow> x = z" |
89 "x = y \<and> y = z \<longrightarrow> x = z" |
179 "(\<forall>x y z. f x y = f x z \<longrightarrow> y = z) \<and> b \<noteq> c \<longrightarrow> f a b \<noteq> f a c" |
179 "(\<forall>x y z. f x y = f x z \<longrightarrow> y = z) \<and> b \<noteq> c \<longrightarrow> f a b \<noteq> f a c" |
180 "(\<forall>x y z. f x y = f z y \<longrightarrow> x = z) \<and> a \<noteq> d \<longrightarrow> f a b \<noteq> f d b" |
180 "(\<forall>x y z. f x y = f z y \<longrightarrow> x = z) \<and> a \<noteq> d \<longrightarrow> f a b \<noteq> f d b" |
181 by smt+ |
181 by smt+ |
182 |
182 |
183 |
183 |
184 section {* Guidance for quantifier heuristics: patterns *} |
184 section \<open>Guidance for quantifier heuristics: patterns\<close> |
185 |
185 |
186 lemma |
186 lemma |
187 assumes "\<forall>x. |
187 assumes "\<forall>x. |
188 SMT.trigger (SMT.Symb_Cons (SMT.Symb_Cons (SMT.pat (f x)) SMT.Symb_Nil) SMT.Symb_Nil) |
188 SMT.trigger (SMT.Symb_Cons (SMT.Symb_Cons (SMT.pat (f x)) SMT.Symb_Nil) SMT.Symb_Nil) |
189 (f x = x)" |
189 (f x = x)" |
196 (SMT.Symb_Cons (SMT.pat (g y)) SMT.Symb_Nil)) SMT.Symb_Nil) (f x = g y)" |
196 (SMT.Symb_Cons (SMT.pat (g y)) SMT.Symb_Nil)) SMT.Symb_Nil) (f x = g y)" |
197 shows "f a = g b" |
197 shows "f a = g b" |
198 using assms by smt |
198 using assms by smt |
199 |
199 |
200 |
200 |
201 section {* Meta-logical connectives *} |
201 section \<open>Meta-logical connectives\<close> |
202 |
202 |
203 lemma |
203 lemma |
204 "True \<Longrightarrow> True" |
204 "True \<Longrightarrow> True" |
205 "False \<Longrightarrow> True" |
205 "False \<Longrightarrow> True" |
206 "False \<Longrightarrow> False" |
206 "False \<Longrightarrow> False" |
220 "(p \<or> q) \<and> \<not> p \<Longrightarrow> q" |
220 "(p \<or> q) \<and> \<not> p \<Longrightarrow> q" |
221 "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)" |
221 "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)" |
222 by smt+ |
222 by smt+ |
223 |
223 |
224 |
224 |
225 section {* Integers *} |
225 section \<open>Integers\<close> |
226 |
226 |
227 lemma |
227 lemma |
228 "(0::int) = 0" |
228 "(0::int) = 0" |
229 "(0::int) = (- 0)" |
229 "(0::int) = (- 0)" |
230 "(1::int) = 1" |
230 "(1::int) = 1" |
375 "x < y \<longrightarrow> y < z \<longrightarrow> x < z" |
375 "x < y \<longrightarrow> y < z \<longrightarrow> x < z" |
376 "x < y \<and> y < z \<longrightarrow> \<not> (z < x)" |
376 "x < y \<and> y < z \<longrightarrow> \<not> (z < x)" |
377 by smt+ |
377 by smt+ |
378 |
378 |
379 |
379 |
380 section {* Reals *} |
380 section \<open>Reals\<close> |
381 |
381 |
382 lemma |
382 lemma |
383 "(0::real) = 0" |
383 "(0::real) = 0" |
384 "(0::real) = -0" |
384 "(0::real) = -0" |
385 "(0::real) = (- 0)" |
385 "(0::real) = (- 0)" |
485 "x < y \<longrightarrow> y < z \<longrightarrow> x < z" |
485 "x < y \<longrightarrow> y < z \<longrightarrow> x < z" |
486 "x < y \<and> y < z \<longrightarrow> \<not> (z < x)" |
486 "x < y \<and> y < z \<longrightarrow> \<not> (z < x)" |
487 by smt+ |
487 by smt+ |
488 |
488 |
489 |
489 |
490 section {* Datatypes, Records, and Typedefs *} |
490 section \<open>Datatypes, Records, and Typedefs\<close> |
491 |
491 |
492 subsection {* Without support by the SMT solver *} |
492 subsection \<open>Without support by the SMT solver\<close> |
493 |
493 |
494 subsubsection {* Algebraic datatypes *} |
494 subsubsection \<open>Algebraic datatypes\<close> |
495 |
495 |
496 lemma |
496 lemma |
497 "x = fst (x, y)" |
497 "x = fst (x, y)" |
498 "y = snd (x, y)" |
498 "y = snd (x, y)" |
499 "((x, y) = (y, x)) = (x = y)" |
499 "((x, y) = (y, x)) = (x = y)" |
527 "snd (hd [(a, b)]) = b" |
527 "snd (hd [(a, b)]) = b" |
528 using fst_conv snd_conv prod.collapse list.sel(1,3) list.simps |
528 using fst_conv snd_conv prod.collapse list.sel(1,3) list.simps |
529 by smt+ |
529 by smt+ |
530 |
530 |
531 |
531 |
532 subsubsection {* Records *} |
532 subsubsection \<open>Records\<close> |
533 |
533 |
534 record point = |
534 record point = |
535 cx :: int |
535 cx :: int |
536 cy :: int |
536 cy :: int |
537 |
537 |
592 apply (smt bw_point.update_convs(1)) |
592 apply (smt bw_point.update_convs(1)) |
593 apply (smt bw_point.cases_scheme bw_point.update_convs(1) point.update_convs(1,2)) |
593 apply (smt bw_point.cases_scheme bw_point.update_convs(1) point.update_convs(1,2)) |
594 done |
594 done |
595 |
595 |
596 |
596 |
597 subsubsection {* Type definitions *} |
597 subsubsection \<open>Type definitions\<close> |
598 |
598 |
599 typedef int' = "UNIV::int set" by (rule UNIV_witness) |
599 typedef int' = "UNIV::int set" by (rule UNIV_witness) |
600 |
600 |
601 definition n0 where "n0 = Abs_int' 0" |
601 definition n0 where "n0 = Abs_int' 0" |
602 definition n1 where "n1 = Abs_int' 1" |
602 definition n1 where "n1 = Abs_int' 1" |
608 "plus' n1 n1 = n2" |
608 "plus' n1 n1 = n2" |
609 "plus' n0 n2 = n2" |
609 "plus' n0 n2 = n2" |
610 by (smt n0_def n1_def n2_def plus'_def Abs_int'_inverse Rep_int'_inverse UNIV_I)+ |
610 by (smt n0_def n1_def n2_def plus'_def Abs_int'_inverse Rep_int'_inverse UNIV_I)+ |
611 |
611 |
612 |
612 |
613 subsection {* With support by the SMT solver (but without proofs) *} |
613 subsection \<open>With support by the SMT solver (but without proofs)\<close> |
614 |
614 |
615 subsubsection {* Algebraic datatypes *} |
615 subsubsection \<open>Algebraic datatypes\<close> |
616 |
616 |
617 lemma |
617 lemma |
618 "x = fst (x, y)" |
618 "x = fst (x, y)" |
619 "y = snd (x, y)" |
619 "y = snd (x, y)" |
620 "((x, y) = (y, x)) = (x = y)" |
620 "((x, y) = (y, x)) = (x = y)" |
651 using fst_conv snd_conv prod.collapse list.sel(1,3) |
651 using fst_conv snd_conv prod.collapse list.sel(1,3) |
652 using [[smt_oracle, z3_extensions]] |
652 using [[smt_oracle, z3_extensions]] |
653 by smt+ |
653 by smt+ |
654 |
654 |
655 |
655 |
656 subsubsection {* Records *} |
656 subsubsection \<open>Records\<close> |
657 |
657 |
658 lemma |
658 lemma |
659 "\<lparr>cx = x, cy = y\<rparr> = \<lparr>cx = x', cy = y'\<rparr> \<Longrightarrow> x = x' \<and> y = y'" |
659 "\<lparr>cx = x, cy = y\<rparr> = \<lparr>cx = x', cy = y'\<rparr> \<Longrightarrow> x = x' \<and> y = y'" |
660 using [[smt_oracle, z3_extensions]] |
660 using [[smt_oracle, z3_extensions]] |
661 by smt+ |
661 by smt+ |
714 using point.simps bw_point.simps |
714 using point.simps bw_point.simps |
715 using [[smt_oracle, z3_extensions]] |
715 using [[smt_oracle, z3_extensions]] |
716 by smt |
716 by smt |
717 |
717 |
718 |
718 |
719 subsubsection {* Type definitions *} |
719 subsubsection \<open>Type definitions\<close> |
720 |
720 |
721 lemma |
721 lemma |
722 "n0 \<noteq> n1" |
722 "n0 \<noteq> n1" |
723 "plus' n1 n1 = n2" |
723 "plus' n1 n1 = n2" |
724 "plus' n0 n2 = n2" |
724 "plus' n0 n2 = n2" |
725 using [[smt_oracle, z3_extensions]] |
725 using [[smt_oracle, z3_extensions]] |
726 by (smt n0_def n1_def n2_def plus'_def)+ |
726 by (smt n0_def n1_def n2_def plus'_def)+ |
727 |
727 |
728 |
728 |
729 section {* Function updates *} |
729 section \<open>Function updates\<close> |
730 |
730 |
731 lemma |
731 lemma |
732 "(f (i := v)) i = v" |
732 "(f (i := v)) i = v" |
733 "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v)) i2 = f i2" |
733 "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v)) i2 = f i2" |
734 "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v1, i2 := v2)) i1 = v1" |
734 "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v1, i2 := v2)) i1 = v1" |
738 "i1 \<noteq> i2 \<and>i1 \<noteq> i3 \<and> i2 \<noteq> i3 \<longrightarrow> (f (i1 := v1, i2 := v2)) i3 = f i3" |
738 "i1 \<noteq> i2 \<and>i1 \<noteq> i3 \<and> i2 \<noteq> i3 \<longrightarrow> (f (i1 := v1, i2 := v2)) i3 = f i3" |
739 using fun_upd_same fun_upd_apply |
739 using fun_upd_same fun_upd_apply |
740 by smt+ |
740 by smt+ |
741 |
741 |
742 |
742 |
743 section {* Sets *} |
743 section \<open>Sets\<close> |
744 |
744 |
745 lemma Empty: "x \<notin> {}" by simp |
745 lemma Empty: "x \<notin> {}" by simp |
746 |
746 |
747 lemmas smt_sets = Empty UNIV_I Un_iff Int_iff |
747 lemmas smt_sets = Empty UNIV_I Un_iff Int_iff |
748 |
748 |