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