| author | wenzelm | 
| Thu, 05 Sep 2013 20:19:22 +0200 | |
| changeset 53419 | 1c87e79bb838 | 
| parent 50666 | 6f48853f08d5 | 
| child 55465 | 0d31c0546286 | 
| permissions | -rw-r--r-- | 
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 1 | (* Title: HOL/SMT_Examples/SMT_Examples.thy | 
| 36898 | 2 | Author: Sascha Boehme, TU Muenchen | 
| 3 | *) | |
| 4 | ||
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 5 | header {* Examples for the SMT binding *}
 | 
| 36898 | 6 | |
| 7 | theory SMT_Examples | |
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 8 | imports Complex_Main | 
| 36898 | 9 | begin | 
| 10 | ||
| 47152 
446cfc760ccf
renamed "smt_fixed" to "smt_read_only_certificates"
 blanchet parents: 
47111diff
changeset | 11 | declare [[smt_certificates = "SMT_Examples.certs"]] | 
| 
446cfc760ccf
renamed "smt_fixed" to "smt_read_only_certificates"
 blanchet parents: 
47111diff
changeset | 12 | declare [[smt_read_only_certificates = true]] | 
| 36898 | 13 | |
| 14 | ||
| 15 | ||
| 16 | section {* Propositional and first-order logic *}
 | |
