src/HOL/SMT_Examples/SMT_Examples.thy
author paulson <lp15@cam.ac.uk>
Tue Apr 25 16:39:54 2017 +0100 (2017-04-25)
changeset 65578 e4997c181cce
parent 63167 0909deb8059b
child 66298 5ff9fe3fee66
permissions -rw-r--r--
New material from PNT proof, as well as more default [simp] declarations. Also removed duplicate theorems about geometric series
boehmes@36899
     1
(*  Title:      HOL/SMT_Examples/SMT_Examples.thy
boehmes@36898
     2
    Author:     Sascha Boehme, TU Muenchen
boehmes@36898
     3
*)
boehmes@36898
     4
wenzelm@63167
     5
section \<open>Examples for the SMT binding\<close>
boehmes@36898
     6
boehmes@36898
     7
theory SMT_Examples
boehmes@36899
     8
imports Complex_Main
boehmes@36898
     9
begin
boehmes@36898
    10
blanchet@58367
    11
declare [[smt_certificates = "SMT_Examples.certs"]]
blanchet@58061
    12
declare [[smt_read_only_certificates = true]]
boehmes@36898
    13
boehmes@36898
    14
wenzelm@63167
    15
section \<open>Propositional and first-order logic\<close>
boehmes@36898
    16
blanchet@58061
    17
lemma "True" by smt
blanchet@58061
    18
lemma "p \<or> \<not>p" by smt
blanchet@58061
    19
lemma "(p \<and> True) = p" by smt
blanchet@58061
    20
lemma "(p \<or> q) \<and> \<not>p \<Longrightarrow> q" by smt
blanchet@58061
    21
lemma "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)" by smt
blanchet@58061
    22
lemma "(p1 \<and> p2) \<or> p3 \<longrightarrow> (p1 \<longrightarrow> (p3 \<and> p2) \<or> (p1 \<and> p3)) \<or> p1" by smt
blanchet@58061
    23
lemma "P = P = P = P = P = P = P = P = P = P" by smt
boehmes@36898
    24
blanchet@46084
    25
lemma
blanchet@56079
    26
  assumes "a \<or> b \<or> c \<or> d"
blanchet@56079
    27
      and "e \<or> f \<or> (a \<and> d)"
blanchet@56079
    28
      and "\<not> (a \<or> (c \<and> ~c)) \<or> b"
blanchet@56079
    29
      and "\<not> (b \<and> (x \<or> \<not> x)) \<or> c"
blanchet@56079
    30
      and "\<not> (d \<or> False) \<or> c"
blanchet@56079
    31
      and "\<not> (c \<or> (\<not> p \<and> (p \<or> (q \<and> \<not> q))))"
boehmes@36898
    32
  shows False
blanchet@58061
    33
  using assms by smt
boehmes@36898
    34
boehmes@36898
    35
axiomatization symm_f :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" where
boehmes@36898
    36
  symm_f: "symm_f x y = symm_f y x"
blanchet@56109
    37
blanchet@58061
    38
lemma "a = a \<and> symm_f a b = symm_f b a" by (smt symm_f)
boehmes@36898
    39
blanchet@46084
    40
(*
boehmes@36898
    41
Taken from ~~/src/HOL/ex/SAT_Examples.thy.
boehmes@36898
    42
Translated from TPTP problem library: PUZ015-2.006.dimacs
boehmes@36898
    43
*)
blanchet@46084
    44
lemma
boehmes@36898
    45
  assumes "~x0"
boehmes@36898
    46
  and "~x30"
boehmes@36898
    47
  and "~x29"
boehmes@36898
    48
  and "~x59"
blanchet@56079
    49
  and "x1 \<or> x31 \<or> x0"
blanchet@56079
    50
  and "x2 \<or> x32 \<or> x1"
blanchet@56079
    51
  and "x3 \<or> x33 \<or> x2"
blanchet@56079
    52
  and "x4 \<or> x34 \<or> x3"
blanchet@56079
    53
  and "x35 \<or> x4"
blanchet@56079
    54
  and "x5 \<or> x36 \<or> x30"
blanchet@56079
    55
  and "x6 \<or> x37 \<or> x5 \<or> x31"
blanchet@56079
    56
  and "x7 \<or> x38 \<or> x6 \<or> x32"
