src/HOL/SMT.thy
author haftmann
Sun Oct 08 22:28:22 2017 +0200 (19 months ago)
changeset 66817 0b12755ccbb2
parent 66559 beb48215cda7
child 67091 1393c2340eec
permissions -rw-r--r--
euclidean rings need no normalization
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
haftmann@66817
   127
lemma nat_zero_as_int:
haftmann@66817
   128
  "0 = nat 0"
haftmann@66817
   129
  by simp
haftmann@66817
   130
haftmann@66817
   131
lemma nat_one_as_int:
haftmann@66817
   132
  "1 = nat 1"
haftmann@66817
   133
  by simp
haftmann@66817
   134
blanchet@66298
   135
lemma nat_numeral_as_int: "numeral = (\<lambda>i. nat (numeral i))" by simp
blanchet@66298
   136
lemma nat_less_as_int: "op < = (\<lambda>a b. int a < int b)" by simp
blanchet@66298
   137
lemma nat_leq_as_int: "op \<le> = (\<lambda>a b. int a \<le> int b)" by simp
blanchet@66298
   138
lemma Suc_as_int: "Suc = (\<lambda>a. nat (int a + 1))" by (rule ext) simp
blanchet@66298
   139
lemma nat_plus_as_int: "op + = (\<lambda>a b. nat (int a + int b))" by (rule ext)+ simp
blanchet@66298
   140
lemma nat_minus_as_int: "op - = (\<lambda>a b. nat (int a - int b))" by (rule ext)+ simp
blanchet@66298
   141
lemma nat_times_as_int: "op * = (\<lambda>a b. nat (int a * int b))" by (simp add: nat_mult_distrib)
blanchet@66298
   142
lemma nat_div_as_int: "op div = (\<lambda>a b. nat (int a div int b))" by (simp add: nat_div_distrib)
blanchet@66298
   143
lemma nat_mod_as_int: "op mod = (\<lambda>a b. nat (int a mod int b))" by (simp add: nat_mod_distrib)
blanchet@66298
   144
blanchet@66298
   145
lemma int_Suc: "int (Suc n) = int n + 1" by simp
blanchet@66298
   146
lemma int_plus: "int (n + m) = int n + int m" by (rule of_nat_add)
blanchet@66298
   147
lemma int_minus: "int (n - m) = int (nat (int n - int m))" by auto
blanchet@66298
   148
blanchet@56103
   149
wenzelm@60758
   150
subsection \<open>Integer division and modulo for Z3\<close>
blanchet@56078
   151
wenzelm@60758
   152
text \<open>
wenzelm@61799
   153
The following Z3-inspired definitions are overspecified for the case where \<open>l = 0\<close>. This
wenzelm@61799
   154
Schönheitsfehler is corrected in the \<open>div_as_z3div\<close> and \<open>mod_as_z3mod\<close> theorems.
wenzelm@60758
   155
\<close>
blanchet@56102
   156
blanchet@56078
   157
definition z3div :: "int \<Rightarrow> int \<Rightarrow> int" where
blanchet@56102
   158
  "z3div k l = (if l \<ge> 0 then k div l else - (k div - l))"
blanchet@56078
   159
blanchet@56078
   160
definition z3mod :: "int \<Rightarrow> int \<Rightarrow> int" where
blanchet@56102
   161
  "z3mod k l = k mod (if l \<ge> 0 then l else - l)"
blanchet@56078
   162
blanchet@56101
   163
lemma div_as_z3div:
blanchet@56102
   164
  "\<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
   165
  by (simp add: z3div_def)
blanchet@56101
   166
blanchet@56101
   167
lemma mod_as_z3mod:
blanchet@56102
   168
  "\<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
   169
  by (simp add: z3mod_def)
blanchet@56101
   170
blanchet@56078
   171
wenzelm@60758
   172
subsection \<open>Setup\<close>
blanchet@56078
   173
blanchet@58061
   174
ML_file "Tools/SMT/smt_util.ML"
blanchet@58061
   175
ML_file "Tools/SMT/smt_failure.ML"
blanchet@58061
   176
