src/HOL/SMT/SMT_Base.thy
author boehmes
Tue, 16 Feb 2010 15:25:36 +0100
changeset 35140 117247018b54
parent 35105 1822c658a5e4
child 35943 51b9155467cc
permissions -rw-r--r--
added Cache_IO: cache for output of external tools,
changed SMT solver interface to use Cache_IO
boehmes@33006
     1
(*  Title:      HOL/SMT/SMT_Base.thy
boehmes@33006
     2
    Author:     Sascha Boehme, TU Muenchen
boehmes@33006
     3
*)
boehmes@33006
     4
boehmes@33006
     5
header {* SMT-specific definitions and basic tools *}
boehmes@33006
     6
boehmes@33006
     7
theory SMT_Base
boehmes@35105
     8
imports Real "~~/src/HOL/Word/Word"
boehmes@35105
     9
  "~~/src/HOL/Decision_Procs/Dense_Linear_Order"
boehmes@33006
    10
uses
boehmes@35140
    11
  "~~/src/Tools/Cache_IO/cache_io.ML"
boehmes@33006
    12
  ("Tools/smt_normalize.ML")
boehmes@33006
    13
  ("Tools/smt_monomorph.ML")
boehmes@33006
    14
  ("Tools/smt_translate.ML")
boehmes@33006
    15
  ("Tools/smt_solver.ML")
boehmes@33006
    16
  ("Tools/smtlib_interface.ML")
boehmes@33006
    17
begin
boehmes@33006
    18
boehmes@33006
    19
section {* Triggers for quantifier instantiation *}
boehmes@33006
    20
boehmes@33006
    21
text {*
boehmes@33006
    22
Some SMT solvers support triggers for quantifier instantiation. Each trigger
boehmes@33006
    23
consists of one ore more patterns. A pattern may either be a list of positive
boehmes@33006
    24
subterms (the first being tagged by "pat" and the consecutive subterms tagged
boehmes@33006
    25
by "andpat"), or a list of negative subterms (the first being tagged by "nopat"
boehmes@33006
    26
and the consecutive subterms tagged by "andpat").
boehmes@33006
    27
*}
boehmes@33006
    28
boehmes@33006
    29
datatype pattern = Pattern
boehmes@33006
    30
boehmes@33006
    31
definition pat :: "'a \<Rightarrow> pattern"
boehmes@33006
    32
where "pat _ = Pattern"
boehmes@33006
    33
boehmes@33241
    34
definition nopat :: "'a \<Rightarrow> pattern"
boehmes@33006
    35
where "nopat _ = Pattern"
boehmes@33006
    36
boehmes@33006
    37
definition andpat :: "pattern \<Rightarrow> 'a \<Rightarrow> pattern" (infixl "andpat" 60)
boehmes@33006
    38
where "_ andpat _ = Pattern"
boehmes@33006
    39
boehmes@33006
    40
definition trigger :: "pattern list \<Rightarrow> bool \<Rightarrow> bool"
boehmes@33006
    41
where "trigger _ P = P"
boehmes@33006
    42
boehmes@33006
    43
boehmes@33006
    44
section {* Arithmetic *}
boehmes@33006
    45
boehmes@33006
    46
text {*
boehmes@33006
    47
The sign of @{term "op mod :: int \<Rightarrow> int \<Rightarrow> int"} follows the sign of the
boehmes@33006
    48
divisor. In contrast to that, the sign of the following operation is that of
boehmes@33006
    49
the dividend.
boehmes@33006
    50
*}
boehmes@33006
    51
boehmes@33006
    52
definition rem :: "int \<Rightarrow> int \<Rightarrow> int" (infixl "rem" 70)
boehmes@33006
    53
where "a rem b = 
boehmes@33006
    54
  (if (a \<ge> 0 \<and> b < 0) \<or> (a < 0 \<and> b \<ge> 0) then - (a mod b) else a mod b)"
boehmes@33006
    55
boehmes@33006
    56
text {* A decision procedure for linear real arithmetic: *}
boehmes@33006
    57
boehmes@33006
    58
setup {*
boehmes@33006
    59
  Arith_Data.add_tactic "Ferrante-Rackoff" (K FerranteRackoff.dlo_tac)
boehmes@33006
    60
*}
boehmes@33006
    61
boehmes@33006
    62
boehmes@33006
    63
section {* Bitvectors *}
boehmes@33006
    64
boehmes@33006
    65
text {*
boehmes@33006
    66
The following definitions provide additional functions not found in HOL-Word.
boehmes@33006
    67
*}
boehmes@33006
    68
boehmes@33006
    69
definition sdiv :: "'a::len word \<Rightarrow> 'a word \<Rightarrow> 'a word" (infix "sdiv" 70)
boehmes@33006
    70