blanchet@56079
    57
  and "x8 \<or> x39 \<or> x7 \<or> x33"
blanchet@56079
    58
  and "x9 \<or> x40 \<or> x8 \<or> x34"
blanchet@56079
    59
  and "x41 \<or> x9 \<or> x35"
blanchet@56079
    60
  and "x10 \<or> x42 \<or> x36"
blanchet@56079
    61
  and "x11 \<or> x43 \<or> x10 \<or> x37"
blanchet@56079
    62
  and "x12 \<or> x44 \<or> x11 \<or> x38"
blanchet@56079
    63
  and "x13 \<or> x45 \<or> x12 \<or> x39"
blanchet@56079
    64
  and "x14 \<or> x46 \<or> x13 \<or> x40"
blanchet@56079
    65
  and "x47 \<or> x14 \<or> x41"
blanchet@56079
    66
  and "x15 \<or> x48 \<or> x42"
blanchet@56079
    67
  and "x16 \<or> x49 \<or> x15 \<or> x43"
blanchet@56079
    68
  and "x17 \<or> x50 \<or> x16 \<or> x44"
blanchet@56079
    69
  and "x18 \<or> x51 \<or> x17 \<or> x45"
blanchet@56079
    70
  and "x19 \<or> x52 \<or> x18 \<or> x46"
blanchet@56079
    71
  and "x53 \<or> x19 \<or> x47"
blanchet@56079
    72
  and "x20 \<or> x54 \<or> x48"
blanchet@56079
    73
  and "x21 \<or> x55 \<or> x20 \<or> x49"
blanchet@56079
    74
  and "x22 \<or> x56 \<or> x21 \<or> x50"
blanchet@56079
    75
  and "x23 \<or> x57 \<or> x22 \<or> x51"
blanchet@56079
    76
  and "x24 \<or> x58 \<or> x23 \<or> x52"
blanchet@56079
    77
  and "x59 \<or> x24 \<or> x53"
blanchet@56079
    78
  and "x25 \<or> x54"
blanchet@56079
    79
  and "x26 \<or> x25 \<or> x55"
blanchet@56079
    80
  and "x27 \<or> x26 \<or> x56"
blanchet@56079
    81
  and "x28 \<or> x27 \<or> x57"
blanchet@56079
    82
  and "x29 \<or> x28 \<or> x58"
blanchet@56079
    83
  and "~x1 \<or> ~x31"
blanchet@56079
    84
  and "~x1 \<or> ~x0"
blanchet@56079
    85
  and "~x31 \<or> ~x0"
blanchet@56079
    86
  and "~x2 \<or> ~x32"
blanchet@56079
    87
  and "~x2 \<or> ~x1"
blanchet@56079
    88
  and "~x32 \<or> ~x1"
blanchet@56079
    89
  and "~x3 \<or> ~x33"
blanchet@56079
    90
  and "~x3 \<or> ~x2"
blanchet@56079
    91
  and "~x33 \<or> ~x2"
blanchet@56079
    92
  and "~x4 \<or> ~x34"
blanchet@56079
    93
  and "~x4 \<or> ~x3"
blanchet@56079
    94
  and "~x34 \<or> ~x3"
blanchet@56079
    95
  and "~x35 \<or> ~x4"
blanchet@56079
    96
  and "~x5 \<or> ~x36"
blanchet@56079
    97
  and "~x5 \<or> ~x30"
blanchet@56079
    98
  and "~x36 \<or> ~x30"
blanchet@56079
    99
  and "~x6 \<or> ~x37"
blanchet@56079
   100
  and "~x6 \<or> ~x5"
blanchet@56079
   101
  and "~x6 \<or> ~x31"
blanchet@56079
   102
  and "~x37 \<or> ~x5"
blanchet@56079
   103
  and "~x37 \<or> ~x31"
blanchet@56079
   104
  and "~x5 \<or> ~x31"
blanchet@56079
   105
  and "~x7 \<or> ~x38"
blanchet@56079
   106
  and "~x7 \<or> ~x6"
blanchet@56079
   107
  and "~x7 \<or> ~x32"
blanchet@56079
   108
  and "~x38 \<or> ~x6"
blanchet@56079
   109
  and "~x38 \<or> ~x32"
blanchet@56079
   110
  and "~x6 \<or> ~x32"
blanchet@56079
   111
  and "~x8 \<or> ~x39"