ML_file "Tools/SMT/smt_config.ML"
blanchet@58061
   177
ML_file "Tools/SMT/smt_builtin.ML"
blanchet@58061
   178
ML_file "Tools/SMT/smt_datatypes.ML"
blanchet@58061
   179
ML_file "Tools/SMT/smt_normalize.ML"
blanchet@58061
   180
ML_file "Tools/SMT/smt_translate.ML"
blanchet@58061
   181
ML_file "Tools/SMT/smtlib.ML"
blanchet@58061
   182
ML_file "Tools/SMT/smtlib_interface.ML"
blanchet@58061
   183
ML_file "Tools/SMT/smtlib_proof.ML"
blanchet@58061
   184
ML_file "Tools/SMT/smtlib_isar.ML"
blanchet@58061
   185
ML_file "Tools/SMT/z3_proof.ML"
blanchet@58061
   186
ML_file "Tools/SMT/z3_isar.ML"
blanchet@58061
   187
ML_file "Tools/SMT/smt_solver.ML"
blanchet@58360
   188
ML_file "Tools/SMT/cvc4_interface.ML"
blanchet@59015
   189
ML_file "Tools/SMT/cvc4_proof_parse.ML"
blanchet@58360
   190
ML_file "Tools/SMT/verit_proof.ML"
blanchet@58360
   191
ML_file "Tools/SMT/verit_isar.ML"
blanchet@58360
   192
ML_file "Tools/SMT/verit_proof_parse.ML"
boehmes@59381
   193
ML_file "Tools/SMT/conj_disj_perm.ML"
blanchet@58061
   194
ML_file "Tools/SMT/z3_interface.ML"
blanchet@58061
   195
ML_file "Tools/SMT/z3_replay_util.ML"
blanchet@58061
   196
ML_file "Tools/SMT/z3_replay_rules.ML"
blanchet@58061
   197
ML_file "Tools/SMT/z3_replay_methods.ML"
blanchet@58061
   198
ML_file "Tools/SMT/z3_replay.ML"
blanchet@58061
   199
ML_file "Tools/SMT/smt_systems.ML"
blanchet@56078
   200
wenzelm@60758
   201
method_setup smt = \<open>
blanchet@56078
   202
  Scan.optional Attrib.thms [] >>
blanchet@56078
   203
    (fn thms => fn ctxt =>
blanchet@58061
   204
      METHOD (fn facts => HEADGOAL (SMT_Solver.smt_tac ctxt (thms @ facts))))
wenzelm@60758
   205
\<close> "apply an SMT solver to the current goal"
blanchet@56078
   206
blanchet@56078
   207
wenzelm@60758
   208
subsection \<open>Configuration\<close>
blanchet@56078
   209
wenzelm@60758
   210
text \<open>
blanchet@56078
   211
The current configuration can be printed by the command
wenzelm@61799
   212
\<open>smt_status\<close>, which shows the values of most options.
wenzelm@60758
   213
\<close>
blanchet@56078
   214
blanchet@56078
   215
wenzelm@60758
   216
subsection \<open>General configuration options\<close>
blanchet@56078
   217
wenzelm@60758
   218
text \<open>
wenzelm@61799
   219
The option \<open>smt_solver\<close> can be used to change the target SMT
wenzelm@61799
   220
solver. The possible values can be obtained from the \<open>smt_status\<close>
blanchet@56078
   221
command.
wenzelm@60758
   222
\<close>
blanchet@56078
   223
blanchet@58061
   224
declare [[smt_solver = z3]]
blanchet@56078
   225
wenzelm@60758
   226
text \<open>
blanchet@57696
   227
Since SMT solvers are potentially nonterminating, there is a timeout
blanchet@57696
   228
(given in seconds) to restrict their runtime.
wenzelm@60758
   229
\<close>
blanchet@56078
   230
blanchet@58061
   231
declare [[smt_timeout = 20]]
blanchet@56078
   232
wenzelm@60758
   233
text \<open>
blanchet@57696
   234
SMT solvers apply randomized heuristics. In case a problem is not
blanchet@56078
   235
