src/HOL/SMT_Examples/SMT_Tests.thy
author haftmann
Sat Jul 05 11:01:53 2014 +0200 (2014-07-05)
changeset 57514 bdc2c6b40bf2
parent 57232 8cecd655eef4
child 57696 fb71c6f100f8
permissions -rw-r--r--
prefer ac_simps collections over separate name bindings for add and mult
boehmes@36899
     1
(*  Title:      HOL/SMT_Examples/SMT_Tests.thy
boehmes@36899
     2
    Author:     Sascha Boehme, TU Muenchen
boehmes@36899
     3
*)
boehmes@36899
     4
boehmes@36899
     5
header {* Tests for the SMT binding *}
boehmes@36899
     6
boehmes@36899
     7
theory SMT_Tests
boehmes@36899
     8
imports Complex_Main
boehmes@36899
     9
begin
boehmes@36899
    10
boehmes@36899
    11
smt_status
blanchet@56079
    12
smt2_status
boehmes@36899
    13
boehmes@36899
    14
text {* Most examples are taken from various Isabelle theories and from HOL4. *}
boehmes@36899
    15
boehmes@36899
    16
boehmes@36899
    17
section {* Propositional logic *}
boehmes@36899
    18
boehmes@36899
    19
lemma
boehmes@36899
    20
  "True"
blanchet@57232
    21
  "\<not> False"
blanchet@57232
    22
  "\<not> \<not> True"
boehmes@36899
    23
  "True \<and> True"
boehmes@36899
    24
  "True \<or> False"
boehmes@36899
    25
  "False \<longrightarrow> True"
blanchet@57232
    26
  "\<not> (False \<longleftrightarrow> True)"
blanchet@56079
    27
  by smt2+
boehmes@36899
    28
boehmes@36899
    29
lemma
blanchet@57232
    30
  "P \<or> \<not> P"
blanchet@57232
    31
  "\<not> (P \<and> \<not> P)"
blanchet@57232
    32
  "(True \<and> P) \<or> \<not> P \<or> (False \<and> P) \<or> P"
boehmes@36899
    33
  "P \<longrightarrow> P"
boehmes@36899
    34
  "P \<and> \<not> P \<longrightarrow> False"
boehmes@36899
    35
  "P \<and> Q \<longrightarrow> Q \<and> P"
boehmes@36899
    36
  "P \<or> Q \<longrightarrow> Q \<or> P"
boehmes@36899
    37
  "P \<and> Q \<longrightarrow> P \<or> Q"
blanchet@57232
    38
  "\<not> (P \<or> Q) \<longrightarrow> \<not> P"
blanchet@57232
    39
  "\<not> (P \<or> Q) \<longrightarrow> \<not> Q"
blanchet@57232
    40
  "\<not> P \<longrightarrow> \<not> (P \<and> Q)"
blanchet@57232
    41
  "\<not> Q \<longrightarrow> \<not> (P \<and> Q)"
blanchet@57232
    42
  "(P \<and> Q) \<longleftrightarrow> (\<not> (\<not> P \<or> \<not> Q))"
boehmes@36899
    43
  "(P \<and> Q) \<and> R \<longrightarrow> P \<and> (Q \<and> R)"
boehmes@36899
    44
  "(P \<or> Q) \<or> R \<longrightarrow> P \<or> (Q \<or> R)"
boehmes@36899
    45
  "(P \<and> Q) \<or> R  \<longrightarrow> (P \<or> R) \<and> (Q \<or> R)"
boehmes@36899
    46
  "(P \<or> R) \<and> (Q \<or> R) \<longrightarrow> (P \<and> Q) \<or> R"
boehmes@36899
    47
  "(P \<or> Q) \<and> R \<longrightarrow> (P \<and> R) \<or> (Q \<and> R)"
boehmes@36899
    48
  "(P \<and> R) \<or> (Q \<and> R) \<longrightarrow> (P \<or> Q) \<and> R"
boehmes@36899
    49
  "((P \<longrightarrow> Q) \<longrightarrow> P) \<longrightarrow> P"
boehmes@36899
    50
  "(P \<longrightarrow> R) \<and> (Q \<longrightarrow> R) \<longleftrightarrow> (P \<or> Q \<longrightarrow> R)"
boehmes@36899
    51
  "(P \<and> Q \<longrightarrow> R) \<longleftrightarrow> (P \<longrightarrow> (Q \<longrightarrow> R))"
boehmes@36899
    52
  "((P \<longrightarrow> R) \<longrightarrow> R) \<longrightarrow>  ((Q \<longrightarrow> R) \<longrightarrow> R) \<longrightarrow> (P \<and> Q \<longrightarrow> R) \<longrightarrow> R"
blanchet@57232
    53
  "\<not> (P \<longrightarrow> R) \<longrightarrow>  \<not> (Q \<longrightarrow> R) \<longrightarrow> \<not> (P \<and> Q \<longrightarrow> R)"
boehmes@36899
    54
  "(P \<longrightarrow> Q \<and> R) \<longleftrightarrow> (P \<longrightarrow> Q) \<and> (P \<longrightarrow> R)"
boehmes@36899
    55
  "P \<longrightarrow> (Q \<longrightarrow> P)"
boehmes@36899
    56
  "(P \<longrightarrow> Q \<longrightarrow> R) \<longrightarrow> (P \<longrightarrow> Q)\<longrightarrow> (P \<longrightarrow> R)"
boehmes@36899
    57
  "(P \<longrightarrow> Q) \<or> (P \<longrightarrow> R) \<longrightarrow> (P \<longrightarrow> Q \<or> R)"
boehmes@36899
    58
  "((((P \<longrightarrow> Q) \<longrightarrow> P) \<longrightarrow> P) \<longrightarrow> Q) \<longrightarrow> Q"
blanchet@57232
    59
  "(P \<longrightarrow> Q) \<longrightarrow> (\<not> Q \<longrightarrow> \<not> P)"
boehmes@36899
    60
  "(P \<longrightarrow> Q \<or> R) \<longrightarrow> (P \<longrightarrow> Q) \<or> (P \<longrightarrow> R)"
boehmes@36899
    61
  "(P \<longrightarrow> Q) \<and> (Q  \<longrightarrow> P) \<longrightarrow> (P \<longleftrightarrow> Q)"
boehmes@36899
    62
  "(P \<longleftrightarrow> Q) \<longleftrightarrow> (Q \<longleftrightarrow> P)"
blanchet@57232
    63
  "\<not> (P \<longleftrightarrow> \<not> P)"
blanchet@57232
    64
  "(P \<longrightarrow> Q) \<longleftrightarrow> (\<not> Q \<longrightarrow> \<not> P)"
boehmes@36899
    65
  "P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P \<longleftrightarrow> P"
blanchet@56079
    66
  by smt2+
boehmes@36899
    67
boehmes@36899
    68
lemma
blanchet@57232
    69
  "(if P then Q1 else Q2) \<longleftrightarrow> ((P \<longrightarrow> Q1) \<and> (\<not> P \<longrightarrow> Q2))"
boehmes@36899
    70
  "if P then (Q \<longrightarrow> P) else (P \<longrightarrow> Q)"
boehmes@36899
    71
  "(if P1 \<or> P2 then Q1 else Q2) \<longleftrightarrow> (if P1 then Q1 else if P2 then Q1 else Q2)"
boehmes@36899
    72
  "(if P1 \<and> P2 then Q1 else Q2) \<longleftrightarrow> (if P1 then if P2 then Q1 else Q2 else Q2)"
boehmes@36899
    73
  "(P1 \<longrightarrow> (if P2 then Q1 else Q2)) \<longleftrightarrow>
boehmes@36899
    74
   (if P1 \<longrightarrow> P2 then P1 \<longrightarrow> Q1 else P1 \<longrightarrow> Q2)"
blanchet@56079
    75
  by smt2+
boehmes@36899
    76
boehmes@36899
    77
lemma
blanchet@57232
    78
  "case P of True \<Rightarrow> P | False \<Rightarrow> \<not> P"
blanchet@57232
    79
  "case P of False \<Rightarrow> \<not> P | True \<Rightarrow> P"
blanchet@57232
    80
  "case \<not> P of True \<Rightarrow> \<not> P | False \<Rightarrow> P"
boehmes@36899
    81
  "case P of True \<Rightarrow> (Q \<longrightarrow> P) | False \<Rightarrow> (P \<longrightarrow> Q)"
blanchet@56079
    82
  by smt2+
boehmes@36899
    83
boehmes@36899
    84
