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