blanchet@56079
   112
  and "~x8 \<or> ~x7"
blanchet@56079
   113
  and "~x8 \<or> ~x33"
blanchet@56079
   114
  and "~x39 \<or> ~x7"
blanchet@56079
   115
  and "~x39 \<or> ~x33"
blanchet@56079
   116
  and "~x7 \<or> ~x33"
blanchet@56079
   117
  and "~x9 \<or> ~x40"
blanchet@56079
   118
  and "~x9 \<or> ~x8"
blanchet@56079
   119
  and "~x9 \<or> ~x34"
blanchet@56079
   120
  and "~x40 \<or> ~x8"
blanchet@56079
   121
  and "~x40 \<or> ~x34"
blanchet@56079
   122
  and "~x8 \<or> ~x34"
blanchet@56079
   123
  and "~x41 \<or> ~x9"
blanchet@56079
   124
  and "~x41 \<or> ~x35"
blanchet@56079
   125
  and "~x9 \<or> ~x35"
blanchet@56079
   126
  and "~x10 \<or> ~x42"
blanchet@56079
   127
  and "~x10 \<or> ~x36"
blanchet@56079
   128
  and "~x42 \<or> ~x36"
blanchet@56079
   129
  and "~x11 \<or> ~x43"
blanchet@56079
   130
  and "~x11 \<or> ~x10"
blanchet@56079
   131
  and "~x11 \<or> ~x37"
blanchet@56079
   132
  and "~x43 \<or> ~x10"
blanchet@56079
   133
  and "~x43 \<or> ~x37"
blanchet@56079
   134
  and "~x10 \<or> ~x37"
blanchet@56079
   135
  and "~x12 \<or> ~x44"
blanchet@56079
   136
  and "~x12 \<or> ~x11"
blanchet@56079
   137
  and "~x12 \<or> ~x38"
blanchet@56079
   138
  and "~x44 \<or> ~x11"
blanchet@56079
   139
  and "~x44 \<or> ~x38"
blanchet@56079
   140
  and "~x11 \<or> ~x38"
blanchet@56079
   141
  and "~x13 \<or> ~x45"
blanchet@56079
   142
  and "~x13 \<or> ~x12"
blanchet@56079
   143
  and "~x13 \<or> ~x39"
blanchet@56079
   144
  and "~x45 \<or> ~x12"
blanchet@56079
   145
  and "~x45 \<or> ~x39"
blanchet@56079
   146
  and "~x12 \<or> ~x39"
blanchet@56079
   147
  and "~x14 \<or> ~x46"
blanchet@56079
   148
  and "~x14 \<or> ~x13"
blanchet@56079
   149
  and "~x14 \<or> ~x40"
blanchet@56079
   150
  and "~x46 \<or> ~x13"
blanchet@56079
   151
  and "~x46 \<or> ~x40"
blanchet@56079
   152
  and "~x13 \<or> ~x40"
blanchet@56079
   153
  and "~x47 \<or> ~x14"
blanchet@56079
   154
  and "~x47 \<or> ~x41"
blanchet@56079
   155
  and "~x14 \<or> ~x41"
blanchet@56079
   156
  and "~x15 \<or> ~x48"
blanchet@56079
   157
  and "~x15 \<or> ~x42"
blanchet@56079
   158
  and "~x48 \<or> ~x42"
blanchet@56079
   159
  and "~x16 \<or> ~x49"
blanchet@56079
   160
  and "~x16 \<or> ~x15"
blanchet@56079
   161
  and "~x16 \<or> ~x43"
blanchet@56079
   162
  and "~x49 \<or> ~x15"
blanchet@56079
   163
  and "~x49 \<or> ~x43"
blanchet@56079
   164
  and "~x15 \<or> ~x43"
blanchet@56079
   165
  and "~x17 \<or> ~x50"
blanchet@56079
   166
  and "~x17 \<or> ~x16"
blanchet@56079
   167
  and "~x17 \<or> ~x44"
blanchet@56079
   168
  and "~x50 \<or> ~x16"
blanchet@56079
   169
  and "~x50 \<or> ~x44"
blanchet@56079
   170
  and "~x16 \<or> ~x44"
blanchet@56079
   171
  and "~x18 \<or> ~x51"
blanchet@56079
   172
  and "~x18 \<or> ~x17"