boehmes@36899
    85
section {* First-order logic with equality *}
boehmes@36899
    86
boehmes@36899
    87
lemma
boehmes@36899
    88
  "x = x"
boehmes@36899
    89
  "x = y \<longrightarrow> y = x"
boehmes@36899
    90
  "x = y \<and> y = z \<longrightarrow> x = z"
boehmes@36899
    91
  "x = y \<longrightarrow> f x = f y"
boehmes@36899
    92
  "x = y \<longrightarrow> g x y = g y x"
boehmes@36899
    93
  "f (f x) = x \<and> f (f (f (f (f x)))) = x \<longrightarrow> f x = x"
boehmes@36899
    94
  "((if a then b else c) = d) = ((a \<longrightarrow> (b = d)) \<and> (\<not> a \<longrightarrow> (c = d)))"
blanchet@56079
    95
  by smt2+
boehmes@36899
    96
boehmes@36899
    97
lemma
boehmes@36899
    98
  "\<forall>x. x = x"
boehmes@36899
    99
  "(\<forall>x. P x) \<longleftrightarrow> (\<forall>y. P y)"
boehmes@36899
   100
  "\<forall>x. P x \<longrightarrow> (\<forall>y. P x \<or> P y)"
boehmes@36899
   101
  "(\<forall>x. P x \<and> Q x) \<longleftrightarrow> (\<forall>x. P x) \<and> (\<forall>x. Q x)"
boehmes@36899
   102
  "(\<forall>x. P x) \<or> R \<longleftrightarrow> (\<forall>x. P x \<or> R)"
boehmes@36899
   103
  "(\<forall>x y z. S x z) \<longleftrightarrow> (\<forall>x z. S x z)"
boehmes@36899
   104
  "(\<forall>x y. S x y \<longrightarrow> S y x) \<longrightarrow> (\<forall>x. S x y) \<longrightarrow> S y x"
boehmes@36899
   105
  "(\<forall>x. P x \<longrightarrow> P (f x)) \<and> P d \<longrightarrow> P (f(f(f(d))))"
boehmes@36899
   106
  "(\<forall>x y. s x y = s y x) \<longrightarrow> a = a \<and> s a b = s b a"
blanchet@57232
   107
  "(\<forall>s. q s \<longrightarrow> r s) \<and> \<not> r s \<and> (\<forall>s. \<not> r s \<and> \<not> q s \<longrightarrow> p t \<or> q t) \<longrightarrow> p t \<or> r t"
blanchet@56079
   108
  by smt2+
boehmes@36899
   109
boehmes@36899
   110
lemma
blanchet@50662
   111
  "(\<forall>x. P x) \<and> R \<longleftrightarrow> (\<forall>x. P x \<and> R)"
blanchet@56079
   112
  by smt2
blanchet@50662
   113
blanchet@50662
   114
lemma
boehmes@36899
   115
  "\<exists>x. x = x"
boehmes@36899
   116
  "(\<exists>x. P x) \<longleftrightarrow> (\<exists>y. P y)"
boehmes@36899
   117
  "(\<exists>x. P x \<or> Q x) \<longleftrightarrow> (\<exists>x. P x) \<or> (\<exists>x. Q x)"
boehmes@36899
   118
  "(\<exists>x. P x) \<and> R \<longleftrightarrow> (\<exists>x. P x \<and> R)"
boehmes@36899
   119
  "(\<exists>x y z. S x z) \<longleftrightarrow> (\<exists>x z. S x z)"
blanchet@57232
   120
  "\<not> ((\<exists>x. \<not> P x) \<and> ((\<exists>x. P x) \<or> (\<exists>x. P x \<and> Q x)) \<and> \<not> (\<exists>x. P x))"
blanchet@56079
   121
  by smt2+
boehmes@36899
   122
blanchet@49995
   123
lemma
boehmes@36899
   124
  "\<exists>x y. x = y"
boehmes@36899
   125
  "\<exists>x. P x \<longrightarrow> (\<exists>y. P x \<and> P y)"
boehmes@36899
   126
  "(\<exists>x. P x) \<or> R \<longleftrightarrow> (\<exists>x. P x \<or> R)"
boehmes@36899
   127
  "\<exists>x. P x \<longrightarrow> P a \<and> P b"
blanchet@49995
   128
  "\<exists>x. (\<exists>y. P y) \<longrightarrow> P x"
boehmes@36899
   129
  "(\<exists>x. Q \<longrightarrow> P x) \<longleftrightarrow> (Q \<longrightarrow> (\<exists>x. P x))"
blanchet@56727
   130
  by smt2+
boehmes@36899
   131
boehmes@36899
   132
lemma
blanchet@57232
   133
  "(\<not> (\<exists>x. P x)) \<longleftrightarrow> (\<forall>x. \<not> P x)"
boehmes@36899
   134
  "(\<exists>x. P x \<longrightarrow> Q) \<longleftrightarrow> (\<forall>x. P x) \<longrightarrow> Q"
boehmes@36899
   135
  "(\<forall>x y. R x y = x) \<longrightarrow> (\<exists>y. R x y) = R x c"
blanchet@57232
   136
  "(if P x then \<not> (\<exists>y. P y) else (\<forall>y. \<not> P y)) \<longrightarrow> P x \<longrightarrow> P y"
boehmes@36899
   137
  "(\<forall>x y. R x y = x) \<and> (\<forall>x. \<exists>y. R x y) = (\<forall>x. R x c) \<longrightarrow> (\<exists>y. R x y) = R x c"
blanchet@56727
   138
  by smt2+
boehmes@36899
   139
blanchet@49995
   140
lemma
boehmes@41132
   141
  "\<forall>x. \<exists>y. f x y = f x (g x)"
blanchet@57232
   142
  "(\<not> \<not> (\<exists>x. P x)) \<longleftrightarrow> (\<not> (\<forall>x. \<not> P x))"
boehmes@36899
   143
  "\<forall>u. \<exists>v. \<forall>w. \<exists>x. f u v w x = f u (g u) w (h u w)"
boehmes@36899
   144
  "\<exists>x. if x = y then (\<forall>y. y = x \<or> y \<noteq> x) else (\<forall>y. y = (x, x) \<or> y \<noteq> (x, x))"
boehmes@36899
   145
  "\<exists>x. if x = y then (\<exists>y. y = x \<or> y \<noteq> x) else (\<exists>y. y = (x, x) \<or> y \<noteq> (x, x))"
boehmes@36899
   146
  "(\<exists>x. \<forall>y. P x \<longleftrightarrow> P y) \<longrightarrow> ((\<exists>x. P x) \<longleftrightarrow> (\<forall>y. P y))"
boehmes@36899
   147
  "\<exists>z. P z \<longrightarrow> (\<forall>x. P x)"
boehmes@36899
   148
  "(\<exists>y. \<forall>x. R x y) \<longrightarrow> (\<forall>x. \<exists>y. R x y)"
blanchet@56727
   149
  by smt2+
boehmes@36899
   150
boehmes@36899
   151
lemma
blanchet@56079
   152
  "(\<exists>!x. P x) \<longrightarrow> (\<exists>x. P x)"
blanchet@57232
   153
  "(\<exists>!x. P x) \<longleftrightarrow> (\<exists>x. P x \<and> (\<forall>y. y \<noteq> x \<longrightarrow> \<not> P y))"
boehmes@36899
   154
  "P a \<longrightarrow> (\<forall>x. P x \<longrightarrow> x = a) \<longrightarrow> (\<exists>!x. P x)"
boehmes@36899
   155
  "(\<exists>x. P x) \<and> (\<forall>x y. P x \<and> P y \<longrightarrow> x = y) \<longrightarrow> (\<exists>!x. P x)"
boehmes@36899
   156
  "(\<exists>!x. P x) \<and> (\<forall>x. P x \<and> (\<forall>y. P y \<longrightarrow> y = x) \<longrightarrow> R) \<longrightarrow> R"
blanchet@56079
   157
  by smt2+
boehmes@36899
   158
boehmes@36899
   159
lemma
boehmes@37786
   160
  "(\<forall>x\<in>M. P x) \<and> c \<in> M \<longrightarrow> P c"
blanchet@57232
   161
  "(\<exists>x\<in>M. P x) \<or> \<not> (P c \<and> c \<in> M)"
blanchet@56079
   162
  by smt2+
boehmes@37786
   163
boehmes@37786
   164
lemma
boehmes@36899
   165
  "let P = True in P"
blanchet@57232
   166
  "let P = P1 \<or> P2 in P \<or> \<not> P"
