src/HOL/SMT.thy
author blanchet
Wed Aug 30 23:36:21 2017 +0200 (22 months ago)
changeset 66559 beb48215cda7
parent 66551 4df6b0ae900d
child 66817 0b12755ccbb2
permissions -rw-r--r--
added options to make veriT more complete
blanchet@58061
     1
(*  Title:      HOL/SMT.thy
blanchet@56078
     2
    Author:     Sascha Boehme, TU Muenchen
blanchet@66551
     3
    Author:     Jasmin Blanchette, VU Amsterdam
blanchet@56078
     4
*)
blanchet@56078
     5
wenzelm@61626
     6
section \<open>Bindings to Satisfiability Modulo Theories (SMT) solvers based on SMT-LIB 2\<close>
blanchet@56078
     7
blanchet@58061
     8
theory SMT
blanchet@66551
     9
  imports Divides
blanchet@66551
    10
  keywords "smt_status" :: diag
blanchet@56078
    11
begin
blanchet@56078
    12
wenzelm@60758
    13
subsection \<open>A skolemization tactic and proof method\<close>
blanchet@58481
    14
blanchet@58481
    15
lemma choices:
blanchet@58481
    16
  "\<And>Q. \<forall>x. \<exists>y ya. Q x y ya \<Longrightarrow> \<exists>f fa. \<forall>x. Q x (f x) (fa x)"
blanchet@58481
    17
  "\<And>Q. \<forall>x. \<exists>y ya yb. Q x y ya yb \<Longrightarrow> \<exists>f fa fb. \<forall>x. Q x (f x) (fa x) (fb x)"
blanchet@58481
    18
  "\<And>Q. \<forall>x. \<exists>y ya yb yc. Q x y ya yb yc \<Longrightarrow> \<exists>f fa fb fc. \<forall>x. Q x (f x) (fa x) (fb x) (fc x)"
blanchet@58598
    19
  "\<And>Q. \<forall>x. \<exists>y ya yb yc yd. Q x y ya yb yc yd \<Longrightarrow>
blanchet@58598
    20
     \<exists>f fa fb fc fd. \<forall>x. Q x (f x) (fa x) (fb x) (fc x) (fd x)"
blanchet@58598
    21
  "\<And>Q. \<forall>x. \<exists>y ya yb yc yd ye. Q x y ya yb yc yd ye \<Longrightarrow>
blanchet@58598
    22
     \<exists>f fa fb fc fd fe. \<forall>x. Q x (f x) (fa x) (fb x) (fc x) (fd x) (fe x)"
blanchet@58598
    23
  "\<And>Q. \<forall>x. \<exists>y ya yb yc yd ye yf. Q x y ya yb yc yd ye yf \<Longrightarrow>
blanchet@58598
    24
     \<exists>f fa fb fc fd fe ff. \<forall>x. Q x (f x) (fa x) (fb x) (fc x) (fd x) (fe x) (ff x)"
blanchet@58598
    25
  "\<And>Q. \<forall>x. \<exists>y ya yb yc yd ye yf yg. Q x y ya yb yc yd ye yf yg \<Longrightarrow>
blanchet@58598
    26
     \<exists>f fa fb fc fd fe ff fg. \<forall>x. Q x (f x) (fa x) (fb x) (fc x) (fd x) (fe x) (ff x) (fg x)"
blanchet@58481
    27
  by metis+
blanchet@58481
    28
blanchet@58481
    29
lemma bchoices:
blanchet@58481
    30
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya. Q x y ya \<Longrightarrow> \<exists>f fa. \<forall>x \<in> S. Q x (f x) (fa x)"
blanchet@58481
    31
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya yb. Q x y ya yb \<Longrightarrow> \<exists>f fa fb. \<forall>x \<in> S. Q x (f x) (fa x) (fb x)"
blanchet@58481
    32
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya yb yc. Q x y ya yb yc \<Longrightarrow> \<exists>f fa fb fc. \<forall>x \<in> S. Q x (f x) (fa x) (fb x) (fc x)"
blanchet@58598
    33
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya yb yc yd. Q x y ya yb yc yd \<Longrightarrow>
blanchet@58598
    34
    \<exists>f fa fb fc fd. \<forall>x \<in> S. Q x (f x) (fa x) (fb x) (fc x) (fd x)"