blanchet@56079
   173
  and "~x18 \<or> ~x45"
blanchet@56079
   174
  and "~x51 \<or> ~x17"
blanchet@56079
   175
  and "~x51 \<or> ~x45"
blanchet@56079
   176
  and "~x17 \<or> ~x45"
blanchet@56079
   177
  and "~x19 \<or> ~x52"
blanchet@56079
   178
  and "~x19 \<or> ~x18"
blanchet@56079
   179
  and "~x19 \<or> ~x46"
blanchet@56079
   180
  and "~x52 \<or> ~x18"
blanchet@56079
   181
  and "~x52 \<or> ~x46"
blanchet@56079
   182
  and "~x18 \<or> ~x46"
blanchet@56079
   183
  and "~x53 \<or> ~x19"
blanchet@56079
   184
  and "~x53 \<or> ~x47"
blanchet@56079
   185
  and "~x19 \<or> ~x47"
blanchet@56079
   186
  and "~x20 \<or> ~x54"
blanchet@56079
   187
  and "~x20 \<or> ~x48"
blanchet@56079
   188
  and "~x54 \<or> ~x48"
blanchet@56079
   189
  and "~x21 \<or> ~x55"
blanchet@56079
   190
  and "~x21 \<or> ~x20"
blanchet@56079
   191
  and "~x21 \<or> ~x49"
blanchet@56079
   192
  and "~x55 \<or> ~x20"
blanchet@56079
   193
  and "~x55 \<or> ~x49"
blanchet@56079
   194
  and "~x20 \<or> ~x49"
blanchet@56079
   195
  and "~x22 \<or> ~x56"
blanchet@56079
   196
  and "~x22 \<or> ~x21"
blanchet@56079
   197
  and "~x22 \<or> ~x50"
blanchet@56079
   198
  and "~x56 \<or> ~x21"
blanchet@56079
   199
  and "~x56 \<or> ~x50"
blanchet@56079
   200
  and "~x21 \<or> ~x50"
blanchet@56079
   201
  and "~x23 \<or> ~x57"
blanchet@56079
   202
  and "~x23 \<or> ~x22"
blanchet@56079
   203
  and "~x23 \<or> ~x51"
blanchet@56079
   204
  and "~x57 \<or> ~x22"
blanchet@56079
   205
  and "~x57 \<or> ~x51"
blanchet@56079
   206
  and "~x22 \<or> ~x51"
blanchet@56079
   207
  and "~x24 \<or> ~x58"
blanchet@56079
   208
  and "~x24 \<or> ~x23"
blanchet@56079
   209
  and "~x24 \<or> ~x52"
blanchet@56079
   210
  and "~x58 \<or> ~x23"
blanchet@56079
   211
  and "~x58 \<or> ~x52"
blanchet@56079
   212
  and "~x23 \<or> ~x52"
blanchet@56079
   213
  and "~x59 \<or> ~x24"
blanchet@56079
   214
  and "~x59 \<or> ~x53"
blanchet@56079
   215
  and "~x24 \<or> ~x53"
blanchet@56079
   216
  and "~x25 \<or> ~x54"
blanchet@56079
   217
  and "~x26 \<or> ~x25"
blanchet@56079
   218
  and "~x26 \<or> ~x55"
blanchet@56079
   219
  and "~x25 \<or> ~x55"
blanchet@56079
   220
  and "~x27 \<or> ~x26"
blanchet@56079
   221
  and "~x27 \<or> ~x56"
blanchet@56079
   222
  and "~x26 \<or> ~x56"
blanchet@56079
   223
  and "~x28 \<or> ~x27"
blanchet@56079
   224
  and "~x28 \<or> ~x57"
blanchet@56079
   225
  and "~x27 \<or> ~x57"
blanchet@56079
   226
  and "~x29 \<or> ~x28"
blanchet@56079
   227
  and "~x29 \<or> ~x58"
blanchet@56079
   228
  and "~x28 \<or> ~x58"
boehmes@36898
   229
  shows False
blanchet@58061
   230
  using assms by smt
boehmes@36898
   231
boehmes@36898
   232
lemma "\<forall>x::int. P x \<longrightarrow> (\<forall>y::int. P x \<or> P y)"
blanchet@58061
   233
  by smt
boehmes@36898
   234
blanchet@46084
   235