boehmes@36899
   167
  "let P1 = True; P2 = False in P1 \<and> P2 \<longrightarrow> P2 \<or> P1"
boehmes@36899
   168
  "(let x = y in x) = y"
boehmes@36899
   169
  "(let x = y in Q x) \<longleftrightarrow> (let z = y in Q z)"
boehmes@36899
   170
  "(let x = y1; z = y2 in R x z) \<longleftrightarrow> (let z = y2; x = y1 in R x z)"
boehmes@36899
   171
  "(let x = y1; z = y2 in R x z) \<longleftrightarrow> (let z = y1; x = y2 in R z x)"
blanchet@57232
   172
  "let P = (\<forall>x. Q x) in if P then P else \<not> P"
blanchet@56079
   173
  by smt2+
boehmes@36899
   174
boehmes@36899
   175
lemma
boehmes@47155
   176
  "a \<noteq> b \<and> a \<noteq> c \<and> b \<noteq> c \<and> (\<forall>x y. f x = f y \<longrightarrow> y = x) \<longrightarrow> f a \<noteq> f b"
blanchet@56079
   177
  by smt2
boehmes@41899
   178
boehmes@41899
   179
lemma
boehmes@41899
   180
  "(\<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"
boehmes@41899
   181
  "(\<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"
blanchet@56079
   182
  by smt2+
boehmes@36899
   183
boehmes@44753
   184
blanchet@57165
   185
section {* Guidance for quantifier heuristics: patterns *}
boehmes@44753
   186
boehmes@37124
   187
lemma
blanchet@57232
   188
  assumes "\<forall>x.
blanchet@57232
   189
    SMT2.trigger (SMT2.Symb_Cons (SMT2.Symb_Cons (SMT2.pat (f x)) SMT2.Symb_Nil) SMT2.Symb_Nil)
blanchet@57232
   190
    (f x = x)"
boehmes@37124
   191
  shows "f 1 = 1"
blanchet@56079
   192
  using assms using [[smt2_trace]] by smt2
boehmes@37124
   193
boehmes@37124
   194
lemma
blanchet@57232
   195
  assumes "\<forall>x y.
blanchet@57232
   196
    SMT2.trigger (SMT2.Symb_Cons (SMT2.Symb_Cons (SMT2.pat (f x))
blanchet@57232
   197
      (SMT2.Symb_Cons (SMT2.pat (g y)) SMT2.Symb_Nil)) SMT2.Symb_Nil) (f x = g y)"
huffman@47108
   198
  shows "f a = g b"
blanchet@56079
   199
  using assms by smt2
boehmes@37124
   200
boehmes@36899
   201
blanchet@56079
   202
section {* Meta-logical connectives *}
boehmes@36899
   203
boehmes@36899
   204
lemma
boehmes@36899
   205
  "True \<Longrightarrow> True"
boehmes@36899
   206
  "False \<Longrightarrow> True"
boehmes@36899
   207
  "False \<Longrightarrow> False"
boehmes@36899
   208
  "P' x \<Longrightarrow> P' x"
boehmes@36899
   209
  "P \<Longrightarrow> P \<or> Q"
boehmes@36899
   210
  "Q \<Longrightarrow> P \<or> Q"
blanchet@57232
   211
  "\<not> P \<Longrightarrow> P \<longrightarrow> Q"
boehmes@36899
   212
  "Q \<Longrightarrow> P \<longrightarrow> Q"
blanchet@57232
   213
  "\<lbrakk>P; \<not> Q\<rbrakk> \<Longrightarrow> \<not> (P \<longrightarrow> Q)"
boehmes@36899
   214
  "P' x \<equiv> P' x"
boehmes@36899
   215
  "P' x \<equiv> Q' x \<Longrightarrow> P' x = Q' x"
boehmes@36899
   216
  "P' x = Q' x \<Longrightarrow> P' x \<equiv> Q' x"
boehmes@36899
   217
  "x \<equiv> y \<Longrightarrow> y \<equiv> z \<Longrightarrow> x \<equiv> (z::'a::type)"
boehmes@36899
   218
  "x \<equiv> y \<Longrightarrow> (f x :: 'b::type) \<equiv> f y"
boehmes@36899
   219
  "(\<And>x. g x) \<Longrightarrow> g a \<or> a"
boehmes@36899
   220
  "(\<And>x y. h x y \<and> h y x) \<Longrightarrow> \<forall>x. h x x"
blanchet@57232
   221
  "(p \<or> q) \<and> \<not> p \<Longrightarrow> q"
boehmes@36899
   222
  "(a \<and> b) \<or> (c \<and> d) \<Longrightarrow> (a \<and> b) \<or> (c \<and> d)"
blanchet@56727
   223
  by smt2+
boehmes@36899
   224
boehmes@36899
   225
boehmes@36899
   226
section {* Natural numbers *}
boehmes@36899
   227
boehmes@36899
   228
lemma
boehmes@36899
   229
  "(0::nat) = 0"
boehmes@36899
   230
  "(1::nat) = 1"
boehmes@36899
   231
  "(0::nat) < 1"
boehmes@36899
   232
  "(0::nat) \<le> 1"
boehmes@36899
   233
  "(123456789::nat) < 2345678901"
blanchet@56079
   234
  by smt2+
boehmes@36899
   235
boehmes@36899
   236
lemma
boehmes@36899
   237
  "Suc 0 = 1"
boehmes@36899
   238
  "Suc x = x + 1"
boehmes@36899
   239
  "x < Suc x"
boehmes@36899
   240
  "(Suc x = Suc y) = (x = y)"
boehmes@36899
   241
  "Suc (x + y) < Suc x + Suc y"
blanchet@56079
   242
  by smt2+
boehmes@36899
   243
boehmes@36899
   244
lemma
boehmes@36899
   245
  "(x::nat) + 0 = x"
boehmes@36899
   246
  "0 + x = x"
boehmes@36899
   247
  "x + y = y + x"
boehmes@36899
   248
  "x + (y + z) = (x + y) + z"
boehmes@36899
   249
  "(x + y = 0) = (x = 0 \<and> y = 0)"
blanchet@56079
   250
  by smt2+
boehmes@36899
   251
blanchet@56079
   252
lemma
boehmes@36899
   253
  "(x::nat) - 0 = x"
boehmes@36899
   254
  "x < y \<longrightarrow> x - y = 0"
boehmes@36899
   255
  "x - y = 0 \<or> y - x = 0"
boehmes@36899
   256
  "(x - y) + y = (if x < y then y else x)"
blanchet@56079
   257
  "x - y - z = x - (y + z)"
blanchet@56079
   258
  by smt2+
boehmes@36899
   259
boehmes@36899
   260
lemma
boehmes@36899
   261
  "(x::nat) * 0 = 0"
boehmes@36899
   262
  "0 * x = 0"
boehmes@36899
   263
  "x * 1 = x"
boehmes@36899
   264
  "1 * x = x"
boehmes@36899
   265
  "3 * x = x * 3"
blanchet@56079
   266
  by smt2+
boehmes@36899
   267
boehmes@36899
   268
lemma
boehmes@36899
   269
  "(0::nat) div 0 = 0"
boehmes@36899
   270
  "(x::nat) div 0 = 0"
boehmes@36899
   271
  "(0::nat) div 1 = 0"
boehmes@36899
   272
  "(1::nat) div 1 = 1"
boehmes@36899
   273
  "(3::nat) div 1 = 3"
boehmes@36899
   274
  "(x::nat) div 1 = x"
boehmes@36899
   275
  "(0::nat) div 3 = 0"
boehmes@36899
   276
  "(1::nat) div 3 = 0"
boehmes@36899
   277
  "(3::nat) div 3 = 1"
boehmes@36899
   278
  "(x::nat) div 3 \<le> x"
boehmes@36899
   279
  "(x div 3 = x) = (x = 0)"
blanchet@56079
   280
  using [[z3_new_extensions]]
blanchet@56079
   281
  by smt2+
boehmes@36899
   282
boehmes@36899
   283
lemma
boehmes@36899
   284
  "(0::nat) mod 0 = 0"
boehmes@36899
   285
  "(x::nat) mod 0 = x"
boehmes@36899
   286
  "(0::nat) mod 1 = 0"
boehmes@36899
   287
  "(1::nat) mod 1 = 0"
boehmes@36899
   288
  "(3::nat) mod 1 = 0"
boehmes@36899
   289
  "(x::nat) mod 1 = 0"
boehmes@36899
   290
  "(0::nat) mod 3 = 0"