blanchet@58598
    35
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya yb yc yd ye. Q x y ya yb yc yd ye \<Longrightarrow>
blanchet@58598
    36
    \<exists>f fa fb fc fd fe. \<forall>x \<in> S. Q x (f x) (fa x) (fb x) (fc x) (fd x) (fe x)"
blanchet@58598
    37
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya yb yc yd ye yf. Q x y ya yb yc yd ye yf \<Longrightarrow>
blanchet@58598
    38
    \<exists>f fa fb fc fd fe ff. \<forall>x \<in> S. Q x (f x) (fa x) (fb x) (fc x) (fd x) (fe x) (ff x)"
blanchet@58598
    39
  "\<And>Q. \<forall>x \<in> S. \<exists>y ya yb yc yd ye yf yg. Q x y ya yb yc yd ye yf yg \<Longrightarrow>
blanchet@58598
    40
    \<exists>f fa fb fc fd fe ff fg. \<forall>x \<in> S. Q x (f x) (fa x) (fb x) (fc x) (fd x) (fe x) (ff x) (fg x)"
blanchet@58481
    41
  by metis+
blanchet@58481
    42
wenzelm@60758
    43
ML \<open>
blanchet@58481
    44
fun moura_tac ctxt =
blanchet@58481
    45
  Atomize_Elim.atomize_elim_tac ctxt THEN'
blanchet@58481
    46
  SELECT_GOAL (Clasimp.auto_tac (ctxt addSIs @{thms choice choices bchoice bchoices}) THEN
blanchet@58598
    47
    ALLGOALS (Metis_Tactic.metis_tac (take 1 ATP_Proof_Reconstruct.partial_type_encs)
blanchet@58598
    48
        ATP_Proof_Reconstruct.default_metis_lam_trans ctxt [] ORELSE'
blanchet@58598
    49
      blast_tac ctxt))
wenzelm@60758
    50
\<close>
blanchet@58481
    51
wenzelm@60758
    52