solvable by an SMT solver, changing the following option might help.
wenzelm@60758
   236
\<close>
blanchet@56078
   237
blanchet@58061
   238
declare [[smt_random_seed = 1]]
blanchet@56078
   239
wenzelm@60758
   240
text \<open>
blanchet@56078
   241
In general, the binding to SMT solvers runs as an oracle, i.e, the SMT
blanchet@57696
   242
solvers are fully trusted without additional checks. The following
blanchet@56078
   243
option can cause the SMT solver to run in proof-producing mode, giving
blanchet@57696
   244
a checkable certificate. This is currently only implemented for Z3.
wenzelm@60758
   245
\<close>
blanchet@56078
   246
blanchet@58061
   247
declare [[smt_oracle = false]]
blanchet@56078
   248
wenzelm@60758
   249
text \<open>
blanchet@56078
   250
Each SMT solver provides several commandline options to tweak its
blanchet@57696
   251
behaviour. They can be passed to the solver by setting the following
blanchet@56078
   252
options.
wenzelm@60758
   253
\<close>
blanchet@56078
   254
blanchet@58061
   255
declare [[cvc3_options = ""]]
blanchet@66323
   256
declare [[cvc4_options = "--full-saturate-quant --inst-when=full-last-call --inst-no-entail --term-db-mode=relevant --multi-trigger-linear"]]
blanchet@66559
   257
declare [[verit_options = "--index-sorts --index-fresh-sorts"]]
blanchet@58061
   258
declare [[z3_options = ""]]
blanchet@56078
   259
wenzelm@60758
   260
text \<open>
blanchet@56078
   261
The SMT method provides an inference mechanism to detect simple triggers
blanchet@56078
   262
in quantified formulas, which might increase the number of problems
blanchet@56078
   263
solvable by SMT solvers (note: triggers guide quantifier instantiations
blanchet@57696
   264
in the SMT solver). To turn it on, set the following option.
wenzelm@60758
   265
\<close>
blanchet@56078
   266
blanchet@58061
   267
declare [[smt_infer_triggers = false]]
blanchet@56078
   268
wenzelm@60758
   269
text \<open>
blanchet@58360
   270
Enable the following option to use built-in support for datatypes,
blanchet@58360
   271
codatatypes, and records in CVC4. Currently, this is implemented only
blanchet@58360
   272
in oracle mode.
wenzelm@60758
   273
\<close>
blanchet@58360
   274
blanchet@58360
   275
declare [[cvc4_extensions = false]]
blanchet@58360
   276
wenzelm@60758
   277
text \<open>
blanchet@56078
   278
Enable the following option to use built-in support for div/mod, datatypes,
blanchet@57696
   279
and records in Z3. Currently, this is implemented only in oracle mode.
wenzelm@60758
   280
\<close>
blanchet@56078
   281
blanchet@58061
   282
declare [[z3_extensions = false]]
blanchet@56078
   283
blanchet@56078
   284
wenzelm@60758
   285
subsection \<open>Certificates\<close>
blanchet@56078
   286
wenzelm@60758
   287
text \<open>
wenzelm@61799
   288
By setting the option \<open>smt_certificates\<close> to the name of a file,
blanchet@56078
   289
all following applications of an SMT solver a cached in that file.
blanchet@56078
   290
Any further application of the same SMT solver (using the very same
blanchet@56078
   291
configuration) re-uses the cached certificate instead of invoking the
blanchet@57696
   292
solver. An empty string disables caching certificates.
blanchet@56078
   293
blanchet@57696
   294
The filename should be given as an explicit path. It is good
blanchet@56078
   295
practice to use the name of the current theory (with ending
wenzelm@61799
   296
\<open>.certs\<close> instead of \<open>.thy\<close>) as the certificates file.
blanchet@56078
   297
Certificate files should be used at most once in a certain theory context,
blanchet@56078
   298
to avoid race conditions with other concurrent accesses.
wenzelm@60758
   299
\<close>
blanchet@56078
   300
blanchet@58061
   301
declare [[smt_certificates = ""]]
blanchet@56078
   302