boehmes@36899
   291
  "(1::nat) mod 3 = 1"
boehmes@36899
   292
  "(3::nat) mod 3 = 0"
boehmes@36899
   293
  "x mod 3 < 3"
boehmes@36899
   294
  "(x mod 3 = x) = (x < 3)"
blanchet@56079
   295
  using [[z3_new_extensions]]
blanchet@56079
   296
  by smt2+
boehmes@36899
   297
boehmes@36899
   298
lemma
boehmes@36899
   299
  "(x::nat) = x div 1 * 1 + x mod 1"
boehmes@36899
   300
  "x = x div 3 * 3 + x mod 3"
blanchet@56079
   301
  using [[z3_new_extensions]]
blanchet@56079
   302
  by smt2+
boehmes@36899
   303
boehmes@36899
   304
lemma
boehmes@36899
   305
  "min (x::nat) y \<le> x"
boehmes@36899
   306
  "min x y \<le> y"
boehmes@36899
   307
  "min x y \<le> x + y"
boehmes@36899
   308
  "z < x \<and> z < y \<longrightarrow> z < min x y"
boehmes@36899
   309
  "min x y = min y x"
boehmes@36899
   310
  "min x 0 = 0"
blanchet@56079
   311
  by smt2+
boehmes@36899
   312
boehmes@36899
   313
lemma
boehmes@36899
   314
  "max (x::nat) y \<ge> x"
boehmes@36899
   315
  "max x y \<ge> y"
boehmes@36899
   316
  "max x y \<ge> (x - y) + (y - x)"
boehmes@36899
   317
  "z > x \<and> z > y \<longrightarrow> z > max x y"
boehmes@36899
   318
  "max x y = max y x"
boehmes@36899
   319
  "max x 0 = x"
blanchet@56079
   320
  by smt2+
boehmes@36899
   321
boehmes@36899
   322
lemma
boehmes@36899
   323
  "0 \<le> (x::nat)"
boehmes@36899
   324
  "0 < x \<and> x \<le> 1 \<longrightarrow> x = 1"
boehmes@36899
   325
  "x \<le> x"
boehmes@36899
   326
  "x \<le> y \<longrightarrow> 3 * x \<le> 3 * y"
boehmes@36899
   327
  "x < y \<longrightarrow> 3 * x < 3 * y"
boehmes@36899
   328
  "x < y \<longrightarrow> x \<le> y"
boehmes@36899
   329
  "(x < y) = (x + 1 \<le> y)"
blanchet@57232
   330
  "\<not> (x < x)"
boehmes@36899
   331
  "x \<le> y \<longrightarrow> y \<le> z \<longrightarrow> x \<le> z"
boehmes@36899
   332
  "x < y \<longrightarrow> y \<le> z \<longrightarrow> x \<le> z"
boehmes@36899
   333
  "x \<le> y \<longrightarrow> y < z \<longrightarrow> x \<le> z"
boehmes@36899
   334
  "x < y \<longrightarrow> y < z \<longrightarrow> x < z"
blanchet@57232
   335
  "x < y \<and> y < z \<longrightarrow> \<not> (z < x)"
blanchet@56079
   336
  by smt2+
boehmes@36899
   337
boehmes@36899
   338
boehmes@36899
   339
section {* Integers *}
boehmes@36899
   340
boehmes@36899
   341
lemma
boehmes@36899
   342
  "(0::int) = 0"
boehmes@36899
   343
  "(0::int) = (- 0)"
boehmes@36899
   344
  "(1::int) = 1"
blanchet@57232
   345
  "\<not> (-1 = (1::int))"
boehmes@36899
   346
  "(0::int) < 1"
boehmes@36899
   347
  "(0::int) \<le> 1"
boehmes@36899
   348
  "-123 + 345 < (567::int)"
boehmes@36899
   349
  "(123456789::int) < 2345678901"
boehmes@36899
   350
  "(-123456789::int) < 2345678901"
blanchet@56079
   351
  by smt2+
boehmes@36899
   352
boehmes@36899
   353
lemma
boehmes@36899
   354
  "(x::int) + 0 = x"
boehmes@36899
   355
  "0 + x = x"
boehmes@36899
   356
  "x + y = y + x"
boehmes@36899
   357
  "x + (y + z) = (x + y) + z"
boehmes@36899
   358
  "(x + y = 0) = (x = -y)"
blanchet@56079
   359
  by smt2+
boehmes@36899
   360
boehmes@36899
   361
lemma
boehmes@36899
   362
  "(-1::int) = - 1"
boehmes@36899
   363
  "(-3::int) = - 3"
boehmes@36899
   364
  "-(x::int) < 0 \<longleftrightarrow> x > 0"
boehmes@36899
   365
  "x > 0 \<longrightarrow> -x < 0"
boehmes@36899
   366
  "x < 0 \<longrightarrow> -x > 0"
blanchet@56079
   367
  by smt2+
boehmes@36899
   368
blanchet@56079
   369
lemma
boehmes@36899
   370
  "(x::int) - 0 = x"
boehmes@36899
   371
  "0 - x = -x"
boehmes@36899
   372
  "x < y \<longrightarrow> x - y < 0"
boehmes@36899
   373
  "x - y = -(y - x)"
boehmes@36899
   374
  "x - y = -y + x"
blanchet@56079
   375
  "x - y - z = x - (y + z)"
blanchet@56079
   376
  by smt2+
boehmes@36899
   377
boehmes@36899
   378
lemma
boehmes@36899
   379
  "(x::int) * 0 = 0"
boehmes@36899
   380
  "0 * x = 0"
boehmes@36899
   381
  "x * 1 = x"
boehmes@36899
   382
  "1 * x = x"
boehmes@36899
   383
  "x * -1 = -x"
boehmes@36899
   384
  "-1 * x = -x"
boehmes@36899
   385
  "3 * x = x * 3"
blanchet@56079
   386
  by smt2+
boehmes@36899
   387
boehmes@36899
   388
lemma
boehmes@36899
   389
  "(0::int) div 0 = 0"
boehmes@36899
   390
  "(x::int) div 0 = 0"
boehmes@36899
   391
  "(0::int) div 1 = 0"
boehmes@36899
   392
  "(1::int) div 1 = 1"
boehmes@36899
   393
  "(3::int) div 1 = 3"
boehmes@36899
   394
  "(x::int) div 1 = x"
boehmes@37151
   395
  "(0::int) div -1 = 0"
boehmes@37151
   396
  "(1::int) div -1 = -1"
boehmes@37151
   397
  "(3::int) div -1 = -3"
boehmes@37151
   398
  "(x::int) div -1 = -x"
boehmes@36899
   399
  "(0::int) div 3 = 0"
boehmes@37151
   400
  "(0::int) div -3 = 0"
boehmes@36899
   401
  "(1::int) div 3 = 0"
boehmes@36899
   402
  "(3::int) div 3 = 1"
boehmes@37151
   403
  "(5::int) div 3 = 1"
boehmes@37151
   404
  "(1::int) div -3 = -1"
boehmes@37151
   405
  "(3::int) div -3 = -1"
boehmes@37151
   406
  "(5::int) div -3 = -2"
boehmes@37151
   407
  "(-1::int) div 3 = -1"
boehmes@37151
   408
  "(-3::int) div 3 = -1"
boehmes@37151
   409
  "(-5::int) div 3 = -2"
boehmes@37151
   410
  "(-1::int) div -3 = 0"
boehmes@37151
   411
  "(-3::int) div -3 = 1"
boehmes@37151
   412
  "(-5::int) div -3 = 1"
blanchet@56079
   413
  using [[z3_new_extensions]]
blanchet@56079
   414
  by smt2+
boehmes@36899
   415
boehmes@36899
   416
lemma
boehmes@36899
   417
  "(0::int) mod 0 = 0"
boehmes@36899
   418
  "(x::int) mod 0 = x"
boehmes@36899
   419
  "(0::int) mod 1 = 0"
boehmes@36899
   420
  "(1::int) mod 1 = 0"
boehmes@36899
   421
  "(3::int) mod 1 = 0"
boehmes@37151
   422
  "(x::int) mod 1 = 0"
boehmes@37151
   423
  "(0::int) mod -1 = 0"
boehmes@37151
   424
  "(1::int) mod -1 = 0"
boehmes@37151
   425
  "(3::int) mod -1 = 0"
boehmes@37151
   426
  "(x::int) mod -1 = 0"
boehmes@36899
   427
  "(0::int) mod 3 = 0"
boehmes@37151
   428
  "(0::int) mod -3 = 0"
