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