method_setup moura = \<open>
blanchet@60201
    53
  Scan.succeed (SIMPLE_METHOD' o moura_tac)
wenzelm@60758
    54
\<close> "solve skolemization goals, especially those arising from Z3 proofs"
blanchet@58481
    55
blanchet@58481
    56
hide_fact (open) choices bchoices
blanchet@58481
    57
blanchet@58481
    58
wenzelm@60758
    59
subsection \<open>Triggers for quantifier instantiation\<close>
blanchet@56078
    60
wenzelm@60758
    61
text \<open>
blanchet@56078
    62
Some SMT solvers support patterns as a quantifier instantiation
blanchet@57696
    63
heuristics. Patterns may either be positive terms (tagged by "pat")
blanchet@56078
    64
triggering quantifier instantiations -- when the solver finds a
blanchet@56078
    65
term matching a positive pattern, it instantiates the corresponding
blanchet@56078
    66
quantifier accordingly -- or negative terms (tagged by "nopat")
blanchet@57696
    67
inhibiting quantifier instantiations. A list of patterns
blanchet@56078
    68
of the same kind is called a multipattern, and all patterns in a
blanchet@56078
    69
multipattern are considered conjunctively for quantifier instantiation.
blanchet@56078
    70
A list of multipatterns is called a trigger, and their multipatterns
blanchet@57696
    71
act disjunctively during quantifier instantiation. Each multipattern
blanchet@56078
    72
should mention at least all quantified variables of the preceding
blanchet@56078
    73
quantifier block.
wenzelm@60758
    74
\<close>
blanchet@56078
    75
blanchet@57230
    76
typedecl 'a symb_list
blanchet@57230
    77
blanchet@57230
    78
consts
blanchet@57230
    79
  Symb_Nil :: "'a symb_list"
blanchet@57230
    80
  Symb_Cons :: "'a \<Rightarrow> 'a symb_list \<Rightarrow> 'a symb_list"
blanchet@57230
    81
blanchet@56078
    82
typedecl pattern
blanchet@56078
    83
blanchet@56078
    84
consts
blanchet@56078
    85
  pat :: "'a \<Rightarrow> pattern"
blanchet@56078
    86
  nopat :: "'a \<Rightarrow> pattern"
blanchet@56078
    87
blanchet@57230
    88
definition trigger :: "pattern symb_list symb_list \<Rightarrow> bool \<Rightarrow> bool" where
blanchet@57230
    89
  "trigger _ P = P"
blanchet@56078
    90
blanchet@56078
    91
wenzelm@60758
    92
subsection \<open>Higher-order encoding\<close>
blanchet@56078
    93
wenzelm@60758
    94
text \<open>
blanchet@56078
    95
Application is made explicit for constants occurring with varying
blanchet@57696
    96
numbers of arguments. This is achieved by the introduction of the
blanchet@56078
    97
following constant.
wenzelm@60758
    98
\<close>
blanchet@56078
    99
blanchet@56078
   100
definition fun_app :: "'a \<Rightarrow> 'a" where "fun_app f = f"
blanchet@56078
   101
wenzelm@60758
   102
text \<open>
blanchet@56078
   103
Some solvers support a theory of arrays which can be used to encode
blanchet@57696
   104
higher-order functions. The following set of lemmas specifies the
blanchet@56078
   105
properties of such (extensional) arrays.
wenzelm@60758
   106
\<close>
blanchet@56078
   107
blanchet@56078
   108
lemmas array_rules = ext fun_upd_apply fun_upd_same fun_upd_other  fun_upd_upd fun_app_def
blanchet@56078
   109
blanchet@56078
   110
wenzelm@60758
   111
subsection \<open>Normalization\<close>
blanchet@56103
   112
blanchet@56103
   113
lemma case_bool_if[abs_def]: "case_bool x y P = (if P then x else y)"
blanchet@56103
   114
  by simp
blanchet@56103
   115
blanchet@56103
   116
lemmas Ex1_def_raw = Ex1_def[abs_def]
blanchet@56103
   117
lemmas Ball_def_raw = Ball_def[abs_def]
blanchet@56103
   118
lemmas Bex_def_raw = Bex_def[abs_def]
blanchet@56103
   119
lemmas abs_if_raw = abs_if[abs_def]
blanchet@56103
   120
lemmas min_def_raw = min_def[abs_def]
blanchet@56103
   121
lemmas max_def_raw = max_def[abs_def]
blanchet@56103
   122
blanchet@66298
   123
lemma nat_int': "\<forall>n. nat (int n) = n" by simp
blanchet@66298
   124
lemma int_nat_nneg: "\<forall>i. i \<ge> 0 \<longrightarrow> int (nat i) = i" by simp
blanchet@66298
   125
lemma int_nat_neg: "\<forall>i. i < 0 \<longrightarrow> int (nat i) = 0" by simp
blanchet@66298
   126
blanchet@66298
   127
lemmas nat_zero_as_int = transfer_nat_int_numerals(1)
blanchet@66298
   128
lemmas nat_one_as_int = transfer_nat_int_numerals(2)
blanchet@66298
   129
lemma nat_numeral_as_int: "numeral = (\<lambda>i. nat (numeral i))" by simp
blanchet@66298
   130
lemma nat_less_as_int: "op < = (\<lambda>a b. int a < int b)" by simp
blanchet@66298
   131
lemma nat_leq_as_int: "op \<le> = (\<lambda>a b. int a \<le> int b)" by simp
blanchet@66298
   132
lemma Suc_as_int: "Suc = (\<lambda>a. nat (int a + 1))" by (rule ext) simp
blanchet@66298
   133
lemma nat_plus_as_int: "op + = (\<lambda>a b. nat (int a + int b))" by (rule ext)+ simp
blanchet@66298
   134
lemma nat_minus_as_int: "op - = (\<lambda>a b. nat (int a - int b))" by (rule ext)+ simp
blanchet@66298
   135
lemma nat_times_as_int: "op * = (\<lambda>a b. nat (int a * int b))" by (simp add: nat_mult_distrib)
blanchet@66298
   136
lemma nat_div_as_int: "op div = (\<lambda>a b. nat (int a div int b))" by (simp add: nat_div_distrib)
blanchet@66298
   137
lemma nat_mod_as_int: "op mod = (\<lambda>a b. nat (int a mod int b))" by (simp add: nat_mod_distrib)
blanchet@66298
   138
blanchet@66298
   139
lemma int_Suc: "int (Suc n) = int n + 1" by simp
blanchet@66298
   140
lemma int_plus: "int (n + m) = int n + int m" by (rule of_nat_add)
blanchet@66298
   141
lemma int_minus: "int (n - m) = int (nat (int n - int m))" by auto
blanchet@66298
   142
blanchet@56103
   143
wenzelm@60758
   144
subsection \<open>Integer division and modulo for Z3\<close>
blanchet@56078
   145
wenzelm@60758
   146
text \<open>
wenzelm@61799
   147
The following Z3-inspired definitions are overspecified for the case where \<open>l = 0\<close>. This
wenzelm@61799
   148
Schönheitsfehler is corrected in the \<open>div_as_z3div\<close> and \<open>mod_as_z3mod\<close> theorems.
wenzelm@60758
   149
\<close>
blanchet@56102
   150
blanchet@56078
   151
definition z3div :: "int \<Rightarrow> int \<Rightarrow> int" where
blanchet@56102
   152
  "z3div k l = (if l \<ge> 0 then k div l else - (k div - l))"
blanchet@56078
   153
blanchet@56078
   154
definition z3mod :: "int \<Rightarrow> int \<Rightarrow> int" where
blanchet@56102
   155
  "z3mod k l = k mod (if l \<ge> 0 then l else - l)"
blanchet@56078
   156
blanchet@56101
   157
lemma div_as_z3div:
blanchet@56102
   158
  "\<forall>k l. k div l = (if l = 0 then 0 else if l > 0 then z3div k l else z3div (- k) (- l))"
blanchet@56101
   159
  by (simp add: z3div_def)
blanchet@56101
   160
blanchet@56101
   161
lemma mod_as_z3mod:
blanchet@56102
   162
  "\<forall>k l. k mod l = (if l = 0 then k else if l > 0 then z3mod k l else - z3mod (- k) (- l))"
blanchet@56101
   163
  by (simp add: z3mod_def)
blanchet@56101
   164
blanchet@56078
   165
wenzelm@60758
   166
subsection \<open>Setup\<close>
blanchet@56078
   167
blanchet@58061
   168
ML_file "Tools/SMT/smt_util.ML"
blanchet@58061
   169
ML_file "Tools/SMT/smt_failure.ML"
blanchet@58061
   170
ML_file "Tools/SMT/smt_config.ML"
blanchet@58061
   171
ML_file "Tools/SMT/smt_builtin.ML"
blanchet@58061
   172
ML_file "Tools/SMT/smt_datatypes.ML"
blanchet@58061
   173
ML_file "Tools/SMT/smt_normalize.ML"
blanchet@58061
   174
ML_file "Tools/SMT/smt_translate.ML"
blanchet@58061
   175
ML_file "Tools/SMT/smtlib.ML"
blanchet@58061
   176
ML_file "Tools/SMT/smtlib_interface.ML"
blanchet@58061
   177
ML_file "Tools/SMT/smtlib_proof.ML"
blanchet@58061
   178
ML_file "Tools/SMT/smtlib_isar.ML"
blanchet@58061
   179
ML_file "Tools/SMT/z3_proof.ML"
blanchet@58061
   180
ML_file "Tools/SMT/z3_isar.ML"
blanchet@58061
   181
ML_file "Tools/SMT/smt_solver.ML"
blanchet@58360
   182
ML_file "Tools/SMT/cvc4_interface.ML"
blanchet@59015
   183
ML_file "Tools/SMT/cvc4_proof_parse.ML"
blanchet@58360
   184
ML_file "Tools/SMT/verit_proof.ML"
blanchet@58360
   185
ML_file "Tools/SMT/verit_isar.ML"
blanchet@58360
   186
ML_file "Tools/SMT/verit_proof_parse.ML"
boehmes@59381
   187
ML_file "Tools/SMT/conj_disj_perm.ML"
blanchet@58061
   188
ML_file "Tools/SMT/z3_interface.ML"
blanchet@58061
   189
ML_file "Tools/SMT/z3_replay_util.ML"
blanchet@58061
   190
ML_file "Tools/SMT/z3_replay_rules.ML"
blanchet@58061
   191
ML_file "Tools/SMT/z3_replay_methods.ML"
blanchet@58061
   192
ML_file "Tools/SMT/z3_replay.ML"
blanchet@58061
   193
ML_file "Tools/SMT/smt_systems.ML"
blanchet@56078
   194
wenzelm@60758
   195
method_setup smt = \<open>
blanchet@56078
   196
  Scan.optional Attrib.thms [] >>
blanchet@56078
   197
    (fn thms => fn ctxt =>
blanchet@58061
   198
      METHOD (fn facts => HEADGOAL (SMT_Solver.smt_tac ctxt (thms @ facts))))
wenzelm@60758
   199
\<close> "apply an SMT solver to the current goal"
blanchet@56078
   200
blanchet@56078
   201
wenzelm@60758
   202
subsection \<open>Configuration\<close>
blanchet@56078
   203
wenzelm@60758
   204
text \<open>
blanchet@56078
   205
The current configuration can be printed by the command
wenzelm@61799
   206
\<open>smt_status\<close>, which shows the values of most options.
wenzelm@60758
   207
\<close>
blanchet@56078
   208
blanchet@56078
   209
wenzelm@60758
   210
subsection \<open>General configuration options\<close>
blanchet@56078
   211
wenzelm@60758
   212
text \<open>
wenzelm@61799
   213
The option \<open>smt_solver\<close> can be used to change the target SMT
wenzelm@61799
   214
solver. The possible values can be obtained from the \<open>smt_status\<close>
blanchet@56078
   215
command.
wenzelm@60758
   216
\<close>
blanchet@56078
   217
blanchet@58061
   218
declare [[smt_solver = z3]]
blanchet@56078
   219
wenzelm@60758
   220
text \<open>
blanchet@57696
   221
Since SMT solvers are potentially nonterminating, there is a timeout
blanchet@57696
   222
(given in seconds) to restrict their runtime.
wenzelm@60758
   223
\<close>
blanchet@56078
   224
blanchet@58061
   225
declare [[smt_timeout = 20]]
blanchet@56078
   226
wenzelm@60758
   227
text \<open>
blanchet@57696
   228
SMT solvers apply randomized heuristics. In case a problem is not
blanchet@56078
   229
solvable by an SMT solver, changing the following option might help.
wenzelm@60758
   230
\<close>
blanchet@56078
   231
blanchet@58061
   232
declare [[smt_random_seed = 1]]
blanchet@56078
   233
wenzelm@60758
   234
text \<open>
blanchet@56078
   235
In general, the binding to SMT solvers runs as an oracle, i.e, the SMT
blanchet@57696
   236
solvers are fully trusted without additional checks. The following
blanchet@56078
   237
option can cause the SMT solver to run in proof-producing mode, giving
blanchet@57696
   238
a checkable certificate. This is currently only implemented for Z3.
wenzelm@60758
   239
\<close>
blanchet@56078
   240
blanchet@58061
   241
declare [[smt_oracle = false]]
blanchet@56078
   242
wenzelm@60758
   243
text \<open>
blanchet@56078
   244
Each SMT solver provides several commandline options to tweak its
blanchet@57696
   245
behaviour. They can be passed to the solver by setting the following
blanchet@56078
   246
options.
wenzelm@60758
   247
\<close>
blanchet@56078
   248
blanchet@58061
   249
declare [[cvc3_options = ""]]
blanchet@66323
   250
declare [[cvc4_options = "--full-saturate-quant --inst-when=full-last-call --inst-no-entail --term-db-mode=relevant --multi-trigger-linear"]]
blanchet@66559
   251
declare [[verit_options = "--index-sorts --index-fresh-sorts"]]
blanchet@58061
   252
declare [[z3_options = ""]]
blanchet@56078
   253
wenzelm@60758
   254
text \<open>
blanchet@56078
   255
The SMT method provides an inference mechanism to detect simple triggers
blanchet@56078
   256
in quantified formulas, which might increase the number of problems
blanchet@56078
   257
solvable by SMT solvers (note: triggers guide quantifier instantiations
blanchet@57696
   258
in the SMT solver). To turn it on, set the following option.
wenzelm@60758
   259
\<close>
blanchet@56078
   260
blanchet@58061
   261
declare [[smt_infer_triggers = false]]
blanchet@56078
   262
wenzelm@60758
   263
text \<open>
blanchet@58360
   264
Enable the following option to use built-in support for datatypes,
blanchet@58360
   265
codatatypes, and records in CVC4. Currently, this is implemented only
blanchet@58360
   266
in oracle mode.
wenzelm@60758
   267
\<close>
blanchet@58360
   268
blanchet@58360
   269
declare [[cvc4_extensions = false]]
blanchet@58360
   270
wenzelm@60758
   271
text \<open>
blanchet@56078
   272
Enable the following option to use built-in support for div/mod, datatypes,
blanchet@57696
   273
and records in Z3. Currently, this is implemented only in oracle mode.
wenzelm@60758
   274
\<close>
blanchet@56078
   275
blanchet@58061
   276
declare [[z3_extensions = false]]
blanchet@56078
   277
blanchet@56078
   278
wenzelm@60758
   279
subsection \<open>Certificates\<close>
blanchet@56078
   280
wenzelm@60758
   281
text \<open>
wenzelm@61799
   282
By setting the option \<open>smt_certificates\<close> to the name of a file,
blanchet@56078
   283
all following applications of an SMT solver a cached in that file.
blanchet@56078
   284
Any further application of the same SMT solver (using the very same
blanchet@56078
   285
configuration) re-uses the cached certificate instead of invoking the
blanchet@57696
   286
solver. An empty string disables caching certificates.
blanchet@56078
   287
blanchet@57696
   288
The filename should be given as an explicit path. It is good
blanchet@56078
   289
practice to use the name of the current theory (with ending
wenzelm@61799
   290
\<open>.certs\<close> instead of \<open>.thy\<close>) as the certificates file.
blanchet@56078
   291
Certificate files should be used at most once in a certain theory context,
blanchet@56078
   292
to avoid race conditions with other concurrent accesses.
wenzelm@60758
   293
\<close>
blanchet@56078
   294
blanchet@58061
   295
declare [[smt_certificates = ""]]
blanchet@56078
   296
wenzelm@60758
   297
text \<open>
wenzelm@61799
   298
The option \<open>smt_read_only_certificates\<close> controls whether only
blanchet@56078
   299
stored certificates are should be used or invocation of an SMT solver
wenzelm@61799
   300
is allowed. When set to \<open>true\<close>, no SMT solver will ever be
blanchet@56078
   301
invoked and only the existing certificates found in the configured
wenzelm@61799
   302
cache are used;  when set to \<open>false\<close> and there is no cached
blanchet@56078
   303
certificate for some proposition, then the configured SMT solver is
blanchet@56078
   304
invoked.
wenzelm@60758
   305
\<close>
blanchet@56078
   306
blanchet@58061
   307
declare [[smt_read_only_certificates = false]]
blanchet@56078
   308
blanchet@56078
   309
wenzelm@60758
   310
subsection \<open>Tracing\<close>
blanchet@56078
   311
wenzelm@60758
   312
text \<open>
blanchet@57696
   313
The SMT method, when applied, traces important information. To
wenzelm@61799
   314
make it entirely silent, set the following option to \<open>false\<close>.
wenzelm@60758
   315
\<close>
blanchet@56078
   316
blanchet@58061
   317
declare [[smt_verbose = true]]
blanchet@56078
   318
wenzelm@60758
   319
text \<open>
blanchet@56078
   320
For tracing the generated problem file given to the SMT solver as
blanchet@56078
   321
well as the returned result of the solver, the option
wenzelm@61799
   322
\<open>smt_trace\<close> should be set to \<open>true\<close>.
wenzelm@60758
   323
\<close>
blanchet@56078
   324
blanchet@58061
   325
declare [[smt_trace = false]]
blanchet@56078
   326
blanchet@56078
   327
wenzelm@60758
   328
subsection \<open>Schematic rules for Z3 proof reconstruction\<close>
blanchet@56078
   329
wenzelm@60758
   330
text \<open>
blanchet@57696
   331
Several prof rules of Z3 are not very well documented. There are two
blanchet@56078
   332
lemma groups which can turn failing Z3 proof reconstruction attempts
wenzelm@61799
   333
into succeeding ones: the facts in \<open>z3_rule\<close> are tried prior to
blanchet@56078
   334
any implemented reconstruction procedure for all uncertain Z3 proof
wenzelm@61799
   335
rules;  the facts in \<open>z3_simp\<close> are only fed to invocations of
blanchet@56078
   336
the simplifier when reconstructing theory-specific proof steps.
wenzelm@60758
   337
\<close>
blanchet@56078
   338
blanchet@58061
   339
lemmas [z3_rule] =
blanchet@56078
   340
  refl eq_commute conj_commute disj_commute simp_thms nnf_simps
blanchet@56078
   341
  ring_distribs field_simps times_divide_eq_right times_divide_eq_left
blanchet@56078
   342
  if_True if_False not_not
hoelzl@58776
   343
  NO_MATCH_def
blanchet@56078
   344
blanchet@58061
   345
lemma [z3_rule]:
blanchet@57169
   346
  "(P \<and> Q) = (\<not> (\<not> P \<or> \<not> Q))"
blanchet@57169
   347
  "(P \<and> Q) = (\<not> (\<not> Q \<or> \<not> P))"
blanchet@57169
   348
  "(\<not> P \<and> Q) = (\<not> (P \<or> \<not> Q))"
blanchet@57169
   349
  "(\<not> P \<and> Q) = (\<not> (\<not> Q \<or> P))"
blanchet@57169
   350
  "(P \<and> \<not> Q) = (\<not> (\<not> P \<or> Q))"
blanchet@57169
   351
  "(P \<and> \<not> Q) = (\<not> (Q \<or> \<not> P))"
blanchet@57169
   352
  "(\<not> P \<and> \<not> Q) = (\<not> (P \<or> Q))"
blanchet@57169
   353
  "(\<not> P \<and> \<not> Q) = (\<not> (Q \<or> P))"
blanchet@56078
   354
  by auto
blanchet@56078
   355
blanchet@58061
   356
lemma [z3_rule]:
blanchet@57169
   357
  "(P \<longrightarrow> Q) = (Q \<or> \<not> P)"
blanchet@57169
   358
  "(\<not> P \<longrightarrow> Q) = (P \<or> Q)"
blanchet@57169
   359
  "(\<not> P \<longrightarrow> Q) = (Q \<or> P)"
blanchet@56078
   360
  "(True \<longrightarrow> P) = P"
blanchet@56078
   361
  "(P \<longrightarrow> True) = True"
blanchet@56078
   362
  "(False \<longrightarrow> P) = True"
blanchet@56078
   363
  "(P \<longrightarrow> P) = True"
blanchet@59037
   364
  "(\<not> (A \<longleftrightarrow> \<not> B)) \<longleftrightarrow> (A \<longleftrightarrow> B)"
blanchet@56078
   365
  by auto
blanchet@56078
   366
blanchet@58061
   367
lemma [z3_rule]:
blanchet@57169
   368
  "((P = Q) \<longrightarrow> R) = (R | (Q = (\<not> P)))"
blanchet@56078
   369
  by auto
blanchet@56078
   370
blanchet@58061
   371
lemma [z3_rule]:
blanchet@57169
   372
  "(\<not> True) = False"
blanchet@57169
   373
  "(\<not> False) = True"
blanchet@56078
   374
  "(x = x) = True"
blanchet@56078
   375
  "(P = True) = P"
blanchet@56078
   376
  "(True = P) = P"
blanchet@57169
   377
  "(P = False) = (\<not> P)"
blanchet@57169
   378
  "(False = P) = (\<not> P)"
blanchet@57169
   379
  "((\<not> P) = P) = False"
blanchet@57169
   380
  "(P = (\<not> P)) = False"
blanchet@57169
   381
  "((\<not> P) = (\<not> Q)) = (P = Q)"
blanchet@57169
   382
  "\<not> (P = (\<not> Q)) = (P = Q)"
blanchet@57169
   383
  "\<not> ((\<not> P) = Q) = (P = Q)"
blanchet@57169
   384
  "(P \<noteq> Q) = (Q = (\<not> P))"
blanchet@57169
   385
  "(P = Q) = ((\<not> P \<or> Q) \<and> (P \<or> \<not> Q))"
blanchet@57169
   386
  "(P \<noteq> Q) = ((\<not> P \<or> \<not> Q) \<and> (P \<or> Q))"
blanchet@56078
   387
  by auto
blanchet@56078
   388
blanchet@58061
   389
lemma [z3_rule]:
blanchet@57169
   390
  "(if P then P else \<not> P) = True"
blanchet@57169
   391
  "(if \<not> P then \<not> P else P) = True"
blanchet@56078
   392
  "(if P then True else False) = P"
blanchet@57169
   393
  "(if P then False else True) = (\<not> P)"
blanchet@57169
   394
  "(if P then Q else True) = ((\<not> P) \<or> Q)"
blanchet@57169
   395
  "(if P then Q else True) = (Q \<or> (\<not> P))"
blanchet@57169
   396
  "(if P then Q else \<not> Q) = (P = Q)"
blanchet@57169
   397
  "(if P then Q else \<not> Q) = (Q = P)"
blanchet@57169
   398
  "(if P then \<not> Q else Q) = (P = (\<not> Q))"
blanchet@57169
   399
  "(if P then \<not> Q else Q) = ((\<not> Q) = P)"
blanchet@57169
   400
  "(if \<not> P then x else y) = (if P then y else x)"
blanchet@57169
   401
  "(if P then (if Q then x else y) else x) = (if P \<and> (\<not> Q) then y else x)"
blanchet@57169
   402
  "(if P then (if Q then x else y) else x) = (if (\<not> Q) \<and> P then y else x)"
blanchet@56078
   403
  "(if P then (if Q then x else y) else y) = (if P \<and> Q then x else y)"
blanchet@56078
   404
  "(if P then (if Q then x else y) else y) = (if Q \<and> P then x else y)"
blanchet@56078
   405
  "(if P then x else if P then y else z) = (if P then x else z)"
blanchet@56078
   406
  "(if P then x else if Q then x else y) = (if P \<or> Q then x else y)"
blanchet@56078
   407
  "(if P then x else if Q then x else y) = (if Q \<or> P then x else y)"
blanchet@56078
   408
  "(if P then x = y else x = z) = (x = (if P then y else z))"
blanchet@56078
   409
  "(if P then x = y else y = z) = (y = (if P then x else z))"
blanchet@56078
   410
  "(if P then x = y else z = y) = (y = (if P then x else z))"
blanchet@56078
   411
  by auto
blanchet@56078
   412
blanchet@58061
   413
lemma [z3_rule]:
blanchet@56078
   414
  "0 + (x::int) = x"
blanchet@56078
   415
  "x + 0 = x"
blanchet@56078
   416
  "x + x = 2 * x"
blanchet@56078
   417
  "0 * x = 0"
blanchet@56078
   418
  "1 * x = x"
blanchet@56078
   419
  "x + y = y + x"
blanchet@57230
   420
  by (auto simp add: mult_2)
blanchet@56078
   421
blanchet@58061
   422
lemma [z3_rule]:  (* for def-axiom *)
blanchet@56078
   423
  "P = Q \<or> P \<or> Q"
blanchet@57169
   424
  "P = Q \<or> \<not> P \<or> \<not> Q"
blanchet@57169
   425
  "(\<not> P) = Q \<or> \<not> P \<or> Q"
blanchet@57169
   426
  "(\<not> P) = Q \<or> P \<or> \<not> Q"
blanchet@57169
   427
  "P = (\<not> Q) \<or> \<not> P \<or> Q"
blanchet@57169
   428
  "P = (\<not> Q) \<or> P \<or> \<not> Q"
blanchet@57169
   429
  "P \<noteq> Q \<or> P \<or> \<not> Q"
blanchet@57169
   430
  "P \<noteq> Q \<or> \<not> P \<or> Q"
blanchet@57169
   431
  "P \<noteq> (\<not> Q) \<or> P \<or> Q"
blanchet@57169
   432
  "(\<not> P) \<noteq> Q \<or> P \<or> Q"
blanchet@57169
   433
  "P \<or> Q \<or> P \<noteq> (\<not> Q)"
blanchet@57169
   434
  "P \<or> Q \<or> (\<not> P) \<noteq> Q"
blanchet@57169
   435
  "P \<or> \<not> Q \<or> P \<noteq> Q"
blanchet@57169
   436
  "\<not> P \<or> Q \<or> P \<noteq> Q"
blanchet@56078
   437
  "P \<or> y = (if P then x else y)"
blanchet@56078
   438
  "P \<or> (if P then x else y) = y"
blanchet@57169
   439
  "\<not> P \<or> x = (if P then x else y)"
blanchet@57169
   440
  "\<not> P \<or> (if P then x else y) = x"
blanchet@57169
   441
  "P \<or> R \<or> \<not> (if P then Q else R)"
blanchet@57169
   442
  "\<not> P \<or> Q \<or> \<not> (if P then Q else R)"
blanchet@57169
   443
  "\<not> (if P then Q else R) \<or> \<not> P \<or> Q"
blanchet@57169
   444
  "\<not> (if P then Q else R) \<or> P \<or> R"
blanchet@57169
   445
  "(if P then Q else R) \<or> \<not> P \<or> \<not> Q"
blanchet@57169
   446
  "(if P then Q else R) \<or> P \<or> \<not> R"
blanchet@57169
   447
  "(if P then \<not> Q else R) \<or> \<not> P \<or> Q"
blanchet@57169
   448
  "(if P then Q else \<not> R) \<or> P \<or> R"
blanchet@56078
   449
  by auto
blanchet@56078
   450
blanchet@57230
   451
hide_type (open) symb_list pattern
blanchet@57230
   452
hide_const (open) Symb_Nil Symb_Cons trigger pat nopat fun_app z3div z3mod
blanchet@56078
   453
blanchet@56078
   454
end