boehmes@36899
   429
  "(1::int) mod 3 = 1"
boehmes@36899
   430
  "(3::int) mod 3 = 0"
boehmes@37151
   431
  "(5::int) mod 3 = 2"
boehmes@37151
   432
  "(1::int) mod -3 = -2"
boehmes@37151
   433
  "(3::int) mod -3 = 0"
boehmes@37151
   434
  "(5::int) mod -3 = -1"
boehmes@37151
   435
  "(-1::int) mod 3 = 2"
boehmes@37151
   436
  "(-3::int) mod 3 = 0"
boehmes@37151
   437
  "(-5::int) mod 3 = 1"
boehmes@37151
   438
  "(-1::int) mod -3 = -1"
boehmes@37151
   439
  "(-3::int) mod -3 = 0"
boehmes@37151
   440
  "(-5::int) mod -3 = -2"
boehmes@36899
   441
  "x mod 3 < 3"
boehmes@37151
   442
  "(x mod 3 = x) \<longrightarrow> (x < 3)"
blanchet@56079
   443
  using [[z3_new_extensions]]
blanchet@56079
   444
  by smt2+
boehmes@36899
   445
boehmes@36899
   446
lemma
boehmes@36899
   447
  "(x::int) = x div 1 * 1 + x mod 1"
boehmes@36899
   448
  "x = x div 3 * 3 + x mod 3"
blanchet@56079
   449
  using [[z3_new_extensions]]
blanchet@56079
   450
  by smt2+
boehmes@36899
   451
boehmes@36899
   452
lemma
boehmes@36899
   453
  "abs (x::int) \<ge> 0"
boehmes@36899
   454
  "(abs x = 0) = (x = 0)"
boehmes@36899
   455
  "(x \<ge> 0) = (abs x = x)"
boehmes@36899
   456
  "(x \<le> 0) = (abs x = -x)"
boehmes@36899
   457
  "abs (abs x) = abs x"
blanchet@56079
   458
  by smt2+
boehmes@36899
   459
boehmes@36899
   460
lemma
boehmes@36899
   461
  "min (x::int) y \<le> x"
boehmes@36899
   462
  "min x y \<le> y"
boehmes@36899
   463
  "z < x \<and> z < y \<longrightarrow> z < min x y"
boehmes@36899
   464
  "min x y = min y x"
boehmes@36899
   465
  "x \<ge> 0 \<longrightarrow> min x 0 = 0"
boehmes@36899
   466
  "min x y \<le> abs (x + y)"
blanchet@56079
   467
  by smt2+
boehmes@36899
   468
boehmes@36899
   469
lemma
boehmes@36899
   470
  "max (x::int) y \<ge> x"
boehmes@36899
   471
  "max x y \<ge> y"
boehmes@36899
   472
  "z > x \<and> z > y \<longrightarrow> z > max x y"
boehmes@36899
   473
  "max x y = max y x"
boehmes@36899
   474
  "x \<ge> 0 \<longrightarrow> max x 0 = x"
boehmes@36899
   475
  "max x y \<ge> - abs x - abs y"
blanchet@56079
   476
  by smt2+
boehmes@36899
   477
boehmes@36899
   478
lemma
boehmes@36899
   479
  "0 < (x::int) \<and> x \<le> 1 \<longrightarrow> x = 1"
boehmes@36899
   480
  "x \<le> x"
boehmes@36899
   481
  "x \<le> y \<longrightarrow> 3 * x \<le> 3 * y"
boehmes@36899
   482
  "x < y \<longrightarrow> 3 * x < 3 * y"
boehmes@36899
   483
  "x < y \<longrightarrow> x \<le> y"
boehmes@36899
   484
  "(x < y) = (x + 1 \<le> y)"
blanchet@57232
   485
  "\<not> (x < x)"
boehmes@36899
   486
  "x \<le> y \<longrightarrow> y \<le> z \<longrightarrow> x \<le> z"
boehmes@36899
   487
  "x < y \<longrightarrow> y \<le> z \<longrightarrow> x \<le> z"
boehmes@36899
   488
  "x \<le> y \<longrightarrow> y < z \<longrightarrow> x \<le> z"
boehmes@36899
   489
  "x < y \<longrightarrow> y < z \<longrightarrow> x < z"
blanchet@57232
   490
  "x < y \<and> y < z \<longrightarrow> \<not> (z < x)"
blanchet@56079
   491
  by smt2+
boehmes@36899
   492
boehmes@36899
   493
boehmes@36899
   494
section {* Reals *}
boehmes@36899
   495
boehmes@36899
   496
lemma
boehmes@36899
   497
  "(0::real) = 0"
boehmes@36899
   498
  "(0::real) = -0"
boehmes@36899
   499
  "(0::real) = (- 0)"
boehmes@36899
   500
  "(1::real) = 1"
blanchet@57232
   501
  "\<not> (-1 = (1::real))"
boehmes@36899
   502
  "(0::real) < 1"
boehmes@36899
   503
  "(0::real) \<le> 1"
boehmes@36899
   504
  "-123 + 345 < (567::real)"
boehmes@36899
   505
  "(123456789::real) < 2345678901"
boehmes@36899
   506
  "(-123456789::real) < 2345678901"
blanchet@56079
   507
  by smt2+
boehmes@36899
   508
boehmes@36899
   509
lemma
boehmes@36899
   510
  "(x::real) + 0 = x"
boehmes@36899
   511
  "0 + x = x"
boehmes@36899
   512
  "x + y = y + x"
boehmes@36899
   513
  "x + (y + z) = (x + y) + z"
boehmes@36899
   514
  "(x + y = 0) = (x = -y)"
blanchet@56079
   515
  by smt2+
boehmes@36899
   516
boehmes@36899
   517
lemma
boehmes@41132
   518
  "(-1::real) = - 1"
boehmes@41132
   519
  "(-3::real) = - 3"
boehmes@36899
   520
  "-(x::real) < 0 \<longleftrightarrow> x > 0"
boehmes@36899
   521
  "x > 0 \<longrightarrow> -x < 0"
boehmes@36899
   522
  "x < 0 \<longrightarrow> -x > 0"
blanchet@56079
   523
  by smt2+
boehmes@36899
   524
blanchet@49995
   525
lemma
boehmes@36899
   526
  "(x::real) - 0 = x"
boehmes@36899
   527
  "0 - x = -x"
boehmes@36899
   528
  "x < y \<longrightarrow> x - y < 0"
boehmes@36899
   529
  "x - y = -(y - x)"
boehmes@36899
   530
  "x - y = -y + x"
blanchet@56079
   531
  "x - y - z = x - (y + z)"
blanchet@56079
   532
  by smt2+
boehmes@36899
   533
boehmes@36899
   534
lemma
boehmes@41132
   535
  "(x::real) * 0 = 0"
boehmes@36899
   536
  "0 * x = 0"
boehmes@36899
   537
  "x * 1 = x"
boehmes@36899
   538
  "1 * x = x"
boehmes@36899
   539
  "x * -1 = -x"
boehmes@36899
   540
  "-1 * x = -x"
boehmes@36899
   541
  "3 * x = x * 3"
blanchet@56079
   542
  by smt2+
boehmes@36899
   543
boehmes@36899
   544
lemma
boehmes@36899
   545
  "(1/2 :: real) < 1"
boehmes@36899
   546
  "(1::real) / 3 = 1 / 3"
boehmes@36899
   547
  "(1::real) / -3 = - 1 / 3"
boehmes@36899
   548
  "(-1::real) / 3 = - 1 / 3"
boehmes@36899
   549
  "(-1::real) / -3 = 1 / 3"
boehmes@36899
   550
  "(x::real) / 1 = x"
boehmes@36899
   551
  "x > 0 \<longrightarrow> x / 3 < x"
boehmes@36899
   552
  "x < 0 \<longrightarrow> x / 3 > x"
blanchet@56079
   553
  using [[z3_new_extensions]]
blanchet@56079
   554
  by smt2+
boehmes@36899
   555
boehmes@36899
   556
lemma
boehmes@36899
   557
  "(3::real) * (x / 3) = x"
boehmes@36899
   558
  "(x * 3) / 3 = x"
boehmes@36899
   559
  "x > 0 \<longrightarrow> 2 * x / 3 < x"
boehmes@36899
   560
  "x < 0 \<longrightarrow> 2 * x / 3 > x"
blanchet@56079
   561
  using [[z3_new_extensions]]
blanchet@56079
   562
  by smt2+
boehmes@36899
   563