lemma
boehmes@36898
   236
  assumes "(\<forall>x y. P x y = x)"
boehmes@36898
   237
  shows "(\<exists>y. P x y) = P x c"
blanchet@58061
   238
  using assms by smt
boehmes@36898
   239
blanchet@46084
   240
lemma
boehmes@36898
   241
  assumes "(\<forall>x y. P x y = x)"
boehmes@36898
   242
  and "(\<forall>x. \<exists>y. P x y) = (\<forall>x. P x c)"
boehmes@36898
   243
  shows "(EX y. P x y) = P x c"
blanchet@58061
   244
  using assms by smt
boehmes@36898
   245
boehmes@36898
   246
lemma
boehmes@36898
   247
  assumes "if P x then \<not>(\<exists>y. P y) else (\<forall>y. \<not>P y)"
boehmes@36898
   248
  shows "P x \<longrightarrow> P y"
blanchet@58061
   249
  using assms by smt
boehmes@36898
   250
boehmes@36898
   251
wenzelm@63167
   252
section \<open>Arithmetic\<close>
boehmes@36898
   253
wenzelm@63167
   254
subsection \<open>Linear arithmetic over integers and reals\<close>
boehmes@36898
   255
blanchet@58061
   256
lemma "(3::int) = 3" by smt
blanchet@58061
   257
lemma "(3::real) = 3" by smt
blanchet@58061
   258
lemma "(3 :: int) + 1 = 4" by smt
blanchet@58061
   259
lemma "x + (y + z) = y + (z + (x::int))" by smt
blanchet@58061
   260
lemma "max (3::int) 8 > 5" by smt
wenzelm@61945
   261
lemma "\<bar>x :: real\<bar> + \<bar>y\<bar> \<ge> \<bar>x + y\<bar>" by smt
blanchet@58061
   262
lemma "P ((2::int) < 3) = P True" by smt
blanchet@58061
   263
lemma "x + 3 \<ge> 4 \<or> x < (1::int)" by smt
boehmes@36898
   264
boehmes@36898
   265
lemma
boehmes@36898
   266
  assumes "x \<ge> (3::int)" and "y = x + 4"
blanchet@46084
   267
  shows "y - x > 0"
blanchet@58061
   268
  using assms by smt
boehmes@36898
   269
blanchet@58061
   270
lemma "let x = (2 :: int) in x + x \<noteq> 5" by smt
boehmes@36898
   271
boehmes@36898
   272
lemma
boehmes@36898
   273
  fixes x :: real
boehmes@36898
   274
  assumes "3 * x + 7 * a < 4" and "3 < 2 * x"
boehmes@36898
   275
  shows "a < 0"
blanchet@58061
   276
  using assms by smt
boehmes@36898
   277
blanchet@58061
   278
lemma "(0 \<le> y + -1 * x \<or> \<not> 0 \<le> x \<or> 0 \<le> (x::int)) = (\<not> False)" by smt
boehmes@36898
   279
boehmes@36898
   280
lemma "
blanchet@56079
   281
  (n < m \<and> m < n') \<or> (n < m \<and> m = n') \<or> (n < n' \<and> n' < m) \<or>