| 17 | ||
| 18 | lemma "True" by smt | |
| 19 | ||
| 20 | lemma "p \<or> \<not>p" by smt | |
| 21 | ||
| 22 | lemma "(p \<and> True) = p" by smt | |
| 23 | ||
| 24 | lemma "(p \<or> q) \<and> \<not>p \<Longrightarrow> q" by smt | |
| 25 | ||
| 26 | lemma "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)" | |
| 27 | by smt | |
| 28 | ||
| 29 | lemma "(p1 \<and> p2) \<or> p3 \<longrightarrow> (p1 \<longrightarrow> (p3 \<and> p2) \<or> (p1 \<and> p3)) \<or> p1" by smt | |
| 30 | ||
| 31 | lemma "P=P=P=P=P=P=P=P=P=P" by smt | |
| 32 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 33 | lemma | 
| 36898 | 34 | assumes "a | b | c | d" | 
| 35 | and "e | f | (a & d)" | |
| 36 | and "~(a | (c & ~c)) | b" | |
| 37 | and "~(b & (x | ~x)) | c" | |
| 38 | and "~(d | False) | c" | |
| 39 | and "~(c | (~p & (p | (q & ~q))))" | |
| 40 | shows False | |
| 41 | using assms by smt | |
| 42 | ||
| 43 | axiomatization symm_f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where | |
| 44 | symm_f: "symm_f x y = symm_f y x" | |
| 45 | lemma "a = a \<and> symm_f a b = symm_f b a" by (smt symm_f) | |
| 46 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 47 | (* | 
| 36898 | 48 | Taken from ~~/src/HOL/ex/SAT_Examples.thy. | 
| 49 | Translated from TPTP problem library: PUZ015-2.006.dimacs | |
| 50 | *) | |
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 51 | lemma | 
| 36898 | 52 | assumes "~x0" | 
| 53 | and "~x30" | |
| 54 | and "~x29" | |
| 55 | and "~x59" | |
| 56 | and "x1 | x31 | x0" | |
| 57 | and "x2 | x32 | x1" | |
| 58 | and "x3 | x33 | x2" | |
| 59 | and "x4 | x34 | x3" | |
| 60 | and "x35 | x4" | |
| 61 | and "x5 | x36 | x30" | |
| 62 | and "x6 | x37 | x5 | x31" | |
| 63 | and "x7 | x38 | x6 | x32" | |
| 64 | and "x8 | x39 | x7 | x33" | |
| 65 | and "x9 | x40 | x8 | x34" | |
| 66 | and "x41 | x9 | x35" | |
| 67 | and "x10 | x42 | x36" | |
| 68 | and "x11 | x43 | x10 | x37" | |
| 69 | and "x12 | x44 | x11 | x38" | |
| 70 | and "x13 | x45 | x12 | x39" | |
| 71 | and "x14 | x46 | x13 | x40" | |
| 72 | and "x47 | x14 | x41" | |
| 73 | and "x15 | x48 | x42" | |
| 74 | and "x16 | x49 | x15 | x43" | |
| 75 | and "x17 | x50 | x16 | x44" | |
| 76 | and "x18 | x51 | x17 | x45" | |
| 77 | and "x19 | x52 | x18 | x46" | |
| 78 | and "x53 | x19 | x47" | |
| 79 | and "x20 | x54 | x48" | |
| 80 | and "x21 | x55 | x20 | x49" | |
| 81 | and "x22 | x56 | x21 | x50" | |
| 82 | and "x23 | x57 | x22 | x51" | |
| 83 | and "x24 | x58 | x23 | x52" | |
| 84 | and "x59 | x24 | x53" | |
| 85 | and "x25 | x54" | |
| 86 | and "x26 | x25 | x55" | |
| 87 | and "x27 | x26 | x56" | |
| 88 | and "x28 | x27 | x57" | |
| 89 | and "x29 | x28 | x58" | |
| 90 | and "~x1 | ~x31" | |
| 91 | and "~x1 | ~x0" | |
| 92 | and "~x31 | ~x0" | |
| 93 | and "~x2 | ~x32" | |
| 94 | and "~x2 | ~x1" | |
| 95 | and "~x32 | ~x1" | |
| 96 | and "~x3 | ~x33" | |
| 97 | and "~x3 | ~x2" | |
| 98 | and "~x33 | ~x2" | |
| 99 | and "~x4 | ~x34" | |
| 100 | and "~x4 | ~x3" | |
| 101 | and "~x34 | ~x3" | |
| 102 | and "~x35 | ~x4" | |
| 103 | and "~x5 | ~x36" | |
| 104 | and "~x5 | ~x30" | |
| 105 | and "~x36 | ~x30" | |
| 106 | and "~x6 | ~x37" | |
| 107 | and "~x6 | ~x5" | |
| 108 | and "~x6 | ~x31" | |
| 109 | and "~x37 | ~x5" | |
| 110 | and "~x37 | ~x31" | |
| 111 | and "~x5 | ~x31" | |
| 112 | and "~x7 | ~x38" | |
| 113 | and "~x7 | ~x6" | |
| 114 | and "~x7 | ~x32" | |
| 115 | and "~x38 | ~x6" | |
| 116 | and "~x38 | ~x32" | |
| 117 | and "~x6 | ~x32" | |
| 118 | and "~x8 | ~x39" | |
| 119 | and "~x8 | ~x7" | |
| 120 | and "~x8 | ~x33" | |
| 121 | and "~x39 | ~x7" | |
| 122 | and "~x39 | ~x33" | |
| 123 | and "~x7 | ~x33" | |
| 124 | and "~x9 | ~x40" | |
| 125 | and "~x9 | ~x8" | |
| 126 | and "~x9 | ~x34" | |
| 127 | and "~x40 | ~x8" | |
| 128 | and "~x40 | ~x34" | |
| 129 | and "~x8 | ~x34" | |
| 130 | and "~x41 | ~x9" | |
| 131 | and "~x41 | ~x35" | |
| 132 | and "~x9 | ~x35" | |
| 133 | and "~x10 | ~x42" | |
| 134 | and "~x10 | ~x36" | |
| 135 | and "~x42 | ~x36" | |
| 136 | and "~x11 | ~x43" | |
| 137 | and "~x11 | ~x10" | |
| 138 | and "~x11 | ~x37" | |
| 139 | and "~x43 | ~x10" | |
| 140 | and "~x43 | ~x37" | |
| 141 | and "~x10 | ~x37" | |
| 142 | and "~x12 | ~x44" | |
| 143 | and "~x12 | ~x11" | |
| 144 | and "~x12 | ~x38" | |
| 145 | and "~x44 | ~x11" | |
| 146 | and "~x44 | ~x38" | |
| 147 | and "~x11 | ~x38" | |
| 148 | and "~x13 | ~x45" | |
| 149 | and "~x13 | ~x12" | |
| 150 | and "~x13 | ~x39" | |
| 151 | and "~x45 | ~x12" | |
| 152 | and "~x45 | ~x39" | |
| 153 | and "~x12 | ~x39" | |
| 154 | and "~x14 | ~x46" | |
| 155 | and "~x14 | ~x13" | |
| 156 | and "~x14 | ~x40" | |
| 157 | and "~x46 | ~x13" | |
| 158 | and "~x46 | ~x40" | |
| 159 | and "~x13 | ~x40" | |
| 160 | and "~x47 | ~x14" | |
| 161 | and "~x47 | ~x41" | |
| 162 | and "~x14 | ~x41" | |
| 163 | and "~x15 | ~x48" | |
| 164 | and "~x15 | ~x42" | |
| 165 | and "~x48 | ~x42" | |
| 166 | and "~x16 | ~x49" | |
| 167 | and "~x16 | ~x15" | |
| 168 | and "~x16 | ~x43" | |
| 169 | and "~x49 | ~x15" | |
| 170 | and "~x49 | ~x43" | |
| 171 | and "~x15 | ~x43" | |
| 172 | and "~x17 | ~x50" | |
| 173 | and "~x17 | ~x16" | |
| 174 | and "~x17 | ~x44" | |
| 175 | and "~x50 | ~x16" | |
| 176 | and "~x50 | ~x44" | |
| 177 | and "~x16 | ~x44" | |
| 178 | and "~x18 | ~x51" | |
| 179 | and "~x18 | ~x17" | |
| 180 | and "~x18 | ~x45" | |
| 181 | and "~x51 | ~x17" | |
| 182 | and "~x51 | ~x45" | |
| 183 | and "~x17 | ~x45" | |
| 184 | and "~x19 | ~x52" | |
| 185 | and "~x19 | ~x18" | |
| 186 | and "~x19 | ~x46" | |
| 187 | and "~x52 | ~x18" | |
| 188 | and "~x52 | ~x46" | |
| 189 | and "~x18 | ~x46" | |
| 190 | and "~x53 | ~x19" | |
| 191 | and "~x53 | ~x47" | |
| 192 | and "~x19 | ~x47" | |
| 193 | and "~x20 | ~x54" | |
| 194 | and "~x20 | ~x48" | |
| 195 | and "~x54 | ~x48" | |
| 196 | and "~x21 | ~x55" | |
| 197 | and "~x21 | ~x20" | |
| 198 | and "~x21 | ~x49" | |
| 199 | and "~x55 | ~x20" | |
| 200 | and "~x55 | ~x49" | |
| 201 | and "~x20 | ~x49" | |
| 202 | and "~x22 | ~x56" | |
| 203 | and "~x22 | ~x21" | |
| 204 | and "~x22 | ~x50" | |
| 205 | and "~x56 | ~x21" | |
| 206 | and "~x56 | ~x50" | |
| 207 | and "~x21 | ~x50" | |
| 208 | and "~x23 | ~x57" | |
| 209 | and "~x23 | ~x22" | |
| 210 | and "~x23 | ~x51" | |
| 211 | and "~x57 | ~x22" | |
| 212 | and "~x57 | ~x51" | |
| 213 | and "~x22 | ~x51" | |
| 214 | and "~x24 | ~x58" | |
| 215 | and "~x24 | ~x23" | |
| 216 | and "~x24 | ~x52" | |
| 217 | and "~x58 | ~x23" | |
| 218 | and "~x58 | ~x52" | |
| 219 | and "~x23 | ~x52" | |
| 220 | and "~x59 | ~x24" | |
| 221 | and "~x59 | ~x53" | |
| 222 | and "~x24 | ~x53" | |
| 223 | and "~x25 | ~x54" | |
| 224 | and "~x26 | ~x25" | |
| 225 | and "~x26 | ~x55" | |
| 226 | and "~x25 | ~x55" | |
| 227 | and "~x27 | ~x26" | |
| 228 | and "~x27 | ~x56" | |
| 229 | and "~x26 | ~x56" | |
| 230 | and "~x28 | ~x27" | |
| 231 | and "~x28 | ~x57" | |
| 232 | and "~x27 | ~x57" | |
| 233 | and "~x29 | ~x28" | |
| 234 | and "~x29 | ~x58" | |
| 235 | and "~x28 | ~x58" | |
| 236 | shows False | |
| 237 | using assms by smt | |
| 238 | ||
| 239 | lemma "\<forall>x::int. P x \<longrightarrow> (\<forall>y::int. P x \<or> P y)" | |
| 240 | by smt | |
| 241 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 242 | lemma | 
| 36898 | 243 | assumes "(\<forall>x y. P x y = x)" | 
| 244 | shows "(\<exists>y. P x y) = P x c" | |
| 245 | using assms by smt | |
| 246 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 247 | lemma | 
| 36898 | 248 | assumes "(\<forall>x y. P x y = x)" | 
| 249 | and "(\<forall>x. \<exists>y. P x y) = (\<forall>x. P x c)" | |
| 250 | shows "(EX y. P x y) = P x c" | |
| 251 | using assms by smt | |
| 252 | ||
| 253 | lemma | |
| 254 | assumes "if P x then \<not>(\<exists>y. P y) else (\<forall>y. \<not>P y)" | |
| 255 | shows "P x \<longrightarrow> P y" | |
| 256 | using assms by smt | |
| 257 | ||
| 258 | ||
| 259 | section {* Arithmetic *}
 | |