boehmes@36899
   564
lemma
boehmes@36899
   565
  "abs (x::real) \<ge> 0"
boehmes@36899
   566
  "(abs x = 0) = (x = 0)"
boehmes@36899
   567
  "(x \<ge> 0) = (abs x = x)"
boehmes@36899
   568
  "(x \<le> 0) = (abs x = -x)"
boehmes@36899
   569
  "abs (abs x) = abs x"
blanchet@56079
   570
  by smt2+
boehmes@36899
   571
boehmes@36899
   572
lemma
boehmes@36899
   573
  "min (x::real) y \<le> x"
boehmes@36899
   574
  "min x y \<le> y"
boehmes@36899
   575
  "z < x \<and> z < y \<longrightarrow> z < min x y"
boehmes@36899
   576
  "min x y = min y x"
boehmes@36899
   577
  "x \<ge> 0 \<longrightarrow> min x 0 = 0"
boehmes@36899
   578
  "min x y \<le> abs (x + y)"
blanchet@56079
   579
  by smt2+
boehmes@36899
   580
boehmes@36899
   581
lemma
boehmes@36899
   582
  "max (x::real) y \<ge> x"
boehmes@36899
   583
  "max x y \<ge> y"
boehmes@36899
   584
  "z > x \<and> z > y \<longrightarrow> z > max x y"
boehmes@36899
   585
  "max x y = max y x"
boehmes@36899
   586
  "x \<ge> 0 \<longrightarrow> max x 0 = x"
boehmes@36899
   587
  "max x y \<ge> - abs x - abs y"
blanchet@56079
   588
  by smt2+
boehmes@36899
   589
boehmes@36899
   590
lemma
boehmes@36899
   591
  "x \<le> (x::real)"
boehmes@36899
   592
  "x \<le> y \<longrightarrow> 3 * x \<le> 3 * y"
boehmes@36899
   593
  "x < y \<longrightarrow> 3 * x < 3 * y"
boehmes@36899
   594
  "x < y \<longrightarrow> x \<le> y"
blanchet@57232
   595
  "\<not> (x < x)"
boehmes@36899
   596
  "x \<le> y \<longrightarrow> y \<le> z \<longrightarrow> x \<le> z"
boehmes@36899
   597
  "x < y \<longrightarrow> y \<le> z \<longrightarrow> x \<le> z"
boehmes@36899
   598
  "x \<le> y \<longrightarrow> y < z \<longrightarrow> x \<le> z"
boehmes@36899
   599
  "x < y \<longrightarrow> y < z \<longrightarrow> x < z"
blanchet@57232
   600
  "x < y \<and> y < z \<longrightarrow> \<not> (z < x)"
blanchet@56079
   601
  by smt2+
boehmes@36899
   602
boehmes@36899
   603
boehmes@41426
   604
section {* Datatypes, Records, and Typedefs *}
boehmes@41426
   605
boehmes@41426
   606
subsection {* Without support by the SMT solver *}
boehmes@41426
   607
boehmes@41426
   608
subsubsection {* Algebraic datatypes *}
boehmes@36899
   609
boehmes@36899
   610
lemma
boehmes@36899
   611
  "x = fst (x, y)"
boehmes@36899
   612
  "y = snd (x, y)"
boehmes@36899
   613
  "((x, y) = (y, x)) = (x = y)"
boehmes@36899
   614
  "((x, y) = (u, v)) = (x = u \<and> y = v)"
boehmes@36899
   615
  "(fst (x, y, z) = fst (u, v, w)) = (x = u)"
boehmes@36899
   616
  "(snd (x, y, z) = snd (u, v, w)) = (y = v \<and> z = w)"
boehmes@36899
   617
  "(fst (snd (x, y, z)) = fst (snd (u, v, w))) = (y = v)"
boehmes@36899
   618
  "(snd (snd (x, y, z)) = snd (snd (u, v, w))) = (z = w)"
boehmes@36899
   619
  "(fst (x, y) = snd (x, y)) = (x = y)"
boehmes@36899
   620
  "p1 = (x, y) \<and> p2 = (y, x) \<longrightarrow> fst p1 = snd p2"
boehmes@36899
   621
  "(fst (x, y) = snd (x, y)) = (x = y)"
boehmes@36899
   622
  "(fst p = snd p) = (p = (snd p, fst p))"
boehmes@41132
   623
  using fst_conv snd_conv pair_collapse
blanchet@56079
   624
  by smt2+
boehmes@36899
   625
boehmes@41426
   626
lemma
boehmes@41426
   627
  "[x] \<noteq> Nil"
boehmes@41426
   628
  "[x, y] \<noteq> Nil"
boehmes@41426
   629
  "x \<noteq> y \<longrightarrow> [x] \<noteq> [y]"
boehmes@41426
   630
  "hd (x # xs) = x"
boehmes@41426
   631
  "tl (x # xs) = xs"
boehmes@41426
   632
  "hd [x, y, z] = x"
boehmes@41426
   633
  "tl [x, y, z] = [y, z]"
boehmes@41426
   634
  "hd (tl [x, y, z]) = y"
boehmes@41426
   635
  "tl (tl [x, y, z]) = [z]"
blanchet@55417
   636
  using list.sel(1,3) list.simps
blanchet@56079
   637
  by smt2+
boehmes@41426
   638
boehmes@41426
   639
lemma
boehmes@41426
   640
  "fst (hd [(a, b)]) = a"
boehmes@41426
   641
  "snd (hd [(a, b)]) = b"
blanchet@55417
   642
  using fst_conv snd_conv pair_collapse list.sel(1,3) list.simps
blanchet@56079
   643
  by smt2+
boehmes@41426
   644
boehmes@41426
   645
boehmes@41426
   646
subsubsection {* Records *}
boehmes@41426
   647
boehmes@41426
   648
record point =
boehmes@41427
   649
  cx :: int
boehmes@41427
   650
  cy :: int
boehmes@41426
   651
boehmes@41426
   652
record bw_point = point +
boehmes@41426
   653
  black :: bool
boehmes@41426
   654
boehmes@41426
   655
lemma
boehmes@41427
   656
  "p1 = p2 \<longrightarrow> cx p1 = cx p2"
boehmes@41427
   657
  "p1 = p2 \<longrightarrow> cy p1 = cy p2"
boehmes@41427
   658
  "cx p1 \<noteq> cx p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41427
   659
  "cy p1 \<noteq> cy p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41426
   660
  using point.simps
blanchet@56079
   661
  by smt2+
boehmes@41426
   662
boehmes@41426
   663
lemma
boehmes@41427
   664
  "cx \<lparr> cx = 3, cy = 4 \<rparr> = 3"
boehmes@41427
   665
  "cy \<lparr> cx = 3, cy = 4 \<rparr> = 4"
boehmes@41427
   666
  "cx \<lparr> cx = 3, cy = 4 \<rparr> \<noteq> cy \<lparr> cx = 3, cy = 4 \<rparr>"
boehmes@41427
   667
  "\<lparr> cx = 3, cy = 4 \<rparr> \<lparr> cx := 5 \<rparr> = \<lparr> cx = 5, cy = 4 \<rparr>"
boehmes@41427
   668
  "\<lparr> cx = 3, cy = 4 \<rparr> \<lparr> cy := 6 \<rparr> = \<lparr> cx = 3, cy = 6 \<rparr>"
boehmes@41427
   669
  "p = \<lparr> cx = 3, cy = 4 \<rparr> \<longrightarrow> p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> = p"
boehmes@41427
   670
  "p = \<lparr> cx = 3, cy = 4 \<rparr> \<longrightarrow> p \<lparr> cy := 4 \<rparr> \<lparr> cx := 3 \<rparr> = p"
boehmes@41426
   671
  using point.simps
blanchet@56079
   672
  by smt2+
boehmes@41426
   673
boehmes@41426
   674
lemma
boehmes@41427
   675
  "cy (p \<lparr> cx := a \<rparr>) = cy p"
boehmes@41427
   676
  "cx (p \<lparr> cy := a \<rparr>) = cx p"
boehmes@41427
   677
  "p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> = p \<lparr> cy := 4 \<rparr> \<lparr> cx := 3 \<rparr>"
boehmes@41426
   678
  sorry
boehmes@41426
   679
boehmes@41426
   680
lemma
boehmes@41427
   681
  "p1 = p2 \<longrightarrow> cx p1 = cx p2"
boehmes@41427
   682
  "p1 = p2 \<longrightarrow> cy p1 = cy p2"
