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