| 260 | ||
| 261 | subsection {* Linear arithmetic over integers and reals *}
 | |
| 262 | ||
| 263 | lemma "(3::int) = 3" by smt | |
| 264 | ||
| 265 | lemma "(3::real) = 3" by smt | |
| 266 | ||
| 267 | lemma "(3 :: int) + 1 = 4" by smt | |
| 268 | ||
| 269 | lemma "x + (y + z) = y + (z + (x::int))" by smt | |
| 270 | ||
| 271 | lemma "max (3::int) 8 > 5" by smt | |
| 272 | ||
| 273 | lemma "abs (x :: real) + abs y \<ge> abs (x + y)" by smt | |
| 274 | ||
| 275 | lemma "P ((2::int) < 3) = P True" by smt | |
| 276 | ||
| 277 | lemma "x + 3 \<ge> 4 \<or> x < (1::int)" by smt | |
| 278 | ||
| 279 | lemma | |
| 280 | assumes "x \<ge> (3::int)" and "y = x + 4" | |
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 281 | shows "y - x > 0" | 
| 36898 | 282 | using assms by smt | 
| 283 | ||
| 284 | lemma "let x = (2 :: int) in x + x \<noteq> 5" by smt | |
| 285 | ||
| 286 | lemma | |
| 287 | fixes x :: real | |
| 288 | assumes "3 * x + 7 * a < 4" and "3 < 2 * x" | |
| 289 | shows "a < 0" | |
| 290 | using assms by smt | |
| 291 | ||
| 292 | lemma "(0 \<le> y + -1 * x \<or> \<not> 0 \<le> x \<or> 0 \<le> (x::int)) = (\<not> False)" by smt | |
| 293 | ||
| 294 | lemma " | |
| 295 | (n < m & m < n') | (n < m & m = n') | (n < n' & n' < m) | | |
| 296 | (n = n' & n' < m) | (n = m & m < n') | | |
| 297 | (n' < m & m < n) | (n' < m & m = n) | | |
| 298 | (n' < n & n < m) | (n' = n & n < m) | (n' = m & m < n) | | |
| 299 | (m < n & n < n') | (m < n & n' = n) | (m < n' & n' < n) | | |
| 300 | (m = n & n < n') | (m = n' & n' < n) | | |
| 301 | (n' = m & m = (n::int))" | |
| 302 | by smt | |
| 303 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 304 | text{*
 | 
| 36898 | 305 | The following example was taken from HOL/ex/PresburgerEx.thy, where it says: | 
| 306 | ||
| 307 | This following theorem proves that all solutions to the | |
| 308 |   recurrence relation $x_{i+2} = |x_{i+1}| - x_i$ are periodic with
 | |
| 309 | period 9. The example was brought to our attention by John | |
| 310 | Harrison. It does does not require Presburger arithmetic but merely | |
| 311 | quantifier-free linear arithmetic and holds for the rationals as well. | |
| 312 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 313 | Warning: it takes (in 2006) over 4.2 minutes! | 
| 36898 | 314 | |
| 315 | There, it is proved by "arith". SMT is able to prove this within a fraction | |
| 316 | of one second. With proof reconstruction, it takes about 13 seconds on a Core2 | |
| 317 | processor. | |
| 318 | *} | |
| 319 | ||
| 320 | lemma "\<lbrakk> x3 = abs x2 - x1; x4 = abs x3 - x2; x5 = abs x4 - x3; | |
| 321 | x6 = abs x5 - x4; x7 = abs x6 - x5; x8 = abs x7 - x6; | |
| 322 | x9 = abs x8 - x7; x10 = abs x9 - x8; x11 = abs x10 - x9 \<rbrakk> | |
| 323 | \<Longrightarrow> x1 = x10 & x2 = (x11::int)" | |
| 324 | by smt | |
| 325 | ||
| 326 | ||
| 327 | lemma "let P = 2 * x + 1 > x + (x::real) in P \<or> False \<or> P" by smt | |
| 328 | ||
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 329 | lemma "x + (let y = x mod 2 in 2 * y + 1) \<ge> x + (1::int)" | 
| 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 330 | using [[z3_with_extensions]] | 
| 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 331 | by smt | 
| 36898 | 332 | |
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 333 | lemma "x + (let y = x mod 2 in y + y) < x + (3::int)" | 
| 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 334 | using [[z3_with_extensions]] | 
| 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 335 | by smt | 
| 36898 | 336 | |
| 337 | lemma | |
| 338 | assumes "x \<noteq> (0::real)" | |
| 339 | shows "x + x \<noteq> (let P = (abs x > 1) in if P \<or> \<not>P then 4 else 2) * x" | |
| 340 | using assms by smt | |
| 341 | ||
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 342 | lemma | 
| 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 343 | assumes "(n + m) mod 2 = 0" and "n mod 4 = 3" | 
| 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 344 | shows "n mod 2 = 1 & m mod 2 = (1::int)" | 
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 345 | using assms [[z3_with_extensions]] by smt | 
| 37151 | 346 | |
| 36898 | 347 | |
| 348 | ||
| 349 | subsection {* Linear arithmetic with quantifiers *}
 | |
| 350 | ||
| 351 | lemma "~ (\<exists>x::int. False)" by smt | |
| 352 | ||
| 353 | lemma "~ (\<exists>x::real. False)" by smt | |
| 354 | ||
| 355 | lemma "\<exists>x::int. 0 < x" | |
| 40163 
a462d5207aa6
changed SMT configuration options; updated SMT certificates
 boehmes parents: 
37151diff
changeset | 356 | using [[smt_oracle=true]] (* no Z3 proof *) | 
| 36898 | 357 | by smt | 
| 358 | ||
| 359 | lemma "\<exists>x::real. 0 < x" | |
| 40163 
a462d5207aa6
changed SMT configuration options; updated SMT certificates
 boehmes parents: 
37151diff
changeset | 360 | using [[smt_oracle=true]] (* no Z3 proof *) | 
| 36898 | 361 | by smt | 
| 362 | ||
| 363 | lemma "\<forall>x::int. \<exists>y. y > x" | |
| 40163 
a462d5207aa6
changed SMT configuration options; updated SMT certificates
 boehmes parents: 
37151diff
changeset | 364 | using [[smt_oracle=true]] (* no Z3 proof *) | 
| 36898 | 365 | by smt | 
| 366 | ||
| 367 | lemma "\<forall>x y::int. (x = 0 \<and> y = 1) \<longrightarrow> x \<noteq> y" by smt | |
| 368 | ||
| 369 | lemma "\<exists>x::int. \<forall>y. x < y \<longrightarrow> y < 0 \<or> y >= 0" by smt | |
| 370 | ||
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 371 | lemma "\<forall>x y::int. x < y \<longrightarrow> (2 * x + 1) < (2 * y)" by smt | 
| 36898 | 372 | |
| 373 | lemma "\<forall>x y::int. (2 * x + 1) \<noteq> (2 * y)" by smt | |
| 374 | ||
| 375 | lemma "\<forall>x y::int. x + y > 2 \<or> x + y = 2 \<or> x + y < 2" by smt | |
| 376 | ||
| 377 | lemma "\<forall>x::int. if x > 0 then x + 1 > 0 else 1 > x" by smt | |
| 378 | ||
| 379 | lemma "if (ALL x::int. x < 0 \<or> x > 0) then False else True" by smt | |
| 380 | ||
| 381 | lemma "(if (ALL x::int. x < 0 \<or> x > 0) then -1 else 3) > (0::int)" by smt | |
| 382 | ||
| 383 | lemma "~ (\<exists>x y z::int. 4 * x + -6 * y = (1::int))" by smt | |
| 384 | ||
| 385 | lemma "\<exists>x::int. \<forall>x y. 0 < x \<and> 0 < y \<longrightarrow> (0::int) < x + y" by smt | |
| 386 | ||
| 387 | lemma "\<exists>u::int. \<forall>(x::int) y::real. 0 < x \<and> 0 < y \<longrightarrow> -1 < x" by smt | |
| 388 | ||
| 389 | lemma "\<exists>x::int. (\<forall>y. y \<ge> x \<longrightarrow> y > 0) \<longrightarrow> x > 0" by smt | |
| 390 | ||
| 37124 | 391 | lemma "\<forall>x::int. SMT.trigger [[SMT.pat x]] (x < a \<longrightarrow> 2 * x < 2 * a)" by smt | 
| 36898 | 392 | |
| 42318 
0fd33b6b22cf
corrected order of steps in Z3 proof reconstruction for elimination of unused quantified variables: first try to eliminate unused variables, then skip over used variables
 boehmes parents: 
41786diff
changeset | 393 | lemma "\<forall>(a::int) b::int. 0 < b \<or> b < 1" by smt | 
| 
0fd33b6b22cf
corrected order of steps in Z3 proof reconstruction for elimination of unused quantified variables: first try to eliminate unused variables, then skip over used variables
 boehmes parents: 
41786diff
changeset | 394 | |
| 36898 | 395 | |
| 396 | subsection {* Non-linear arithmetic over integers and reals *}
 | |
| 397 | ||
| 398 | lemma "a > (0::int) \<Longrightarrow> a*b > 0 \<Longrightarrow> b > 0" | |
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 399 | using [[smt_oracle, z3_with_extensions]] | 
| 41282 | 400 | by smt | 
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 401 | |
| 41282 | 402 | lemma "(a::int) * (x + 1 + y) = a * x + a * (y + 1)" | 
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 403 | using [[z3_with_extensions]] | 
| 41282 | 404 | by smt | 
| 36898 | 405 | |
| 41282 | 406 | lemma "((x::real) * (1 + y) - x * (1 - y)) = (2 * x * y)" | 
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 407 | using [[z3_with_extensions]] | 
| 41303 | 408 | by smt | 
| 36898 | 409 | |
| 410 | lemma | |
| 411 | "(U::int) + (1 + p) * (b + e) + p * d = | |
| 412 | U + (2 * (1 + p) * (b + e) + (1 + p) * d + d * p) - (1 + p) * (b + d + e)" | |
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 413 | using [[z3_with_extensions]] | 
| 41303 | 414 | by smt | 
| 36898 | 415 | |
| 43893 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 416 | lemma [z3_rule]: | 
| 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 417 | fixes x :: "int" | 
| 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 418 | assumes "x * y \<le> 0" and "\<not> y \<le> 0" and "\<not> x \<le> 0" | 
| 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 419 | shows False | 
| 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 420 | using assms by (metis mult_le_0_iff) | 
| 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 421 | |
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 422 | lemma "x * y \<le> (0 :: int) \<Longrightarrow> x \<le> 0 \<or> y \<le> 0" | 
| 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 423 | using [[z3_with_extensions]] | 
| 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 424 | by smt | 
| 43893 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 425 | |
| 
f3e75541cb78
allow rules with premises to be declared as z3_rule (to circumvent incompleteness of Z3 proof reconstruction)
 boehmes parents: 
42321diff
changeset | 426 | |
| 36898 | 427 | |
| 428 | subsection {* Linear arithmetic for natural numbers *}
 | |
| 429 | ||
| 430 | lemma "2 * (x::nat) ~= 1" by smt | |
| 431 | ||
| 432 | lemma "a < 3 \<Longrightarrow> (7::nat) > 2 * a" by smt | |
| 433 | ||
| 434 | lemma "let x = (1::nat) + y in x - y > 0 * x" by smt | |
| 435 | ||
| 436 | lemma | |
| 437 | "let x = (1::nat) + y in | |
| 438 | let P = (if x > 0 then True else False) in | |
| 439 | False \<or> P = (x - 1 = y) \<or> (\<not>P \<longrightarrow> False)" | |
| 440 | by smt | |
| 441 | ||
| 442 | lemma "int (nat \<bar>x::int\<bar>) = \<bar>x\<bar>" by smt | |
| 443 | ||
| 444 | definition prime_nat :: "nat \<Rightarrow> bool" where | |
| 445 | "prime_nat p = (1 < p \<and> (\<forall>m. m dvd p --> m = 1 \<or> m = p))" | |
| 446 | lemma "prime_nat (4*m + 1) \<Longrightarrow> m \<ge> (1::nat)" by (smt prime_nat_def) | |
| 447 | ||
| 448 | ||
| 449 | section {* Pairs *}
 | |
| 450 | ||
| 41132 | 451 | lemma "fst (x, y) = a \<Longrightarrow> x = a" | 
| 452 | using fst_conv | |
| 453 | by smt | |
| 36898 | 454 | |
| 41132 | 455 | lemma "p1 = (x, y) \<and> p2 = (y, x) \<Longrightarrow> fst p1 = snd p2" | 
| 456 | using fst_conv snd_conv | |
| 457 | by smt | |
| 36898 | 458 | |
| 459 | ||
| 460 | section {* Higher-order problems and recursion *}
 | |
| 461 | ||
| 41132 | 462 | lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> (f (i1 := v1, i2 := v2)) i = f i" | 
| 463 | using fun_upd_same fun_upd_apply | |
| 464 | by smt | |
| 36898 | 465 | |
| 466 | lemma "(f g (x::'a::type) = (g x \<and> True)) \<or> (f g x = True) \<or> (g x = True)" | |
| 467 | by smt | |
| 468 | ||
| 47111 
a4476e55a241
reintroduced broken proofs and regenerated certificates
 blanchet parents: 
47108diff
changeset | 469 | lemma "id x = x \<and> id True = True" by (smt id_def) | 
| 36898 | 470 | |
| 41132 | 471 | lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> ((f (i1 := v1)) (i2 := v2)) i = f i" | 
| 472 | using fun_upd_same fun_upd_apply | |
| 473 | by smt | |
| 36898 | 474 | |
| 41786 
a5899d0ce1a1
added test cases with quantifier occurring in first-order term positions
 boehmes parents: 
41601diff
changeset | 475 | lemma | 
| 
a5899d0ce1a1
added test cases with quantifier occurring in first-order term positions
 boehmes parents: 
41601diff
changeset | 476 | "f (\<exists>x. g x) \<Longrightarrow> True" | 
| 
a5899d0ce1a1
added test cases with quantifier occurring in first-order term positions
 boehmes parents: 
41601diff
changeset | 477 | "f (\<forall>x. g x) \<Longrightarrow> True" | 
| 
a5899d0ce1a1
added test cases with quantifier occurring in first-order term positions
 boehmes parents: 
41601diff
changeset | 478 | by smt+ | 
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 479 | |
| 42319 
9a8ba59aed06
unfold and eta-contract let expressions before lambda-lifting to avoid bad terms
 boehmes parents: 
42318diff
changeset | 480 | lemma True using let_rsp by smt | 
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 481 | |
| 42321 
ce83c1654b86
fixed eta-expansion: use correct order to apply new bound variables
 boehmes parents: 
42319diff
changeset | 482 | lemma "le = op \<le> \<Longrightarrow> le (3::int) 42" by smt | 
| 
ce83c1654b86
fixed eta-expansion: use correct order to apply new bound variables
 boehmes parents: 
42319diff
changeset | 483 | |
| 36898 | 484 | lemma "map (\<lambda>i::nat. i + 1) [0, 1] = [1, 2]" by (smt map.simps) | 
| 485 | ||
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 486 | |
| 36898 | 487 | lemma "(ALL x. P x) | ~ All P" by smt | 
| 488 | ||
| 489 | fun dec_10 :: "nat \<Rightarrow> nat" where | |
| 490 | "dec_10 n = (if n < 10 then n else dec_10 (n - 10))" | |
| 491 | lemma "dec_10 (4 * dec_10 4) = 6" by (smt dec_10.simps) | |
| 492 | ||
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 493 | |
| 36898 | 494 | axiomatization | 
| 495 | eval_dioph :: "int list \<Rightarrow> nat list \<Rightarrow> int" | |
| 496 | where | |
| 497 | eval_dioph_mod: | |
| 498 | "eval_dioph ks xs mod int n = eval_dioph ks (map (\<lambda>x. x mod n) xs) mod int n" | |
| 499 | and | |
| 500 | eval_dioph_div_mult: | |
| 501 | "eval_dioph ks (map (\<lambda>x. x div n) xs) * int n + | |
| 502 | eval_dioph ks (map (\<lambda>x. x mod n) xs) = eval_dioph ks xs" | |
| 503 | lemma | |
| 504 | "(eval_dioph ks xs = l) = | |
| 505 | (eval_dioph ks (map (\<lambda>x. x mod 2) xs) mod 2 = l mod 2 \<and> | |
| 506 | eval_dioph ks (map (\<lambda>x. x div 2) xs) = | |
| 507 | (l - eval_dioph ks (map (\<lambda>x. x mod 2) xs)) div 2)" | |
| 41132 | 508 | using [[smt_oracle=true]] (*FIXME*) | 
| 48069 
e9b2782c4f99
restricted Z3 by default to a fragment where proof reconstruction should not fail (for better integration with Sledgehammer) -- the full set of supported Z3 features can still be used by enabling the configuration option "z3_with_extensions"
 boehmes parents: 
47155diff
changeset | 509 | using [[z3_with_extensions]] | 
| 36898 | 510 | by (smt eval_dioph_mod[where n=2] eval_dioph_div_mult[where n=2]) | 
| 511 | ||
| 512 | ||
| 45393 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 513 | context complete_lattice | 
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 514 | begin | 
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 515 | |
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 516 | lemma | 
| 45393 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 517 |   assumes "Sup { a | i::bool . True } \<le> Sup { b | i::bool . True }"
 | 
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 518 |   and     "Sup { b | i::bool . True } \<le> Sup { a | i::bool . True }"
 | 
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 519 |   shows   "Sup { a | i::bool . True } \<le> Sup { a | i::bool . True }"
 | 
| 46084 
dd7fb9e651ad
regenerate SMT example certificates, to reflect "set" type constructor
 blanchet parents: 
45972diff
changeset | 520 | using assms by (smt order_trans) | 
| 45393 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 521 | |
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 522 | end | 
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 523 | |
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 524 | |
| 
13ab80eafd71
try different alternatives in discharging extra assumptions when schematic theorems obtained from lambda-lifting can be instantiated in different ways
 boehmes parents: 
43893diff
changeset | 525 | |
| 36898 | 526 | section {* Monomorphization examples *}
 | 
| 527 | ||
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 528 | definition Pred :: "'a \<Rightarrow> bool" where "Pred x = True" | 
| 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 529 | lemma poly_Pred: "Pred x \<and> (Pred [x] \<or> \<not>Pred[x])" by (simp add: Pred_def) | 
| 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 530 | lemma "Pred (1::int)" by (smt poly_Pred) | 
| 36898 | 531 | |
| 36899 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 532 | axiomatization g :: "'a \<Rightarrow> nat" | 
| 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 533 | axiomatization where | 
| 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 534 | g1: "g (Some x) = g [x]" and | 
| 
bcd6fce5bf06
layered SMT setup, adapted SMT clients, added further tests, made Z3 proof abstraction configurable
 boehmes parents: 
36898diff
changeset | 535 | g2: "g None = g []" and | 
| 36898 | 536 | g3: "g xs = length xs" | 
| 537 | lemma "g (Some (3::int)) = g (Some True)" by (smt g1 g2 g3 list.size) | |
| 538 | ||
| 539 | end |