boehmes@41426
   683
  "p1 = p2 \<longrightarrow> black p1 = black p2"
boehmes@41427
   684
  "cx p1 \<noteq> cx p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41427
   685
  "cy p1 \<noteq> cy p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41426
   686
  "black p1 \<noteq> black p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41426
   687
  using point.simps bw_point.simps
blanchet@56079
   688
  by smt2+
boehmes@41426
   689
boehmes@41426
   690
lemma
boehmes@41427
   691
  "cx \<lparr> cx = 3, cy = 4, black = b \<rparr> = 3"
boehmes@41427
   692
  "cy \<lparr> cx = 3, cy = 4, black = b \<rparr> = 4"
boehmes@41427
   693
  "black \<lparr> cx = 3, cy = 4, black = b \<rparr> = b"
boehmes@41427
   694
  "cx \<lparr> cx = 3, cy = 4, black = b \<rparr> \<noteq> cy \<lparr> cx = 3, cy = 4, black = b \<rparr>"
boehmes@41427
   695
  "\<lparr> cx = 3, cy = 4, black = b \<rparr> \<lparr> cx := 5 \<rparr> = \<lparr> cx = 5, cy = 4, black = b \<rparr>"
boehmes@41427
   696
  "\<lparr> cx = 3, cy = 4, black = b \<rparr> \<lparr> cy := 6 \<rparr> = \<lparr> cx = 3, cy = 6, black = b \<rparr>"
boehmes@41427
   697
  "p = \<lparr> cx = 3, cy = 4, black = True \<rparr> \<longrightarrow>
boehmes@41427
   698
     p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> \<lparr> black := True \<rparr> = p"
boehmes@41427
   699
  "p = \<lparr> cx = 3, cy = 4, black = True \<rparr> \<longrightarrow>
boehmes@41427
   700
     p \<lparr> cy := 4 \<rparr> \<lparr> black := True \<rparr> \<lparr> cx := 3 \<rparr> = p"
boehmes@41427
   701
  "p = \<lparr> cx = 3, cy = 4, black = True \<rparr> \<longrightarrow>
boehmes@41427
   702
     p \<lparr> black := True \<rparr> \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> = p"
boehmes@41426
   703
  using point.simps bw_point.simps
blanchet@56859
   704
  by smt+ (* smt2 FIXME: bad Z3 4.3.x proof *)
boehmes@41426
   705
boehmes@41426
   706
lemma
boehmes@41427
   707
  "\<lparr> cx = 3, cy = 4, black = b \<rparr> \<lparr> black := w \<rparr> = \<lparr> cx = 3, cy = 4, black = w \<rparr>"
boehmes@41427
   708
  "\<lparr> cx = 3, cy = 4, black = True \<rparr> \<lparr> black := False \<rparr> =
boehmes@41427
   709
     \<lparr> cx = 3, cy = 4, black = False \<rparr>"
boehmes@41427
   710
  "p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> \<lparr> black := True \<rparr> =
boehmes@41427
   711
     p \<lparr> black := True \<rparr> \<lparr> cy := 4 \<rparr> \<lparr> cx := 3 \<rparr>"
boehmes@41426
   712
  sorry
boehmes@41426
   713
boehmes@41426
   714
boehmes@41426
   715
subsubsection {* Type definitions *}
boehmes@41426
   716
blanchet@57214
   717
typedef int' = "UNIV::int set" by (rule UNIV_witness)
boehmes@41426
   718
blanchet@57214
   719
definition n0 where "n0 = Abs_int' 0"
blanchet@57214
   720
definition n1 where "n1 = Abs_int' 1"
blanchet@57214
   721
definition n2 where "n2 = Abs_int' 2"
blanchet@57214
   722
definition plus' where "plus' n m = Abs_int' (Rep_int' n + Rep_int' m)"
boehmes@41426
   723
boehmes@41426
   724
lemma
blanchet@57214
   725
  "n0 \<noteq> n1"
blanchet@57214
   726
  "plus' n1 n1 = n2"
blanchet@57214
   727
  "plus' n0 n2 = n2"