wenzelm@60758
   303
text \<open>
wenzelm@61799
   304
The option \<open>smt_read_only_certificates\<close> controls whether only
blanchet@56078
   305
stored certificates are should be used or invocation of an SMT solver
wenzelm@61799
   306
is allowed. When set to \<open>true\<close>, no SMT solver will ever be
blanchet@56078
   307
invoked and only the existing certificates found in the configured
wenzelm@61799
   308
cache are used;  when set to \<open>false\<close> and there is no cached
blanchet@56078
   309
certificate for some proposition, then the configured SMT solver is
blanchet@56078
   310
invoked.
wenzelm@60758
   311
\<close>
blanchet@56078
   312
blanchet@58061
   313
declare [[smt_read_only_certificates = false]]
blanchet@56078
   314
blanchet@56078
   315
wenzelm@60758
   316
subsection \<open>Tracing\<close>
blanchet@56078
   317
wenzelm@60758
   318
text \<open>
blanchet@57696
   319
The SMT method, when applied, traces important information. To
wenzelm@61799
   320
make it entirely silent, set the following option to \<open>false\<close>.
wenzelm@60758
   321
\<close>
blanchet@56078
   322
blanchet@58061
   323
declare [[smt_verbose = true]]
blanchet@56078
   324
wenzelm@60758
   325
text \<open>
blanchet@56078
   326
For tracing the generated problem file given to the SMT solver as
blanchet@56078
   327
well as the returned result of the solver, the option
wenzelm@61799
   328
\<open>smt_trace\<close> should be set to \<open>true\<close>.
wenzelm@60758
   329
\<close>
blanchet@56078
   330
blanchet@58061
   331
declare [[smt_trace = false]]
blanchet@56078
   332
blanchet@56078
   333
wenzelm@60758
   334
subsection \<open>Schematic rules for Z3 proof reconstruction\<close>
blanchet@56078
   335
wenzelm@60758
   336
text \<open>
blanchet@57696
   337
Several prof rules of Z3 are not very well documented. There are two
blanchet@56078
   338
lemma groups which can turn failing Z3 proof reconstruction attempts
wenzelm@61799
   339
into succeeding ones: the facts in \<open>z3_rule\<close> are tried prior to
blanchet@56078
   340
any implemented reconstruction procedure for all uncertain Z3 proof
wenzelm@61799
   341
rules;  the facts in \<open>z3_simp\<close> are only fed to invocations of
blanchet@56078
   342
the simplifier when reconstructing theory-specific proof steps.
wenzelm@60758
   343
\<close>
blanchet@56078
   344
blanchet@58061
   345
lemmas [z3_rule] =
blanchet@56078
   346
  refl eq_commute conj_commute disj_commute simp_thms nnf_simps
blanchet@56078
   347
  ring_distribs field_simps times_divide_eq_right times_divide_eq_left
blanchet@56078
   348
  if_True if_False not_not
hoelzl@58776
   349
  NO_MATCH_def
blanchet@56078
   350
blanchet@58061
   351
lemma [z3_rule]:
blanchet@57169
   352
  "(P \<and> Q) = (\<not> (\<not> P \<or> \<not> Q))"
blanchet@57169
   353
  "(P \<and> Q) = (\<not> (\<not> Q \<or> \<not> P))"
blanchet@57169
   354
  "(\<not> P \<and> Q) = (\<not> (P \<or> \<not> Q))"
blanchet@57169
   355
  "(\<not> P \<and> Q) = (\<not> (\<not> Q \<or> P))"
blanchet@57169
   356
  "(P \<and> \<not> Q) = (\<not> (\<not> P \<or> Q))"
blanchet@57169
   357
  "(P \<and> \<not> Q) = (\<not> (Q \<or> \<not> P))"
blanchet@57169
   358
  "(\<not> P \<and> \<not> Q) = (\<not> (P \<or> Q))"
blanchet@57169
   359
  "(\<not> P \<and> \<not> Q) = (\<not> (Q \<or> P))"
blanchet@56078
   360
  by auto
blanchet@56078
   361