where "w1 sdiv w2 = word_of_int (sint w1 div sint w2)"
boehmes@33006
    71
boehmes@33006
    72
definition smod :: "'a::len word \<Rightarrow> 'a word \<Rightarrow> 'a word" (infix "smod" 70)
boehmes@33006
    73
  (* sign follows divisor *)
boehmes@33006
    74
where "w1 smod w2 = word_of_int (sint w1 mod sint w2)"
boehmes@33006
    75
boehmes@33006
    76
definition srem :: "'a::len word \<Rightarrow> 'a word \<Rightarrow> 'a word" (infix "srem" 70)
boehmes@33006
    77
  (* sign follows dividend *)
boehmes@33006
    78
where "w1 srem w2 = word_of_int (sint w1 rem sint w2)"
boehmes@33006
    79
boehmes@33006
    80
definition bv_shl :: "'a::len0 word \<Rightarrow> 'a word \<Rightarrow> 'a word"
boehmes@33006
    81
where "bv_shl w1 w2 = (w1 << unat w2)"
boehmes@33006
    82
boehmes@33006
    83
definition bv_lshr :: "'a::len0 word \<Rightarrow> 'a word \<Rightarrow> 'a word"
boehmes@33006
    84
where "bv_lshr w1 w2 = (w1 >> unat w2)"
boehmes@33006
    85
boehmes@33006
    86
definition bv_ashr :: "'a::len word \<Rightarrow> 'a word \<Rightarrow> 'a word"
boehmes@33006
    87
where "bv_ashr w1 w2 = (w1 >>> unat w2)"
boehmes@33006
    88
boehmes@33006
    89
boehmes@33006
    90
section {* Higher-Order Encoding *}
boehmes@33006
    91
boehmes@33006
    92
definition "apply" where "apply f x = f x"
boehmes@33006
    93
boehmes@34947
    94
definition array_ext where "array_ext a b = (SOME x. a = b \<or> a x \<noteq> b x)"
boehmes@34947
    95
boehmes@34947
    96
lemma fun_upd_eq: "(f = f (x := y)) = (f x = y)"
boehmes@34947
    97
proof
boehmes@34947
    98
  assume "f = f(x:=y)"
boehmes@34947
    99
  hence "f x = (f(x:=y)) x" by simp
boehmes@34947
   100
  thus "f x = y" by simp
boehmes@34947
   101
qed (auto simp add: ext)
boehmes@34947
   102
boehmes@34947
   103
lemmas array_rules =
boehmes@34947
   104
  ext fun_upd_apply fun_upd_same fun_upd_other fun_upd_upd fun_upd_eq apply_def
boehmes@33006
   105
boehmes@33006
   106
boehmes@33006
   107
section {* First-order logic *}
boehmes@33006
   108
boehmes@33006
   109
text {*
boehmes@33006
   110
Some SMT solver formats require a strict separation between formulas and terms.
boehmes@33006
   111
The following marker symbols are used internally to separate those categories:
boehmes@33006
   112
*}
boehmes@33006
   113
boehmes@33006
   114
definition formula :: "bool \<Rightarrow> bool" where "formula x = x"
boehmes@33006
   115
definition "term" where "term x = x"
boehmes@33006
   116
boehmes@33006
   117
text {*
boehmes@33006
   118
Predicate symbols also occurring as function symbols are turned into function
boehmes@33006
   119
symbols by translating atomic formulas into terms:
boehmes@33006
   120
*}
boehmes@33006
   121
boehmes@33006
   122
abbreviation holds :: "bool \<Rightarrow> bool" where "holds \<equiv> (\<lambda>P. term P = term True)"
boehmes@33006
   123
boehmes@33006
   124
text {*
boehmes@33006
   125
The following constant represents equivalence, to be treated differently than
boehmes@33006
   126
the (polymorphic) equality predicate:
boehmes@33006
   127
*}
boehmes@33006
   128
boehmes@33006
   129
definition iff :: "bool \<Rightarrow> bool \<Rightarrow> bool" (infix "iff" 50) where
boehmes@33006
   130
  "(x iff y) = (x = y)"
boehmes@33006
   131
boehmes@33006
   132
boehmes@33006
   133
section {* Setup *}
boehmes@33006
   134
boehmes@33006
   135
use "Tools/smt_normalize.ML"
boehmes@33006
   136
use "Tools/smt_monomorph.ML"
boehmes@33006
   137
use "Tools/smt_translate.ML"
boehmes@33006
   138
use "Tools/smt_solver.ML"
boehmes@33006
   139
use "Tools/smtlib_interface.ML"
boehmes@33006
   140
boehmes@33006
   141
setup {* SMT_Normalize.setup #> SMT_Solver.setup *}
boehmes@33006
   142
boehmes@33006
   143
end