blanchet@57214
   728
  by (smt2 n0_def n1_def n2_def plus'_def Abs_int'_inverse Rep_int'_inverse UNIV_I)+
boehmes@41426
   729
boehmes@41426
   730
boehmes@41426
   731
subsection {* With support by the SMT solver (but without proofs) *}
boehmes@41426
   732
boehmes@41426
   733
subsubsection {* Algebraic datatypes *}
boehmes@41426
   734
boehmes@41426
   735
lemma
boehmes@41426
   736
  "x = fst (x, y)"
boehmes@41426
   737
  "y = snd (x, y)"
boehmes@41426
   738
  "((x, y) = (y, x)) = (x = y)"
boehmes@41426
   739
  "((x, y) = (u, v)) = (x = u \<and> y = v)"
boehmes@41426
   740
  "(fst (x, y, z) = fst (u, v, w)) = (x = u)"
boehmes@41426
   741
  "(snd (x, y, z) = snd (u, v, w)) = (y = v \<and> z = w)"
boehmes@41426
   742
  "(fst (snd (x, y, z)) = fst (snd (u, v, w))) = (y = v)"
boehmes@41426
   743
  "(snd (snd (x, y, z)) = snd (snd (u, v, w))) = (z = w)"
boehmes@41426
   744
  "(fst (x, y) = snd (x, y)) = (x = y)"
boehmes@41426
   745
  "p1 = (x, y) \<and> p2 = (y, x) \<longrightarrow> fst p1 = snd p2"
boehmes@41426
   746
  "(fst (x, y) = snd (x, y)) = (x = y)"
boehmes@41426
   747
  "(fst p = snd p) = (p = (snd p, fst p))"
boehmes@41426
   748
  using fst_conv snd_conv pair_collapse
blanchet@56079
   749
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   750
  by smt2+
boehmes@41426
   751
boehmes@41426
   752
lemma
boehmes@41426
   753
  "[x] \<noteq> Nil"
boehmes@41426
   754
  "[x, y] \<noteq> Nil"
boehmes@41426
   755
  "x \<noteq> y \<longrightarrow> [x] \<noteq> [y]"
boehmes@41426
   756
  "hd (x # xs) = x"
boehmes@41426
   757
  "tl (x # xs) = xs"
boehmes@41426
   758
  "hd [x, y, z] = x"
boehmes@41426
   759
  "tl [x, y, z] = [y, z]"
boehmes@41426
   760
  "hd (tl [x, y, z]) = y"
boehmes@41426
   761
  "tl (tl [x, y, z]) = [z]"
blanchet@55417
   762
  using list.sel(1,3)
blanchet@56079
   763
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   764
  by smt2+
boehmes@41426
   765
boehmes@41426
   766
lemma
boehmes@41426
   767
  "fst (hd [(a, b)]) = a"
boehmes@41426
   768
  "snd (hd [(a, b)]) = b"
blanchet@55417
   769
  using fst_conv snd_conv pair_collapse list.sel(1,3)
blanchet@56079
   770
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   771
  by smt2+
boehmes@41426
   772
boehmes@41426
   773
boehmes@41426
   774
subsubsection {* Records *}
boehmes@41426
   775
boehmes@41426
   776
lemma
boehmes@41427
   777
  "p1 = p2 \<longrightarrow> cx p1 = cx p2"
boehmes@41427
   778
  "p1 = p2 \<longrightarrow> cy p1 = cy p2"
boehmes@41427
   779
  "cx p1 \<noteq> cx p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41427
   780
  "cy p1 \<noteq> cy p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41426
   781
  using point.simps
blanchet@56079
   782
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   783
  by smt2+
boehmes@41426
   784
boehmes@41426
   785
lemma
boehmes@41427
   786
  "cx \<lparr> cx = 3, cy = 4 \<rparr> = 3"
boehmes@41427
   787
  "cy \<lparr> cx = 3, cy = 4 \<rparr> = 4"
boehmes@41427
   788
  "cx \<lparr> cx = 3, cy = 4 \<rparr> \<noteq> cy \<lparr> cx = 3, cy = 4 \<rparr>"
boehmes@41427
   789
  "\<lparr> cx = 3, cy = 4 \<rparr> \<lparr> cx := 5 \<rparr> = \<lparr> cx = 5, cy = 4 \<rparr>"
boehmes@41427
   790
  "\<lparr> cx = 3, cy = 4 \<rparr> \<lparr> cy := 6 \<rparr> = \<lparr> cx = 3, cy = 6 \<rparr>"
boehmes@41427
   791
  "p = \<lparr> cx = 3, cy = 4 \<rparr> \<longrightarrow> p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> = p"
boehmes@41427
   792
  "p = \<lparr> cx = 3, cy = 4 \<rparr> \<longrightarrow> p \<lparr> cy := 4 \<rparr> \<lparr> cx := 3 \<rparr> = p"
boehmes@41426
   793
  using point.simps
blanchet@56079
   794
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   795
  by smt2+
boehmes@41426
   796
boehmes@41426
   797
lemma
boehmes@41427
   798
  "cy (p \<lparr> cx := a \<rparr>) = cy p"
boehmes@41427
   799
  "cx (p \<lparr> cy := a \<rparr>) = cx p"
boehmes@41427
   800
  "p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> = p \<lparr> cy := 4 \<rparr> \<lparr> cx := 3 \<rparr>"
boehmes@41426
   801
  using point.simps
blanchet@56079
   802
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   803
  by smt2+
boehmes@41426
   804
boehmes@41426
   805
lemma
boehmes@41427
   806
  "p1 = p2 \<longrightarrow> cx p1 = cx p2"
boehmes@41427
   807
  "p1 = p2 \<longrightarrow> cy p1 = cy p2"
boehmes@41426
   808
  "p1 = p2 \<longrightarrow> black p1 = black p2"
boehmes@41427
   809
  "cx p1 \<noteq> cx p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41427
   810
  "cy p1 \<noteq> cy p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41426
   811
  "black p1 \<noteq> black p2 \<longrightarrow> p1 \<noteq> p2"
boehmes@41426
   812
  using point.simps bw_point.simps
blanchet@56079
   813
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   814
  by smt2+
boehmes@41426
   815
boehmes@41426
   816
lemma
boehmes@41427
   817
  "cx \<lparr> cx = 3, cy = 4, black = b \<rparr> = 3"
boehmes@41427
   818
  "cy \<lparr> cx = 3, cy = 4, black = b \<rparr> = 4"
boehmes@41427
   819
  "black \<lparr> cx = 3, cy = 4, black = b \<rparr> = b"
boehmes@41427
   820
  "cx \<lparr> cx = 3, cy = 4, black = b \<rparr> \<noteq> cy \<lparr> cx = 3, cy = 4, black = b \<rparr>"
boehmes@41427
   821
  "\<lparr> cx = 3, cy = 4, black = b \<rparr> \<lparr> cx := 5 \<rparr> = \<lparr> cx = 5, cy = 4, black = b \<rparr>"
boehmes@41427
   822
  "\<lparr> cx = 3, cy = 4, black = b \<rparr> \<lparr> cy := 6 \<rparr> = \<lparr> cx = 3, cy = 6, black = b \<rparr>"
boehmes@41427
   823
  "p = \<lparr> cx = 3, cy = 4, black = True \<rparr> \<longrightarrow>
boehmes@41427
   824
     p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> \<lparr> black := True \<rparr> = p"
boehmes@41427
   825
  "p = \<lparr> cx = 3, cy = 4, black = True \<rparr> \<longrightarrow>
boehmes@41427
   826
     p \<lparr> cy := 4 \<rparr> \<lparr> black := True \<rparr> \<lparr> cx := 3 \<rparr> = p"
boehmes@41427
   827
  "p = \<lparr> cx = 3, cy = 4, black = True \<rparr> \<longrightarrow>
boehmes@41427
   828
     p \<lparr> black := True \<rparr> \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> = p"
boehmes@41426
   829
  using point.simps bw_point.simps
blanchet@56079
   830
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   831
  by smt2+
boehmes@41426
   832
boehmes@41426
   833
lemma
boehmes@41427
   834
  "\<lparr> cx = 3, cy = 4, black = b \<rparr> \<lparr> black := w \<rparr> = \<lparr> cx = 3, cy = 4, black = w \<rparr>"
boehmes@41427
   835
  "\<lparr> cx = 3, cy = 4, black = True \<rparr> \<lparr> black := False \<rparr> =
boehmes@41427
   836
     \<lparr> cx = 3, cy = 4, black = False \<rparr>"
boehmes@41427
   837
  sorry
boehmes@41427
   838
boehmes@41427
   839
lemma
boehmes@41427
   840
  "p \<lparr> cx := 3 \<rparr> \<lparr> cy := 4 \<rparr> \<lparr> black := True \<rparr> =
boehmes@41427
   841
     p \<lparr> black := True \<rparr> \<lparr> cy := 4 \<rparr> \<lparr> cx := 3 \<rparr>"
boehmes@41426
   842
  using point.simps bw_point.simps
blanchet@56079
   843
  using [[smt2_oracle, z3_new_extensions]]
blanchet@56079
   844
  by smt2
boehmes@41426
   845
boehmes@41426
   846
boehmes@41426
   847
subsubsection {* Type definitions *}
boehmes@41426
   848
boehmes@41426
   849
lemma
blanchet@57214
   850
  "n0 \<noteq> n1"
blanchet@57214
   851
  "plus' n1 n1 = n2"
blanchet@57214
   852
  "plus' n0 n2 = n2"
blanchet@56079
   853
  using [[smt2_oracle, z3_new_extensions]]
blanchet@57214
   854
  by (smt2 n0_def n1_def n2_def plus'_def)+
boehmes@37157
   855
boehmes@37157
   856
boehmes@37157
   857
section {* Function updates *}
boehmes@37157
   858
boehmes@37157
   859
lemma
boehmes@37157
   860
  "(f (i := v)) i = v"
boehmes@37157
   861
  "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v)) i2 = f i2"
boehmes@37157
   862
  "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v1, i2 := v2)) i1 = v1"
boehmes@37157
   863
  "i1 \<noteq> i2 \<longrightarrow> (f (i1 := v1, i2 := v2)) i2 = v2"
boehmes@37157
   864
  "i1 = i2 \<longrightarrow> (f (i1 := v1, i2 := v2)) i1 = v2"
boehmes@37157
   865
  "i1 = i2 \<longrightarrow> (f (i1 := v1, i2 := v2)) i1 = v2"
boehmes@47155
   866
  "i1 \<noteq> i2 \<and>i1 \<noteq> i3 \<and>  i2 \<noteq> i3 \<longrightarrow> (f (i1 := v1, i2 := v2)) i3 = f i3"
boehmes@41132
   867
  using fun_upd_same fun_upd_apply
blanchet@56079
   868
  by smt2+
boehmes@37157
   869
boehmes@37157
   870
boehmes@37157
   871
section {* Sets *}
boehmes@37157
   872
boehmes@44925
   873
lemma Empty: "x \<notin> {}" by simp
boehmes@44925
   874
blanchet@56079
   875
lemmas smt2_sets = Empty UNIV_I Un_iff Int_iff
boehmes@37157
   876
boehmes@37157
   877
lemma
boehmes@37157
   878
  "x \<notin> {}"
boehmes@37157
   879
  "x \<in> UNIV"
boehmes@44925
   880
  "x \<in> A \<union> B \<longleftrightarrow> x \<in> A \<or> x \<in> B"
boehmes@44925
   881
  "x \<in> P \<union> {} \<longleftrightarrow> x \<in> P"
boehmes@37157
   882
  "x \<in> P \<union> UNIV"
boehmes@44925
   883
  "x \<in> P \<union> Q \<longleftrightarrow> x \<in> Q \<union> P"
boehmes@44925
   884
  "x \<in> P \<union> P \<longleftrightarrow> x \<in> P"
boehmes@44925
   885
  "x \<in> P \<union> (Q \<union> R) \<longleftrightarrow> x \<in> (P \<union> Q) \<union> R"
boehmes@44925
   886
  "x \<in> A \<inter> B \<longleftrightarrow> x \<in> A \<and> x \<in> B"
boehmes@37157
   887
  "x \<notin> P \<inter> {}"
boehmes@44925
   888
  "x \<in> P \<inter> UNIV \<longleftrightarrow> x \<in> P"
boehmes@44925
   889
  "x \<in> P \<inter> Q \<longleftrightarrow> x \<in> Q \<inter> P"
boehmes@44925
   890
  "x \<in> P \<inter> P \<longleftrightarrow> x \<in> P"
boehmes@44925
   891
  "x \<in> P \<inter> (Q \<inter> R) \<longleftrightarrow> x \<in> (P \<inter> Q) \<inter> R"
boehmes@44925
   892
  "{x. x \<in> P} = {y. y \<in> P}"
blanchet@56079
   893
  by (smt2 smt2_sets)+
boehmes@37157
   894
boehmes@36899
   895
end