blanchet@58061
   362
lemma [z3_rule]:
blanchet@57169
   363
  "(P \<longrightarrow> Q) = (Q \<or> \<not> P)"
blanchet@57169
   364
  "(\<not> P \<longrightarrow> Q) = (P \<or> Q)"
blanchet@57169
   365
  "(\<not> P \<longrightarrow> Q) = (Q \<or> P)"
blanchet@56078
   366
  "(True \<longrightarrow> P) = P"
blanchet@56078
   367
  "(P \<longrightarrow> True) = True"
blanchet@56078
   368
  "(False \<longrightarrow> P) = True"
blanchet@56078
   369
  "(P \<longrightarrow> P) = True"
blanchet@59037
   370
  "(\<not> (A \<longleftrightarrow> \<not> B)) \<longleftrightarrow> (A \<longleftrightarrow> B)"
blanchet@56078
   371
  by auto
blanchet@56078
   372
blanchet@58061
   373
lemma [z3_rule]:
blanchet@57169
   374
  "((P = Q) \<longrightarrow> R) = (R | (Q = (\<not> P)))"
blanchet@56078
   375
  by auto
blanchet@56078
   376
blanchet@58061
   377
lemma [z3_rule]:
blanchet@57169
   378
  "(\<not> True) = False"
blanchet@57169
   379
  "(\<not> False) = True"
blanchet@56078
   380
  "(x = x) = True"
blanchet@56078
   381
  "(P = True) = P"
blanchet@56078
   382
  "(True = P) = P"
blanchet@57169
   383
  "(P = False) = (\<not> P)"
blanchet@57169
   384
  "(False = P) = (\<not> P)"
blanchet@57169
   385
  "((\<not> P) = P) = False"
blanchet@57169
   386
  "(P = (\<not> P)) = False"
blanchet@57169
   387
  "((\<not> P) = (\<not> Q)) = (P = Q)"
blanchet@57169
   388
  "\<not> (P = (\<not> Q)) = (P = Q)"
blanchet@57169
   389
  "\<not> ((\<not> P) = Q) = (P = Q)"
blanchet@57169
   390
  "(P \<noteq> Q) = (Q = (\<not> P))"
blanchet@57169
   391
  "(P = Q) = ((\<not> P \<or> Q) \<and> (P \<or> \<not> Q))"
blanchet@57169
   392
  "(P \<noteq> Q) = ((\<not> P \<or> \<not> Q) \<and> (P \<or> Q))"
blanchet@56078
   393
  by auto
blanchet@56078
   394
blanchet@58061
   395
lemma [z3_rule]:
blanchet@57169
   396
  "(if P then P else \<not> P) = True"
blanchet@57169
   397
  "(if \<not> P then \<not> P else P) = True"
blanchet@56078
   398
  "(if P then True else False) = P"
blanchet@57169
   399
  "(if P then False else True) = (\<not> P)"
blanchet@57169
   400
  "(if P then Q else True) = ((\<not> P) \<or> Q)"
blanchet@57169
   401
  "(if P then Q else True) = (Q \<or> (\<not> P))"
blanchet@57169
   402
  "(if P then Q else \<not> Q) = (P = Q)"
blanchet@57169
   403
  "(if P then Q else \<not> Q) = (Q = P)"
blanchet@57169
   404
  "(if P then \<not> Q else Q) = (P = (\<not> Q))"
blanchet@57169
   405
  "(if P then \<not> Q else Q) = ((\<not> Q) = P)"
blanchet@57169
   406
  "(if \<not> P then x else y) = (if P then y else x)"
blanchet@57169
   407
  "(if P then (if Q then x else y) else x) = (if P \<and> (\<not> Q) then y else x)"
blanchet@57169
   408
  "(if P then (if Q then x else y) else x) = (if (\<not> Q) \<and> P then y else x)"
blanchet@56078
   409
  "(if P then (if Q then x else y) else y) = (if P \<and> Q then x else y)"
blanchet@56078
   410
  "(if P then (if Q then x else y) else y) = (if Q \<and> P then x else y)"