blanchet@56079
   282
  (n = n' \<and> n' < m) \<or> (n = m \<and> m < n') \<or>
blanchet@56079
   283
  (n' < m \<and> m < n) \<or> (n' < m \<and> m = n) \<or>
blanchet@56079
   284
  (n' < n \<and> n < m) \<or> (n' = n \<and> n < m) \<or> (n' = m \<and> m < n) \<or>
blanchet@56079
   285
  (m < n \<and> n < n') \<or> (m < n \<and> n' = n) \<or> (m < n' \<and> n' < n) \<or>
blanchet@56079
   286
  (m = n \<and> n < n') \<or> (m = n' \<and> n' < n) \<or>
blanchet@56079
   287
  (n' = m \<and> m = (n::int))"
blanchet@58061
   288
  by smt
boehmes@36898
   289
wenzelm@63167
   290
text\<open>
boehmes@36898
   291
The following example was taken from HOL/ex/PresburgerEx.thy, where it says:
boehmes@36898
   292
boehmes@36898
   293
  This following theorem proves that all solutions to the
boehmes@36898
   294
  recurrence relation $x_{i+2} = |x_{i+1}| - x_i$ are periodic with
boehmes@36898
   295
  period 9.  The example was brought to our attention by John
boehmes@36898
   296
  Harrison. It does does not require Presburger arithmetic but merely
boehmes@36898
   297
  quantifier-free linear arithmetic and holds for the rationals as well.
boehmes@36898
   298
blanchet@46084
   299
  Warning: it takes (in 2006) over 4.2 minutes!
boehmes@36898
   300
boehmes@36898
   301
There, it is proved by "arith". SMT is able to prove this within a fraction
boehmes@36898
   302
of one second. With proof reconstruction, it takes about 13 seconds on a Core2
boehmes@36898
   303
processor.
wenzelm@63167
   304
\<close>
boehmes@36898
   305
wenzelm@61945
   306
lemma "\<lbrakk> x3 = \<bar>x2\<bar> - x1; x4 = \<bar>x3\<bar> - x2; x5 = \<bar>x4\<bar> - x3;
wenzelm@61945
   307
         x6 = \<bar>x5\<bar> - x4; x7 = \<bar>x6\<bar> - x5; x8 = \<bar>x7\<bar> - x6;
wenzelm@61945
   308
         x9 = \<bar>x8\<bar> - x7; x10 = \<bar>x9\<bar> - x8; x11 = \<bar>x10\<bar> - x9 \<rbrakk>
blanchet@56079
   309
 \<Longrightarrow> x1 = x10 \<and> x2 = (x11::int)"
blanchet@58061
   310
  by smt
boehmes@36898
   311
boehmes@36898
   312
blanchet@58061
   313
lemma "let P = 2 * x + 1 > x + (x::real) in P \<or> False \<or> P" by smt
boehmes@36898
   314
boehmes@48069
   315
lemma "x + (let y = x mod 2 in 2 * y + 1) \<ge> x + (1::int)"
blanchet@58061
   316
  using [[z3_extensions]] by smt
boehmes@36898
   317
boehmes@48069
   318
lemma "x + (let y = x mod 2 in y + y) < x + (3::int)"
blanchet@58061
   319
  using [[z3_extensions]] by smt
boehmes@36898
   320
boehmes@36898
   321
lemma
boehmes@36898
   322
  assumes "x \<noteq> (0::real)"
wenzelm@61945
   323
  shows "x + x \<noteq> (let P = (\<bar>x\<bar> > 1) in if P \<or> \<not> P then 4 else 2) * x"
blanchet@58061
   324
  using assms [[z3_extensions]] by smt
boehmes@36898
   325
boehmes@36898
   326
wenzelm@63167
   327
subsection \<open>Linear arithmetic with quantifiers\<close>
boehmes@36898
   328
blanchet@58061
   329
lemma "~ (\<exists>x::int. False)" by smt
blanchet@58061
   330
lemma "~ (\<exists>x::real. False)" by smt
boehmes@36898
   331
blanchet@58061
   332
lemma "\<exists>x::int. 0 < x" by smt
boehmes@36898
   333
boehmes@36898
   334
lemma "\<exists>x::real. 0 < x"
blanchet@58061
   335
  using [[smt_oracle=true]] (* no Z3 proof *)
blanchet@58061
   336
  by smt
boehmes@36898
   337
blanchet@58061
   338
lemma "\<forall>x::int. \<exists>y. y > x" by smt
boehmes@36898
   339
blanchet@58061
   340
lemma "\<forall>x y::int. (x = 0 \<and> y = 1) \<longrightarrow> x \<noteq> y" by smt
blanchet@58061
   341
lemma "\<exists>x::int. \<forall>y. x < y \<longrightarrow> y < 0 \<or> y >= 0" by smt
blanchet@58061
   342
lemma "\<forall>x y::int. x < y \<longrightarrow> (2 * x + 1) < (2 * y)" by smt
blanchet@58061
   343
lemma "\<forall>x y::int. (2 * x + 1) \<noteq> (2 * y)" by smt
blanchet@58061
   344
lemma "\<forall>x y::int. x + y > 2 \<or> x + y = 2 \<or> x + y < 2" by smt
blanchet@58061
   345
lemma "\<forall>x::int. if x > 0 then x + 1 > 0 else 1 > x" by smt
blanchet@58061
   346
lemma "if (ALL x::int. x < 0 \<or> x > 0) then False else True" by smt
blanchet@58061
   347
lemma "(if (ALL x::int. x < 0 \<or> x > 0) then -1 else 3) > (0::int)" by smt
blanchet@58061
   348
lemma "~ (\<exists>x y z::int. 4 * x + -6 * y = (1::int))" by smt
blanchet@58061
   349
lemma "\<exists>x::int. \<forall>x y. 0 < x \<and> 0 < y \<longrightarrow> (0::int) < x + y" by smt
blanchet@58061
   350
lemma "\<exists>u::int. \<forall>(x::int) y::real. 0 < x \<and> 0 < y \<longrightarrow> -1 < x" by smt
blanchet@58061
   351
lemma "\<exists>x::int. (\<forall>y. y \<ge> x \<longrightarrow> y > 0) \<longrightarrow> x > 0" by smt
blanchet@58061
   352
lemma "\<forall>(a::int) b::int. 0 < b \<or> b < 1" by smt
boehmes@42318
   353
boehmes@36898
   354
wenzelm@63167
   355
subsection \<open>Non-linear arithmetic over integers and reals\<close>
boehmes@36898
   356
boehmes@36898
   357
lemma "a > (0::int) \<Longrightarrow> a*b > 0 \<Longrightarrow> b > 0"
blanchet@58061
   358
  using [[smt_oracle, z3_extensions]]
blanchet@58061
   359
  by smt
boehmes@36899
   360
boehmes@41282
   361
lemma  "(a::int) * (x + 1 + y) = a * x + a * (y + 1)"
blanchet@58061
   362
  using [[z3_extensions]]
blanchet@58061
   363
  by smt
boehmes@36898
   364
boehmes@41282
   365
lemma "((x::real) * (1 + y) - x * (1 - y)) = (2 * x * y)"
blanchet@58061
   366
  using [[z3_extensions]]
blanchet@58061
   367
  by smt
boehmes@36898
   368
boehmes@36898
   369
lemma
boehmes@36898
   370
  "(U::int) + (1 + p) * (b + e) + p * d =
boehmes@36898
   371
   U + (2 * (1 + p) * (b + e) + (1 + p) * d + d * p) - (1 + p) * (b + d + e)"
blanchet@58061
   372
  using [[z3_extensions]] by smt
boehmes@36898
   373
blanchet@58061
   374
lemma [z3_rule]:
boehmes@43893
   375
  fixes x :: "int"
boehmes@43893
   376
  assumes "x * y \<le> 0" and "\<not> y \<le> 0" and "\<not> x \<le> 0"
boehmes@43893
   377
  shows False
boehmes@43893
   378
  using assms by (metis mult_le_0_iff)
boehmes@43893
   379
boehmes@36898
   380
wenzelm@63167
   381
section \<open>Pairs\<close>
boehmes@36898
   382
boehmes@41132
   383
lemma "fst (x, y) = a \<Longrightarrow> x = a"
blanchet@58061
   384
  using fst_conv by smt
boehmes@36898
   385
boehmes@41132
   386
lemma "p1 = (x, y) \<and> p2 = (y, x) \<Longrightarrow> fst p1 = snd p2"
blanchet@58061
   387
  using fst_conv snd_conv by smt
boehmes@36898
   388
boehmes@36898
   389
wenzelm@63167
   390
section \<open>Higher-order problems and recursion\<close>
boehmes@36898
   391
boehmes@41132
   392
lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> (f (i1 := v1, i2 := v2)) i = f i"
blanchet@58061
   393
  using fun_upd_same fun_upd_apply by smt
boehmes@36898
   394
boehmes@36898
   395
lemma "(f g (x::'a::type) = (g x \<and> True)) \<or> (f g x = True) \<or> (g x = True)"
blanchet@58061
   396
  by smt
boehmes@36898
   397
blanchet@56109
   398
lemma "id x = x \<and> id True = True"
blanchet@58061
   399
  by (smt id_def)
boehmes@36898
   400
boehmes@41132
   401
lemma "i \<noteq> i1 \<and> i \<noteq> i2 \<Longrightarrow> ((f (i1 := v1)) (i2 := v2)) i = f i"
blanchet@58061
   402
  using fun_upd_same fun_upd_apply by smt
boehmes@36898
   403
boehmes@41786
   404
lemma
boehmes@41786
   405
  "f (\<exists>x. g x) \<Longrightarrow> True"
boehmes@41786
   406
  "f (\<forall>x. g x) \<Longrightarrow> True"
blanchet@58061
   407
  by smt+
boehmes@36899
   408
blanchet@58061
   409
lemma True using let_rsp by smt
blanchet@58061
   410
lemma "le = op \<le> \<Longrightarrow> le (3::int) 42" by smt
blanchet@58061
   411
lemma "map (\<lambda>i::int. i + 1) [0, 1] = [1, 2]" by (smt list.map)
blanchet@58061
   412
lemma "(ALL x. P x) \<or> ~ All P" by smt
boehmes@36898
   413
blanchet@57696
   414
fun dec_10 :: "int \<Rightarrow> int" where
boehmes@36898
   415
  "dec_10 n = (if n < 10 then n else dec_10 (n - 10))"
blanchet@56109
   416
blanchet@58061
   417
lemma "dec_10 (4 * dec_10 4) = 6" by (smt dec_10.simps)
boehmes@36898
   418
boehmes@36898
   419
axiomatization
blanchet@57696
   420
  eval_dioph :: "int list \<Rightarrow> int list \<Rightarrow> int"
blanchet@56109
   421
where
blanchet@57696
   422
  eval_dioph_mod: "eval_dioph ks xs mod n = eval_dioph ks (map (\<lambda>x. x mod n) xs) mod n"
blanchet@56109
   423
and
boehmes@36898
   424
  eval_dioph_div_mult:
blanchet@57696
   425
  "eval_dioph ks (map (\<lambda>x. x div n) xs) * n +
boehmes@36898
   426
   eval_dioph ks (map (\<lambda>x. x mod n) xs) = eval_dioph ks xs"
blanchet@56109
   427
boehmes@36898
   428
lemma
boehmes@36898
   429
  "(eval_dioph ks xs = l) =
boehmes@36898
   430
   (eval_dioph ks (map (\<lambda>x. x mod 2) xs) mod 2 = l mod 2 \<and>
blanchet@57696
   431
    eval_dioph ks (map (\<lambda>x. x div 2) xs) = (l - eval_dioph ks (map (\<lambda>x. x mod 2) xs)) div 2)"
blanchet@58061
   432
  using [[smt_oracle = true]] (*FIXME*)
blanchet@58061
   433
  using [[z3_extensions]]
blanchet@58061
   434
  by (smt eval_dioph_mod[where n=2] eval_dioph_div_mult[where n=2])
boehmes@36898
   435
boehmes@36898
   436
boehmes@45393
   437
context complete_lattice
boehmes@45393
   438
begin
boehmes@45393
   439
blanchet@46084
   440
lemma
blanchet@56079
   441
  assumes "Sup {a | i::bool. True} \<le> Sup {b | i::bool. True}"
blanchet@56079
   442
  and "Sup {b | i::bool. True} \<le> Sup {a | i::bool. True}"
blanchet@56079
   443
  shows "Sup {a | i::bool. True} \<le> Sup {a | i::bool. True}"
blanchet@58061
   444
  using assms by (smt order_trans)
boehmes@45393
   445
boehmes@45393
   446
end
boehmes@45393
   447
boehmes@45393
   448
wenzelm@63167
   449
section \<open>Monomorphization examples\<close>
boehmes@36898
   450
boehmes@36899
   451
definition Pred :: "'a \<Rightarrow> bool" where "Pred x = True"
blanchet@56079
   452
blanchet@56079
   453
lemma poly_Pred: "Pred x \<and> (Pred [x] \<or> \<not> Pred [x])" by (simp add: Pred_def)
blanchet@56109
   454
blanchet@58061
   455
lemma "Pred (1::int)" by (smt poly_Pred)
boehmes@36898
   456
boehmes@36899
   457
axiomatization g :: "'a \<Rightarrow> nat"
boehmes@36899
   458
axiomatization where
boehmes@36899
   459
  g1: "g (Some x) = g [x]" and
boehmes@36899
   460
  g2: "g None = g []" and
boehmes@36898
   461
  g3: "g xs = length xs"
blanchet@56079
   462
blanchet@58061
   463
lemma "g (Some (3::int)) = g (Some True)" by (smt g1 g2 g3 list.size)
boehmes@36898
   464
boehmes@36898
   465
end