blanchet@56078
   411
  "(if P then x else if P then y else z) = (if P then x else z)"
blanchet@56078
   412
  "(if P then x else if Q then x else y) = (if P \<or> Q then x else y)"
blanchet@56078
   413
  "(if P then x else if Q then x else y) = (if Q \<or> P then x else y)"
blanchet@56078
   414
  "(if P then x = y else x = z) = (x = (if P then y else z))"
blanchet@56078
   415
  "(if P then x = y else y = z) = (y = (if P then x else z))"
blanchet@56078
   416
  "(if P then x = y else z = y) = (y = (if P then x else z))"
blanchet@56078
   417
  by auto
blanchet@56078
   418
blanchet@58061
   419
lemma [z3_rule]:
blanchet@56078
   420
  "0 + (x::int) = x"
blanchet@56078
   421
  "x + 0 = x"
blanchet@56078
   422
  "x + x = 2 * x"
blanchet@56078
   423
  "0 * x = 0"
blanchet@56078
   424
  "1 * x = x"
blanchet@56078
   425
  "x + y = y + x"
blanchet@57230
   426
  by (auto simp add: mult_2)
blanchet@56078
   427
blanchet@58061
   428
lemma [z3_rule]:  (* for def-axiom *)
blanchet@56078
   429
  "P = Q \<or> P \<or> Q"
blanchet@57169
   430
  "P = Q \<or> \<not> P \<or> \<not> Q"
blanchet@57169
   431
  "(\<not> P) = Q \<or> \<not> P \<or> Q"
blanchet@57169
   432
  "(\<not> P) = Q \<or> P \<or> \<not> Q"
blanchet@57169
   433
  "P = (\<not> Q) \<or> \<not> P \<or> Q"
blanchet@57169
   434
  "P = (\<not> Q) \<or> P \<or> \<not> Q"
blanchet@57169
   435
  "P \<noteq> Q \<or> P \<or> \<not> Q"
blanchet@57169
   436
  "P \<noteq> Q \<or> \<not> P \<or> Q"
blanchet@57169
   437
  "P \<noteq> (\<not> Q) \<or> P \<or> Q"
blanchet@57169
   438
  "(\<not> P) \<noteq> Q \<or> P \<or> Q"
blanchet@57169
   439
  "P \<or> Q \<or> P \<noteq> (\<not> Q)"
blanchet@57169
   440
  "P \<or> Q \<or> (\<not> P) \<noteq> Q"
blanchet@57169
   441
  "P \<or> \<not> Q \<or> P \<noteq> Q"
blanchet@57169
   442
  "\<not> P \<or> Q \<or> P \<noteq> Q"
blanchet@56078
   443
  "P \<or> y = (if P then x else y)"
blanchet@56078
   444
  "P \<or> (if P then x else y) = y"
blanchet@57169
   445
  "\<not> P \<or> x = (if P then x else y)"
blanchet@57169
   446
  "\<not> P \<or> (if P then x else y) = x"
blanchet@57169
   447
  "P \<or> R \<or> \<not> (if P then Q else R)"
blanchet@57169
   448
  "\<not> P \<or> Q \<or> \<not> (if P then Q else R)"
blanchet@57169
   449
  "\<not> (if P then Q else R) \<or> \<not> P \<or> Q"
blanchet@57169
   450
  "\<not> (if P then Q else R) \<or> P \<or> R"
blanchet@57169
   451
  "(if P then Q else R) \<or> \<not> P \<or> \<not> Q"
blanchet@57169
   452
  "(if P then Q else R) \<or> P \<or> \<not> R"
blanchet@57169
   453
  "(if P then \<not> Q else R) \<or> \<not> P \<or> Q"
blanchet@57169
   454
  "(if P then Q else \<not> R) \<or> P \<or> R"
blanchet@56078
   455
  by auto
blanchet@56078
   456
blanchet@57230
   457
hide_type (open) symb_list pattern
blanchet@57230
   458
hide_const (open) Symb_Nil Symb_Cons trigger pat nopat fun_app z3div z3mod
blanchet@56078
   459
blanchet@56078
   460
end