src/HOL/TPTP/TPTP_Proof_Reconstruction.thy
author wenzelm
Wed, 12 Mar 2025 11:39:00 +0100
changeset 82265 4b875a4c83b0
parent 80910 406a85a25189
permissions -rw-r--r--
update for release;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
     1
(*  Title:      HOL/TPTP/TPTP_Proof_Reconstruction.thy
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
     2
    Author:     Nik Sultana, Cambridge University Computer Laboratory
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
     3
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
     4
Proof reconstruction for Leo-II.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
     5
55597
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
     6
USAGE:
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
     7
* Simple call the "reconstruct_leo2" function.
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
     8
* For more advanced use, you could use the component functions used in
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
     9
  "reconstruct_leo2" -- see TPTP_Proof_Reconstruction_Test.thy for
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    10
  examples of this.
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    11
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    12
This file contains definitions describing how to interpret LEO-II's
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    13
calculus in Isabelle/HOL, as well as more general proof-handling
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    14
functions. The definitions in this file serve to build an intermediate
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    15
proof script which is then evaluated into a tactic -- both these steps
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    16
are independent of LEO-II, and are defined in the TPTP_Reconstruct SML
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    17
module.
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    18
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    19
CONFIG:
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    20
The following attributes are mainly useful for debugging:
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    21
  tptp_unexceptional_reconstruction |
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    22
  unexceptional_reconstruction      |-- when these are true, a low-level exception
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    23
                                        is allowed to float to the top (instead of
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    24
                                        triggering a higher-level exception, or
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    25
                                        simply indicating that the reconstruction failed).
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    26
  tptp_max_term_size                --- fail of a term exceeds this size. "0" is taken
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    27
                                        to mean infinity.
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    28
  tptp_informative_failure          |
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    29
  informative_failure               |-- produce more output during reconstruction.
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    30
  tptp_trace_reconstruction         |
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    31
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    32
There are also two attributes, independent of the code here, that
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    33
influence the success of reconstruction: blast_depth_limit and
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    34
unify_search_bound. These are documented in their respective modules,
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    35
but in summary, if unify_search_bound is increased then we can
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    36
handle larger terms (at the cost of performance), since the unification
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    37
engine takes longer to give up the search; blast_depth_limit is
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    38
a limit on proof search performed by Blast. Blast is used for
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    39
the limited proof search that needs to be done to interpret
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    40
instances of LEO-II's inference rules.
25d7b485df81 added a function that carries out all the reconstruction steps, for improved usability;
sultana
parents: 55596
diff changeset
    41
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    42
TODO:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    43
  use RemoveRedundantQuantifications instead of the ad hoc use of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    44
   remove_redundant_quantification_in_lit and remove_redundant_quantification
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    45
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    46
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    47
theory TPTP_Proof_Reconstruction
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    48
imports TPTP_Parser TPTP_Interpret
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    49
(* keywords "import_leo2_proof" :: thy_decl *) (*FIXME currently unused*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    50
begin
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    51
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    52
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    53
section "Setup"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    54
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
    55
ML \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
    56
  val tptp_unexceptional_reconstruction = Attrib.setup_config_bool \<^binding>\<open>tptp_unexceptional_reconstruction\<close> (K false)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    57
  fun unexceptional_reconstruction ctxt = Config.get ctxt tptp_unexceptional_reconstruction
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
    58
  val tptp_informative_failure = Attrib.setup_config_bool \<^binding>\<open>tptp_informative_failure\<close> (K false)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    59
  fun informative_failure ctxt = Config.get ctxt tptp_informative_failure
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
    60
  val tptp_trace_reconstruction = Attrib.setup_config_bool \<^binding>\<open>tptp_trace_reconstruction\<close> (K false)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
    61
  val tptp_max_term_size = Attrib.setup_config_int \<^binding>\<open>tptp_max_term_size\<close> (K 0) (*0=infinity*)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    62
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    63
  fun exceeds_tptp_max_term_size ctxt size =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    64
    let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    65
      val max = Config.get ctxt tptp_max_term_size
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    66
    in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    67
      if max = 0 then false
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    68
      else size > max
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    69
    end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
    70
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    71
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    72
(*FIXME move to TPTP_Proof_Reconstruction_Test_Units*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    73
declare [[
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    74
  tptp_unexceptional_reconstruction = false, (*NOTE should be "false" while testing*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    75
  tptp_informative_failure = true
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    76
]]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    77
78727
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
    78
ML \<open>
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
    79
exception UNSUPPORTED_ROLE
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
    80
exception INTERPRET_INFERENCE
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
    81
\<close>
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
    82
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69597
diff changeset
    83
ML_file \<open>TPTP_Parser/tptp_reconstruct_library.ML\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    84
ML "open TPTP_Reconstruct_Library"
69605
a96320074298 isabelle update -u path_cartouches;
wenzelm
parents: 69597
diff changeset
    85
ML_file \<open>TPTP_Parser/tptp_reconstruct.ML\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    86
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    87
(*FIXME fudge*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    88
declare [[
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    89
  blast_depth_limit = 10,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    90
  unify_search_bound = 5
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    91
]]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    92
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    93
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    94
section "Proof reconstruction"
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
    95
text \<open>There are two parts to proof reconstruction:
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    96
\begin{itemize}
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    97
  \item interpreting the inferences
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    98
  \item building the skeleton, which indicates how to compose
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
    99
    individual inferences into subproofs, and then compose the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   100
    subproofs to give the proof).
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   101
\end{itemize}
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   102
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   103
One step detects unsound inferences, and the other step detects
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   104
unsound composition of inferences.  The two parts can be weakly
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   105
coupled. They rely on a "proof index" which maps nodes to the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   106
inference information. This information consists of the (usually
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   107
prover-specific) name of the inference step, and the Isabelle
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   108
formalisation of the inference as a term. The inference interpretation
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   109
then maps these terms into meta-theorems, and the skeleton is used to
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   110
compose the inference-level steps into a proof.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   111
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   112
Leo2 operates on conjunctions of clauses. Each Leo2 inference has the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   113
following form, where Cx are clauses:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   114
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   115
           C1 && ... && Cn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   116
          -----------------
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   117
          C'1 && ... && C'n
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   118
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   119
Clauses consist of disjunctions of literals (shown as Px below), and might
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   120
have a prefix of !-bound variables, as shown below.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   121
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   122
  ! X... { P1 || ... || Pn}
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   123
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   124
Literals are usually assigned a polarity, but this isn't always the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   125
case; you can come across inferences looking like this (where A is an
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   126
object-level formula):
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   127
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   128
             F
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   129
          --------
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   130
          F = true
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   131
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   132
The symbol "||" represents literal-level disjunction and "&&" is
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   133
clause-level conjunction. Rules will typically lift formula-level
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   134
conjunctions; for instance the following rule lifts object-level
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   135
disjunction:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   136
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   137
          {    (A | B) = true    || ... } && ...
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   138
          --------------------------------------
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   139
          { A = true || B = true || ... } && ...
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   140
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   141
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   142
Using this setup, efficiency might be gained by only interpreting
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   143
inferences once, merging identical inference steps, and merging
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   144
identical subproofs into single inferences thus avoiding some effort.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   145
We can also attempt to minimising proof search when interpreting
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   146
inferences.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   147
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   148
It is hoped that this setup can target other provers by modifying the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   149
clause representation to fit them, and adapting the inference
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   150
interpretation to handle the rules used by the prover. It should also
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   151
facilitate composing together proofs found by different provers.
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   152
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   153
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   154
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   155
subsection "Instantiation"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   156
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   157
lemma polar_allE [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   158
  "\<lbrakk>(\<forall>x. P x) = True; (P x) = True \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   159
  "\<lbrakk>(\<exists>x. P x) = False; (P x) = False \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   160
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   161
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   162
lemma polar_exE [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   163
  "\<lbrakk>(\<exists>x. P x) = True; \<And>x. (P x) = True \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   164
  "\<lbrakk>(\<forall>x. P x) = False; \<And>x. (P x) = False \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   165
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   166
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   167
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   168
(*This carries out an allE-like rule but on (polarised) literals.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   169
 Instead of yielding a free variable (which is a hell for the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   170
 matcher) it seeks to use one of the subgoals' parameters.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   171
 This ought to be sufficient for emulating extcnf_combined,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   172
 but note that the complexity of the problem can be enormous.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   173
fun inst_parametermatch_tac ctxt thms i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   174
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   175
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   176
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   177
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   178
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   179
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   180
    val parameters =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   181
      if null gls then []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   182
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   183
        rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   184
        |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   185
        |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   186
        |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   187
        |> map fst (*just get the parameter names*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   188
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   189
    if null parameters then no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   190
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   191
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   192
        fun instantiate param =
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59763
diff changeset
   193
          (map (Rule_Insts.eres_inst_tac ctxt [((("x", 0), Position.none), param)] []) thms
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   194
                   |> FIRST')
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   195
        val attempts = map instantiate parameters
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   196
      in
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   197
        (fold (curry (op APPEND')) attempts (K no_tac)) i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   198
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   199
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   200
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   201
(*Attempts to use the polar_allE theorems on a specific subgoal.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   202
fun forall_pos_tac ctxt = inst_parametermatch_tac ctxt @{thms polar_allE}
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   203
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   204
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   205
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   206
(*This is similar to inst_parametermatch_tac, but prefers to
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   207
  match variables having identical names. Logically, this is
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   208
  a hack. But it reduces the complexity of the problem.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   209
fun nominal_inst_parametermatch_tac ctxt thm i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   210
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   211
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   212
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   213
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   214
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   215
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   216
    val parameters =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   217
      if null gls then []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   218
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   219
        rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   220
        |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   221
        |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   222
        |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   223
        |> map fst (*just get the parameter names*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   224
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   225
    if null parameters then no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   226
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   227
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   228
        fun instantiates param =
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59763
diff changeset
   229
          Rule_Insts.eres_inst_tac ctxt [((("x", 0), Position.none), param)] [] thm
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   230
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
   231
        val quantified_var = head_quantified_variable ctxt i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   232
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   233
        if is_none quantified_var then no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   234
        else
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   235
          if member (op =) parameters (the quantified_var |> fst) then
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   236
            instantiates (the quantified_var |> fst) i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   237
          else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   238
            K no_tac i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   239
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   240
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   241
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   242
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   243
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   244
subsection "Prefix massaging"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   245
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   246
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   247
exception NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   248
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   249
(*Get quantifier prefix of the hypothesis and conclusion, reorder
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   250
  the hypothesis' quantifiers to have the ones appearing in the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   251
  conclusion first.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   252
fun canonicalise_qtfr_order ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   253
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   254
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   255
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   256
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   257
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   258
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   259
    if null gls then raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   260
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   261
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   262
        val (params, (hyp_clause, conc_clause)) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   263
          rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   264
          |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   265
          |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   266
          |> apsnd Logic.dest_implies
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   267
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   268
        val (hyp_quants, hyp_body) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   269
          HOLogic.dest_Trueprop hyp_clause
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   270
          |> strip_top_All_vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   271
          |> apfst rev
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   272
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   273
        val conc_quants =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   274
          HOLogic.dest_Trueprop conc_clause
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   275
          |> strip_top_All_vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   276
          |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   277
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   278
        val new_hyp =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   279
          (* fold absfree new_hyp_prefix hyp_body *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   280
          (*HOLogic.list_all*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   281
          fold_rev (fn (v, ty) => fn t => HOLogic.mk_all (v, ty, t))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   282
           (prefix_intersection_list
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   283
             hyp_quants conc_quants)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   284
           hyp_body
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   285
          |> HOLogic.mk_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   286
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   287
         val thm = Goal.prove ctxt [] []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   288
           (Logic.mk_implies (hyp_clause, new_hyp))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   289
           (fn _ =>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   290
              (REPEAT_DETERM (HEADGOAL (resolve_tac ctxt @{thms allI})))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   291
              THEN (REPEAT_DETERM
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   292
                    (HEADGOAL
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   293
                     (nominal_inst_parametermatch_tac ctxt @{thm allE})))
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   294
              THEN HEADGOAL (assume_tac ctxt))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   295
      in
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   296
        dresolve_tac ctxt [thm] i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   297
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   298
    end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   299
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   300
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   301
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   302
subsection "Some general rules and congruences"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   303
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   304
(*this isn't an actual rule used in Leo2, but it seems to be
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   305
  applied implicitly during some Leo2 inferences.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   306
lemma polarise: "P ==> P = True" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   307
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   308
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   309
fun is_polarised t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   310
  (TPTP_Reconstruct.remove_polarity true t; true)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   311
  handle TPTP_Reconstruct.UNPOLARISED _ => false
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   312
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   313
fun polarise_subgoal_hyps ctxt =
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   314
  COND' (SOME #> TERMPRED is_polarised (fn _ => true)) (K no_tac) (dresolve_tac ctxt @{thms polarise})
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   315
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   316
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   317
lemma simp_meta [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   318
  "(A --> B) == (~A | B)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   319
  "(A | B) | C == A | B | C"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   320
  "(A & B) & C == A & B & C"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   321
  "(~ (~ A)) == A"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   322
  (* "(A & B) == (~ (~A | ~B))" *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   323
  "~ (A & B) == (~A | ~B)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   324
  "~(A | B) == (~A) & (~B)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   325
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   326
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   327
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   328
subsection "Emulation of Leo2's inference rules"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   329
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   330
(*this is not included in simp_meta since it would make a mess of the polarities*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   331
lemma expand_iff [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   332
 "((A :: bool) = B) \<equiv> (~ A | B) & (~ B | A)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   333
by (rule eq_reflection, auto)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   334
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   335
lemma polarity_switch [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   336
  "(\<not> P) = True \<Longrightarrow> P = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   337
  "(\<not> P) = False \<Longrightarrow> P = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   338
  "P = False \<Longrightarrow> (\<not> P) = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   339
  "P = True \<Longrightarrow> (\<not> P) = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   340
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   341
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   342
lemma solved_all_splits: "False = True \<Longrightarrow> False" by simp
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   343
ML \<open>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   344
fun solved_all_splits_tac ctxt =
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   345
  TRY (eresolve_tac ctxt @{thms conjE} 1)
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   346
  THEN resolve_tac ctxt @{thms solved_all_splits} 1
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   347
  THEN assume_tac ctxt 1
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   348
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   349
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   350
lemma lots_of_logic_expansions_meta [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   351
  "(((A :: bool) = B) = True) == (((A \<longrightarrow> B) = True) & ((B \<longrightarrow> A) = True))"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   352
  "((A :: bool) = B) = False == (((~A) | B) = False) | (((~B) | A) = False)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   353
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   354
  "((F = G) = True) == (\<forall>x. (F x = G x)) = True"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   355
  "((F = G) = False) == (\<forall>x. (F x = G x)) = False"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   356
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   357
  "(A | B) = True == (A = True) | (B = True)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   358
  "(A & B) = False == (A = False) | (B = False)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   359
  "(A | B) = False == (A = False) & (B = False)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   360
  "(A & B) = True == (A = True) & (B = True)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   361
  "(~ A) = True == A = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   362
  "(~ A) = False == A = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   363
  "~ (A = True) == A = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   364
  "~ (A = False) == A = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   365
by (rule eq_reflection, auto)+
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   366
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   367
(*this is used in extcnf_combined handler*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   368
lemma eq_neg_bool: "((A :: bool) = B) = False ==> ((~ (A | B)) | ~ ((~ A) | (~ B))) = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   369
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   370
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   371
lemma eq_pos_bool:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   372
  "((A :: bool) = B) = True ==> ((~ (A | B)) | ~ (~ A | ~ B)) = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   373
  "(A = B) = True \<Longrightarrow> A = True \<or> B = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   374
  "(A = B) = True \<Longrightarrow> A = False \<or> B = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   375
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   376
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   377
(*next formula is more versatile than
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   378
    "(F = G) = True \<Longrightarrow> \<forall>x. ((F x = G x) = True)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   379
  since it doesn't assume that clause is singleton. After splitqtfr,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   380
  and after applying allI exhaustively to the conclusion, we can
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   381
  use the existing functions to find the "(F x = G x) = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   382
  disjunct in the conclusion*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   383
lemma eq_pos_func: "\<And> x. (F = G) = True \<Longrightarrow> (F x = G x) = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   384
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   385
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   386
(*make sure the conclusion consists of just "False"*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   387
lemma flip:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   388
  "((A = True) ==> False) ==> A = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   389
  "((A = False) ==> False) ==> A = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   390
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   391
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   392
(*FIXME try to use Drule.equal_elim_rule1 directly for this*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   393
lemma equal_elim_rule1: "(A \<equiv> B) \<Longrightarrow> A \<Longrightarrow> B" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   394
lemmas leo2_rules =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   395
 lots_of_logic_expansions_meta[THEN equal_elim_rule1]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   396
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   397
(*FIXME is there any overlap with lots_of_logic_expansions_meta or leo2_rules?*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   398
lemma extuni_bool2 [rule_format]: "(A = B) = False \<Longrightarrow> (A = True) | (B = True)" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   399
lemma extuni_bool1 [rule_format]: "(A = B) = False \<Longrightarrow> (A = False) | (B = False)" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   400
lemma extuni_triv [rule_format]: "(A = A) = False \<Longrightarrow> R" by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   401
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   402
(*Order (of A, B, C, D) matters*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   403
lemma dec_commut_eq [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   404
  "((A = B) = (C = D)) = False \<Longrightarrow> (B = C) = False | (A = D) = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   405
  "((A = B) = (C = D)) = False \<Longrightarrow> (B = D) = False | (A = C) = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   406
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   407
lemma dec_commut_disj [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   408
  "((A \<or> B) = (C \<or> D)) = False \<Longrightarrow> (B = C) = False \<or> (A = D) = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   409
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   410
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   411
lemma extuni_func [rule_format]: "(F = G) = False \<Longrightarrow> (\<forall>X. (F X = G X)) = False" by auto
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   412
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   413
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   414
subsection "Emulation: tactics"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   415
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   416
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   417
(*Instantiate a variable according to the info given in the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   418
  proof annotation. Through this we avoid having to come up
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   419
  with instantiations during reconstruction.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   420
fun bind_tac ctxt prob_name ordered_binds =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   421
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   422
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   423
    fun term_to_string t =
80866
8c67b14fdd48 clarified internal tool output: prefer Pretty.pure_string_of over manipulation of print_mode;
wenzelm
parents: 80849
diff changeset
   424
      Pretty.pure_string_of (Syntax.pretty_term ctxt t)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   425
    val ordered_instances =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   426
      TPTP_Reconstruct.interpret_bindings prob_name thy ordered_binds []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   427
      |> map (snd #> term_to_string)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   428
      |> permute
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   429
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   430
    (*instantiate a list of variables, order matters*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   431
    fun instantiate_vars ctxt vars : tactic =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   432
      map (fn var =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   433
            Rule_Insts.eres_inst_tac ctxt
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59763
diff changeset
   434
             [((("x", 0), Position.none), var)] [] @{thm allE} 1)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   435
          vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   436
      |> EVERY
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   437
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   438
    fun instantiate_tac vars =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   439
      instantiate_vars ctxt vars
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   440
      THEN (HEADGOAL (assume_tac ctxt))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   441
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   442
    HEADGOAL (canonicalise_qtfr_order ctxt)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   443
    THEN (REPEAT_DETERM (HEADGOAL (resolve_tac ctxt @{thms allI})))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   444
    THEN REPEAT_DETERM (HEADGOAL (nominal_inst_parametermatch_tac ctxt @{thm allE}))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   445
    (*now only the variable to instantiate should be left*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   446
    THEN FIRST (map instantiate_tac ordered_instances)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   447
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   448
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   449
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   450
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   451
(*Simplification tactics*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   452
local
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   453
  fun rew_goal_tac thms ctxt i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   454
    rewrite_goal_tac ctxt thms i
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   455
    |> CHANGED
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   456
in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   457
  val expander_animal =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   458
    rew_goal_tac (@{thms simp_meta} @ @{thms lots_of_logic_expansions_meta})
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   459
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   460
  val simper_animal =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   461
    rew_goal_tac @{thms simp_meta}
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   462
end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   463
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   464
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   465
lemma prop_normalise [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   466
  "(A | B) | C == A | B | C"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   467
  "(A & B) & C == A & B & C"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   468
  "A | B == ~(~A & ~B)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   469
  "~~ A == A"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   470
by auto
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   471
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   472
(*i.e., break_conclusion*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   473
fun flip_conclusion_tac ctxt =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   474
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   475
    val default_tac =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   476
      (TRY o CHANGED o (rewrite_goal_tac ctxt @{thms prop_normalise}))
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   477
      THEN' resolve_tac ctxt @{thms notI}
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   478
      THEN' (REPEAT_DETERM o eresolve_tac ctxt @{thms conjE})
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   479
      THEN' (TRY o (expander_animal ctxt))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   480
  in
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58941
diff changeset
   481
    default_tac ORELSE' resolve_tac ctxt @{thms flip}
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   482
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   483
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   484
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   485
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   486
subsection "Skolemisation"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   487
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   488
lemma skolemise [rule_format]:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   489
  "\<forall> P. (\<not> (\<forall>x. P x)) \<longrightarrow> \<not> (P (SOME x. ~ P x))"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   490
proof -
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   491
  have "\<And> P. (\<not> (\<forall>x. P x)) \<Longrightarrow> \<not> (P (SOME x. ~ P x))"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   492
  proof -
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   493
    fix P
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   494
    assume ption: "\<not> (\<forall>x. P x)"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   495
    hence a: "\<exists>x. \<not> P x" by force
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   496
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   497
    have hilbert : "\<And>P. (\<exists>x. P x) \<Longrightarrow> (P (SOME x. P x))"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   498
    proof -
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   499
      fix P
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   500
      assume "(\<exists>x. P x)"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   501
      thus "(P (SOME x. P x))"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   502
        apply auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   503
        apply (rule someI)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   504
        apply auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   505
        done
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   506
    qed
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   507
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   508
    from a show "\<not> P (SOME x. \<not> P x)"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   509
    proof -
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   510
      assume "\<exists>x. \<not> P x"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   511
      hence "\<not> P (SOME x. \<not> P x)" by (rule hilbert)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   512
      thus ?thesis .
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   513
    qed
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   514
  qed
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   515
  thus ?thesis by blast
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   516
qed
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   517
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   518
lemma polar_skolemise [rule_format]:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   519
  "\<forall>P. (\<forall>x. P x) = False \<longrightarrow> (P (SOME x. \<not> P x)) = False"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   520
proof -
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   521
  have "\<And>P. (\<forall>x. P x) = False \<Longrightarrow> (P (SOME x. \<not> P x)) = False"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   522
  proof -
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   523
    fix P
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   524
    assume ption: "(\<forall>x. P x) = False"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   525
    hence "\<not> (\<forall>x. P x)" by force
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   526
    hence "\<not> All P" by force
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   527
    hence "\<not> (P (SOME x. \<not> P x))" by (rule skolemise)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   528
    thus "(P (SOME x. \<not> P x)) = False" by force
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   529
  qed
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   530
  thus ?thesis by blast
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   531
qed
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   532
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   533
lemma leo2_skolemise [rule_format]:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   534
  "\<forall>P sk. (\<forall>x. P x) = False \<longrightarrow> (sk = (SOME x. \<not> P x)) \<longrightarrow> (P sk) = False"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   535
by (clarify, rule polar_skolemise)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   536
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   537
lemma lift_forall [rule_format]:
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   538
  "\<And>x. (\<forall>x. A x) = True \<Longrightarrow> (A x) = True"
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   539
  "\<And>x. (\<exists>x. A x) = False \<Longrightarrow> (A x) = False"
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   540
by auto
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   541
lemma lift_exists [rule_format]:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   542
  "\<lbrakk>(All P) = False; sk = (SOME x. \<not> P x)\<rbrakk> \<Longrightarrow> P sk = False"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   543
  "\<lbrakk>(Ex P) = True; sk = (SOME x. P x)\<rbrakk> \<Longrightarrow> P sk = True"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   544
apply (drule polar_skolemise, simp)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   545
apply (simp, drule someI_ex, simp)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   546
done
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   547
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   548
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   549
(*FIXME LHS should be constant. Currently allow variables for testing. Probably should still allow Vars (but not Frees) since they'll act as intermediate values*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   550
fun conc_is_skolem_def t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   551
  case t of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   552
      Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t' $ (Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, _) $ _) =>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   553
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   554
        val (h, args) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   555
          strip_comb t'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   556
          |> apfst (strip_abs #> snd #> strip_comb #> fst)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   557
        val h_property =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   558
          is_Free h orelse
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   559
          is_Var h orelse
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   560
          (is_Const h
80636
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 78727
diff changeset
   561
           andalso (dest_Const_name h <> dest_Const_name \<^term>\<open>HOL.Ex\<close>)
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 78727
diff changeset
   562
           andalso (dest_Const_name h <> dest_Const_name \<^term>\<open>HOL.All\<close>)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   563
           andalso (h <> \<^term>\<open>Hilbert_Choice.Eps\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   564
           andalso (h <> \<^term>\<open>HOL.conj\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   565
           andalso (h <> \<^term>\<open>HOL.disj\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   566
           andalso (h <> \<^term>\<open>HOL.eq\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   567
           andalso (h <> \<^term>\<open>HOL.implies\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   568
           andalso (h <> \<^term>\<open>HOL.The\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   569
           andalso (h <> \<^term>\<open>HOL.Ex1\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   570
           andalso (h <> \<^term>\<open>HOL.Not\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   571
           andalso (h <> \<^term>\<open>HOL.iff\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   572
           andalso (h <> \<^term>\<open>HOL.not_equal\<close>))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   573
        val args_property =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   574
          fold (fn t => fn b =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   575
           b andalso is_Free t) args true
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   576
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   577
        h_property andalso args_property
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   578
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   579
    | _ => false
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   580
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   581
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   582
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   583
(*Hack used to detect if a Skolem definition, with an LHS Var, has had the LHS instantiated into an unacceptable term.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   584
fun conc_is_bad_skolem_def t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   585
  case t of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   586
      Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t' $ (Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, _) $ _) =>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   587
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   588
        val (h, args) = strip_comb t'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   589
        val const_h_test =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   590
          if is_Const h then
80636
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 78727
diff changeset
   591
            (dest_Const_name h = dest_Const_name \<^term>\<open>HOL.Ex\<close>)
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 78727
diff changeset
   592
             orelse (dest_Const_name h = dest_Const_name \<^term>\<open>HOL.All\<close>)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   593
             orelse (h = \<^term>\<open>Hilbert_Choice.Eps\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   594
             orelse (h = \<^term>\<open>HOL.conj\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   595
             orelse (h = \<^term>\<open>HOL.disj\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   596
             orelse (h = \<^term>\<open>HOL.eq\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   597
             orelse (h = \<^term>\<open>HOL.implies\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   598
             orelse (h = \<^term>\<open>HOL.The\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   599
             orelse (h = \<^term>\<open>HOL.Ex1\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   600
             orelse (h = \<^term>\<open>HOL.Not\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   601
             orelse (h = \<^term>\<open>HOL.iff\<close>)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   602
             orelse (h = \<^term>\<open>HOL.not_equal\<close>)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   603
          else true
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   604
        val h_property =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   605
          not (is_Free h) andalso
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   606
          not (is_Var h) andalso
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   607
          const_h_test
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   608
        val args_property =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   609
          fold (fn t => fn b =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   610
           b andalso is_Free t) args true
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   611
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   612
        h_property andalso args_property
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   613
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   614
    | _ => false
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   615
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   616
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   617
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   618
fun get_skolem_conc t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   619
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   620
    val t' =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   621
      strip_top_all_vars [] t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   622
      |> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   623
      |> try_dest_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   624
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   625
    case t' of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   626
        Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t' $ (Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, _) $ _) => SOME t'
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   627
      | _ => NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   628
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   629
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   630
fun get_skolem_conc_const t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   631
  lift_option
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   632
   (fn t' =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   633
     head_of t'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   634
     |> strip_abs_body
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   635
     |> head_of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   636
     |> dest_Const)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   637
   (get_skolem_conc t)
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   638
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   639
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   640
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   641
Technique for handling quantifiers:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   642
  Principles:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   643
  * allE should always match with a !!
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   644
  * exE should match with a constant,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   645
     or bind a fresh !! -- currently not doing the latter since it never seems to arised in normal Leo2 proofs.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   646
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   647
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   648
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   649
fun forall_neg_tac candidate_consts ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   650
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   651
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   652
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   653
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   654
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   655
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   656
    val parameters =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   657
      if null gls then ""
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   658
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   659
        rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   660
        |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   661
        |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   662
        |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   663
        |> map fst (*just get the parameter names*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   664
        |> (fn l =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   665
              if null l then ""
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   666
              else
80910
406a85a25189 clarified signature: more explicit operations;
wenzelm
parents: 80866
diff changeset
   667
                implode_space l
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   668
                |> pair " "
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   669
                |> (op ^))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   670
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   671
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   672
    if null gls orelse null candidate_consts then no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   673
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   674
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   675
        fun instantiate const_name =
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59763
diff changeset
   676
          Rule_Insts.dres_inst_tac ctxt [((("sk", 0), Position.none), const_name ^ parameters)] []
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59639
diff changeset
   677
            @{thm leo2_skolemise}
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   678
        val attempts = map instantiate candidate_consts
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   679
      in
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   680
        (fold (curry (op APPEND')) attempts (K no_tac)) i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   681
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   682
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   683
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   684
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   685
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   686
exception SKOLEM_DEF of term (*The tactic wasn't pointed at a skolem definition*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   687
exception NO_SKOLEM_DEF of (*skolem const name*)string * Binding.binding * term (*The tactic could not find a skolem definition in the theory*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   688
fun absorb_skolem_def ctxt prob_name_opt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   689
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   690
    val thy = Proof_Context.theory_of ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   691
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   692
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   693
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   694
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   695
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   696
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   697
    val conclusion =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   698
      if null gls then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   699
        (*this should never be thrown*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   700
        raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   701
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   702
        rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   703
        |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   704
        |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   705
        |> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   706
        |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   707
        |> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   708
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   709
    fun skolem_const_info_of t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   710
      case t of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   711
          Const (\<^const_name>\<open>HOL.Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t' $ (Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, _) $ _)) =>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   712
          head_of t'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   713
          |> strip_abs_body (*since in general might have a skolem term, so we want to rip out the prefixing lambdas to get to the constant (which should be at head position)*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   714
          |> head_of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   715
          |> dest_Const
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   716
        | _ => raise SKOLEM_DEF t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   717
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   718
    val const_name =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   719
      skolem_const_info_of conclusion
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   720
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   721
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   722
    val def_name = const_name ^ "_def"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   723
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   724
    val bnd_def = (*FIXME consts*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   725
      const_name
56220
4c43a2881b25 more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents: 55597
diff changeset
   726
      |> Long_Name.implode o tl o Long_Name.explode (*FIXME hack to drop theory-name prefix*)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   727
      |> Binding.qualified_name
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   728
      |> Binding.suffix_name "_def"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   729
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   730
    val bnd_name =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   731
      case prob_name_opt of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   732
          NONE => bnd_def
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   733
        | SOME prob_name =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   734
(*            Binding.qualify false
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   735
             (TPTP_Problem_Name.mangle_problem_name prob_name)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   736
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   737
             bnd_def
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   738
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   739
    val thm =
59882
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   740
      (case try (Thm.axiom thy) def_name of
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   741
        SOME thm => thm
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   742
      | NONE =>
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   743
          if is_none prob_name_opt then
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   744
            (*This mode is for testing, so we can be a bit
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   745
              looser with theories*)
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   746
            (* FIXME bad theory context!? *)
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   747
            Thm.add_axiom_global (bnd_name, conclusion) thy
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   748
            |> fst |> snd
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   749
          else
ada832308efe tuned -- avoid exotic Name_Space.defined_entry;
wenzelm
parents: 59858
diff changeset
   750
            raise (NO_SKOLEM_DEF (def_name, bnd_name, conclusion)))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   751
  in
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   752
    resolve_tac ctxt [Drule.export_without_context thm] i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   753
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   754
  handle SKOLEM_DEF _ => no_tac st
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   755
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   756
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   757
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   758
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   759
In current system, there should only be 2 subgoals: the one where
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   760
the skolem definition is being built (with a Var in the LHS), and the other subgoal using Var.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   761
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   762
(*arity must be greater than 0. if arity=0 then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   763
  there's no need to use this expensive matching.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   764
fun find_skolem_term ctxt consts_candidate arity = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   765
  let
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   766
    val _ = \<^assert> (arity > 0)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   767
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   768
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   769
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   770
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   771
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   772
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   773
    (*extract the conclusion of each subgoal*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   774
    val conclusions =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   775
      if null gls then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   776
        raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   777
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   778
        map (strip_top_all_vars [] #> snd #> Logic.strip_horn #> snd) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   779
        (*Remove skolem-definition conclusion, to avoid wasting time analysing it*)
58412
f65f11f4854c more standard Isabelle/ML operations;
wenzelm
parents: 58411
diff changeset
   780
        |> filter (try_dest_Trueprop #> conc_is_skolem_def #> not)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   781
        (*There should only be a single goal*) (*FIXME this might not always be the case, in practice*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   782
        (* |> tap (fn x => @{assert} (is_some (try the_single x))) *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   783
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   784
    (*look for subterms headed by a skolem constant, and whose
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   785
      arguments are all parameter Vars*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   786
    fun get_skolem_terms args (acc : term list) t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   787
      case t of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   788
          (c as Const _) $ (v as Free _) =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   789
            if c = consts_candidate andalso
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   790
             arity = length args + 1 then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   791
              (list_comb (c, v :: args)) :: acc
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   792
            else acc
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   793
        | t1 $ (v as Free _) =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   794
            get_skolem_terms (v :: args) acc t1 @
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   795
             get_skolem_terms [] acc t1
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   796
        | t1 $ t2 =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   797
            get_skolem_terms [] acc t1 @
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   798
             get_skolem_terms [] acc t2
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   799
        | Abs (_, _, t') => get_skolem_terms [] acc t'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   800
        | _ => acc
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   801
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   802
    map (strip_top_All_vars #> snd) conclusions
58411
wenzelm
parents: 57773
diff changeset
   803
    |> maps (get_skolem_terms [] [])
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   804
    |> distinct (op =)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   805
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   806
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   807
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   808
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   809
fun instantiate_skols ctxt consts_candidates i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   810
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   811
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
   812
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   813
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   814
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   815
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   816
    val (params, conclusion) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   817
      if null gls then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   818
        raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   819
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   820
        rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   821
        |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   822
        |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   823
        |> apsnd (Logic.strip_horn #> snd)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   824
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   825
    fun skolem_const_info_of t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   826
      case t of
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   827
          Const (\<^const_name>\<open>HOL.Trueprop\<close>, _) $ (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ lhs $ (Const (\<^const_name>\<open>Hilbert_Choice.Eps\<close>, _) $ rhs)) =>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   828
          let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   829
            (*the parameters we will concern ourselves with*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   830
            val params' =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   831
              Term.add_frees lhs []
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   832
              |> distinct (op =)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   833
            (*check to make sure that params' <= params*)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   834
            val _ = \<^assert> (forall (member (op =) params) params')
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   835
            val skolem_const_ty =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   836
              let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   837
                val (skolem_const_prety, no_params) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   838
                  Term.strip_comb lhs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   839
                  |> apfst (dest_Var #> snd) (*head of lhs consists of a logical variable. we just want its type.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   840
                  |> apsnd length
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   841
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   842
                val _ = \<^assert> (length params = no_params)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   843
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   844
                (*get value type of a function type after n arguments have been supplied*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   845
                fun get_val_ty n ty =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   846
                  if n = 0 then ty
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   847
                  else get_val_ty (n - 1) (dest_funT ty |> snd)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   848
              in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   849
                get_val_ty no_params skolem_const_prety
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   850
              end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   851
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   852
          in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   853
            (skolem_const_ty, params')
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   854
          end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   855
        | _ => raise (SKOLEM_DEF t)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   856
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   857
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   858
find skolem const candidates which, after applying distinct members of params' we end up with, give us something of type skolem_const_ty.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   859
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   860
given a candidate's type, skolem_const_ty, and params', we get some pemutations of params' (i.e. the order in which they can be given to the candidate in order to get skolem_const_ty). If the list of permutations is empty, then we cannot use that candidate.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   861
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   862
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   863
only returns a single matching -- since terms are linear, and variable arguments are Vars, order shouldn't matter, so we can ignore permutations.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   864
doesn't work with polymorphism (for which we'd need to use type unification) -- this is OK since no terms should be polymorphic, since Leo2 proofs aren't.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   865
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   866
    fun use_candidate target_ty params acc cur_ty =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   867
      if null params then
58941
f09dd46352ba more direct type equality;
wenzelm
parents: 58412
diff changeset
   868
        if cur_ty = target_ty then
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   869
          SOME (rev acc)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   870
        else NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   871
      else
78727
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   872
        \<^try>\<open>
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   873
          let
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   874
            val (arg_ty, val_ty) = Term.dest_funT cur_ty
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   875
            (*now find a param of type arg_ty*)
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   876
            val (candidate_param, params') =
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   877
              find_and_remove (snd #> pair arg_ty #> (op =)) params
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   878
          in
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   879
            use_candidate target_ty params' (candidate_param :: acc) val_ty
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   880
          end
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   881
          catch TYPE ("dest_funT", _, _) => NONE  (* FIXME fragile *)
62243
dd22d2423047 clarified exception handling;
wenzelm
parents: 60754
diff changeset
   882
             | _ => NONE  (* FIXME avoid catch-all handler *)
78727
1b052426a2b7 avoid accidental 'handle' of interrupts;
wenzelm
parents: 77879
diff changeset
   883
        \<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   884
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   885
    val (skolem_const_ty, params') = skolem_const_info_of conclusion
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   886
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   887
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   888
For each candidate, build a term and pass it to Thm.instantiate, whic in turn is chained with PRIMITIVE to give us this_tactic.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   889
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   890
Big picture:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   891
  we run the following:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   892
    drule leo2_skolemise THEN' this_tactic
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   893
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   894
NOTE: remember to APPEND' instead of ORELSE' the two tactics relating to skolemisation
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   895
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   896
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   897
    val filtered_candidates =
80636
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 78727
diff changeset
   898
      map (dest_Const_type #> use_candidate skolem_const_ty params' [])
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   899
       consts_candidates (* prefiltered_candidates *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   900
      |> pair consts_candidates (* prefiltered_candidates *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   901
      |> ListPair.zip
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   902
      |> filter (snd #> is_none #> not)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   903
      |> map (apsnd the)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   904
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   905
    val skolem_terms =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   906
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   907
        fun make_result_t (t, args) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   908
          (* list_comb (t, map Free args) *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   909
          if length args > 0 then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   910
            hd (find_skolem_term ctxt t (length args) st)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   911
          else t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   912
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   913
        map make_result_t filtered_candidates
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   914
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   915
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   916
    (*prefix a skolem term with bindings for the parameters*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   917
    (* val contextualise = fold absdummy (map snd params) *)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   918
    val contextualise = fold absfree params
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   919
59639
f596ed647018 clarified context;
wenzelm
parents: 59621
diff changeset
   920
    val skolem_cts = map (contextualise #> Thm.cterm_of ctxt) skolem_terms
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   921
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   922
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   923
(*now the instantiation code*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   924
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   925
    (*there should only be one Var -- that is from the previous application of drule leo2_skolemise. We look for it at the head position in some equation at a conclusion of a subgoal.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   926
    val var_opt =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   927
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   928
        val pre_var =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   929
          gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   930
          |> map
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   931
              (strip_top_all_vars [] #> snd #>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   932
               Logic.strip_horn #> snd #>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   933
               get_skolem_conc)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   934
          |> switch (fold (fn x => fn l => if is_some x then the x :: l else l)) []
58411
wenzelm
parents: 57773
diff changeset
   935
          |> maps (switch Term.add_vars [])
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   936
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   937
        fun make_var pre_var =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   938
          the_single pre_var
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   939
          |> Var
59639
f596ed647018 clarified context;
wenzelm
parents: 59621
diff changeset
   940
          |> Thm.cterm_of ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   941
          |> SOME
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   942
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   943
        if null pre_var then NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   944
        else make_var pre_var
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   945
     end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   946
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   947
    fun instantiate_tac from to =
77879
wenzelm
parents: 74282
diff changeset
   948
      PRIMITIVE (Thm.instantiate (TVars.empty, Vars.make1 (from, to)))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   949
59760
wenzelm
parents: 59755
diff changeset
   950
    val tactic =
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   951
      if is_none var_opt then no_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   952
      else
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
   953
        fold (curry (op APPEND))
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60319
diff changeset
   954
          (map (instantiate_tac (dest_Var (Thm.term_of (the var_opt)))) skolem_cts) no_tac
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   955
  in
59760
wenzelm
parents: 59755
diff changeset
   956
    tactic st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   957
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   958
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   959
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   960
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   961
fun new_skolem_tac ctxt consts_candidates =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   962
  let
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   963
    fun tac thm =
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   964
      dresolve_tac ctxt [thm]
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   965
      THEN' instantiate_skols ctxt consts_candidates
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   966
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   967
    if null consts_candidates then K no_tac
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
   968
    else FIRST' (map tac @{thms lift_exists})
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   969
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   970
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   971
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   972
(*
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   973
need a tactic to expand "? x . P" to "~ ! x. ~ P"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   974
*)
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   975
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   976
fun ex_expander_tac ctxt i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   977
   let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   978
     val simpset =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   979
       empty_simpset ctxt (*NOTE for some reason, Bind exception gets raised if ctxt's simpset isn't emptied*)
67613
ce654b0e6d69 more symbols;
wenzelm
parents: 67405
diff changeset
   980
       |> Simplifier.add_simp @{lemma "Ex P == (\<not> (\<forall>x. \<not> P x))" by auto}
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   981
   in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   982
     CHANGED (asm_full_simp_tac simpset i)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   983
   end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   984
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   985
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   986
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   987
subsubsection "extuni_dec"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   988
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
   989
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   990
(*n-ary decomposition. Code is based on the n-ary arg_cong generator*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   991
fun extuni_dec_n ctxt arity =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   992
  let
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   993
    val _ = \<^assert> (arity > 0)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   994
    val is =
67404
e128ab544996 proper infix;
wenzelm
parents: 67399
diff changeset
   995
      1 upto arity
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   996
      |> map Int.toString
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   997
    val arg_tys = map (fn i => TFree ("arg" ^ i ^ "_ty", \<^sort>\<open>type\<close>)) is
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
   998
    val res_ty = TFree ("res" ^ "_ty", \<^sort>\<open>type\<close>)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
   999
    val f_ty = arg_tys ---> res_ty
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1000
    val f = Free ("f", f_ty)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1001
    val xs = map (fn i =>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1002
      Free ("x" ^ i, TFree ("arg" ^ i ^ "_ty", \<^sort>\<open>type\<close>))) is
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1003
    (*FIXME DRY principle*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1004
    val ys = map (fn i =>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1005
      Free ("y" ^ i, TFree ("arg" ^ i ^ "_ty", \<^sort>\<open>type\<close>))) is
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1006
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1007
    val hyp_lhs = list_comb (f, xs)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1008
    val hyp_rhs = list_comb (f, ys)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1009
    val hyp_eq =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1010
      HOLogic.eq_const res_ty $ hyp_lhs $ hyp_rhs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1011
    val hyp =
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1012
      HOLogic.eq_const HOLogic.boolT $ hyp_eq $ \<^term>\<open>False\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1013
      |> HOLogic.mk_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1014
    fun conc_eq i =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1015
      let
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1016
        val ty = TFree ("arg" ^ i ^ "_ty", \<^sort>\<open>type\<close>)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1017
        val x = Free ("x" ^ i, ty)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1018
        val y = Free ("y" ^ i, ty)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1019
        val eq = HOLogic.eq_const ty $ x $ y
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1020
      in
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1021
        HOLogic.eq_const HOLogic.boolT $ eq $ \<^term>\<open>False\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1022
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1023
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1024
    val conc_disjs = map conc_eq is
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1025
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1026
    val conc =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1027
      if length conc_disjs = 1 then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1028
        the_single conc_disjs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1029
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1030
        fold
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1031
         (fn t => fn t_conc => HOLogic.mk_disj (t_conc, t))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1032
         (tl conc_disjs) (hd conc_disjs)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1033
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1034
    val t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1035
      Logic.mk_implies (hyp, HOLogic.mk_Trueprop conc)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1036
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1037
    Goal.prove ctxt [] [] t (fn _ => auto_tac ctxt)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1038
    |> Drule.export_without_context
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1039
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1040
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1041
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1042
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1043
(*Determine the arity of a function which the "dec"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1044
  unification rule is about to be applied.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1045
  NOTE:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1046
    * Assumes that there is a single hypothesis
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1047
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1048
fun find_dec_arity i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1049
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1050
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1051
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1052
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1053
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1054
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1055
    if null gls then raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1056
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1057
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1058
        val (params, (literal, conc_clause)) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1059
          rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1060
          |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1061
          |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1062
          |> apsnd Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1063
          |> apsnd (apfst the_single)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1064
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1065
        val get_ty =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1066
          HOLogic.dest_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1067
          #> strip_top_All_vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1068
          #> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1069
          #> HOLogic.dest_eq (*polarity's "="*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1070
          #> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1071
          #> HOLogic.dest_eq (*the unification constraint's "="*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1072
          #> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1073
          #> head_of
80636
4041e7c8059d tuned: more explicit dest_Const_name and dest_Const_type;
wenzelm
parents: 78727
diff changeset
  1074
          #> dest_Const_type
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1075
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1076
       fun arity_of ty =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1077
         let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1078
           val (_, res_ty) = dest_funT ty
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1079
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1080
         in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1081
           1 + arity_of res_ty
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1082
         end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1083
         handle (TYPE ("dest_funT", _, _)) => 0
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1084
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1085
      in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1086
        arity_of (get_ty literal)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1087
      end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1088
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1089
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1090
(*given an inference, it returns the parameters (i.e., we've already matched the leading & shared quantification in the hypothesis & conclusion clauses), and the "raw" inference*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1091
fun breakdown_inference i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1092
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1093
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1094
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1095
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1096
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1097
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1098
    if null gls then raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1099
    else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1100
      rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1101
      |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1102
      |> strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1103
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1104
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1105
(*build a custom elimination rule for extuni_dec, and instantiate it to match a specific subgoal*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1106
fun extuni_dec_elim_rule ctxt arity i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1107
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1108
    val rule = extuni_dec_n ctxt arity
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1109
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1110
    val rule_hyp =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1111
      Thm.prop_of rule
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1112
      |> Logic.dest_implies
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1113
      |> fst (*assuming that rule has single hypothesis*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1114
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1115
    (*having run break_hypothesis earlier, we know that the hypothesis
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1116
      now consists of a single literal. We can (and should)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1117
      disregard the conclusion, since it hasn't been "broken",
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1118
      and it might include some unwanted literals -- the latter
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1119
      could cause "diff" to fail (since they won't agree with the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1120
      rule we have generated.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1121
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1122
    val inference_hyp =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1123
      snd (breakdown_inference i st)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1124
      |> Logic.dest_implies
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1125
      |> fst (*assuming that inference has single hypothesis,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1126
               as explained above.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1127
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1128
    TPTP_Reconstruct_Library.diff_and_instantiate ctxt rule rule_hyp inference_hyp
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1129
  end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1130
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1131
fun extuni_dec_tac ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1132
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1133
    val arity = find_dec_arity i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1134
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1135
    fun elim_tac i st =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1136
      let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1137
        val rule =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1138
          extuni_dec_elim_rule ctxt arity i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1139
          (*in case we itroduced free variables during
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1140
            instantiation, we generalise the rule to make
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1141
            those free variables into logical variables.*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1142
          |> Thm.forall_intr_frees
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1143
          |> Drule.export_without_context
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1144
      in dresolve_tac ctxt [rule] i st end
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1145
      handle NO_GOALS => no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1146
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1147
    fun closure tac =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1148
     (*batter fails if there's no toplevel disjunction in the
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1149
       hypothesis, so we also try atac*)
59533
e9ffe89a20a4 proper context;
wenzelm
parents: 59498
diff changeset
  1150
      SOLVE o (tac THEN' (batter_tac ctxt ORELSE' assume_tac ctxt))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1151
    val search_tac =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1152
      ASAP
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1153
        (resolve_tac ctxt @{thms disjI1} APPEND' resolve_tac ctxt @{thms disjI2})
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1154
        (FIRST' (map closure
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 58941
diff changeset
  1155
                  [dresolve_tac ctxt @{thms dec_commut_eq},
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1156
                   dresolve_tac ctxt @{thms dec_commut_disj},
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1157
                   elim_tac]))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1158
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1159
    (CHANGED o search_tac) i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1160
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1161
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1162
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1163
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1164
subsubsection "standard_cnf"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1165
(*Given a standard_cnf inference, normalise it
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1166
     e.g. ((A & B) & C \<longrightarrow> D & E \<longrightarrow> F \<longrightarrow> G) = False
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1167
     is changed to
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1168
          (A & B & C & D & E & F \<longrightarrow> G) = False
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1169
 then custom-build a metatheorem which validates this:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1170
          (A & B & C & D & E & F \<longrightarrow> G) = False
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1171
       -------------------------------------------
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1172
          (A = True) & (B = True) & (C = True) &
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1173
          (D = True) & (E = True) & (F = True) & (G = False)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1174
 and apply this metatheorem.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1175
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1176
There aren't any "positive" standard_cnfs in Leo2's calculus:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1177
  e.g.,  "(A \<longrightarrow> B) = True \<Longrightarrow> A = False | (A = True & B = True)"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1178
since "standard_cnf" seems to be applied at the preprocessing
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1179
stage, together with splitting.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1180
*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1181
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1182
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1183
(*Conjunctive counterparts to Term.disjuncts_aux and Term.disjuncts*)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1184
fun conjuncts_aux (Const (\<^const_name>\<open>HOL.conj\<close>, _) $ t $ t') conjs =
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1185
     conjuncts_aux t (conjuncts_aux t' conjs)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1186
  | conjuncts_aux t conjs = t :: conjs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1187
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1188
fun conjuncts t = conjuncts_aux t []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1189
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1190
(*HOL equivalent of Logic.strip_horn*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1191
local
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1192
  fun imp_strip_horn' acc (Const (\<^const_name>\<open>HOL.implies\<close>, _) $ A $ B) =
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1193
        imp_strip_horn' (A :: acc) B
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1194
    | imp_strip_horn' acc t = (acc, t)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1195
in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1196
  fun imp_strip_horn t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1197
    imp_strip_horn' [] t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1198
    |> apfst rev
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1199
end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1200
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1201
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1202
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1203
(*Returns whether the antecedents are separated by conjunctions
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1204
  or implications; the number of antecedents; and the polarity
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1205
  of the original clause -- I think this will always be "false".*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1206
fun standard_cnf_type ctxt i : thm -> (TPTP_Reconstruct.formula_kind * int * bool) option = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1207
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1208
    val gls =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59533
diff changeset
  1209
      Thm.prop_of st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1210
      |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1211
      |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1212
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1213
    val hypos =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1214
      if null gls then raise NO_GOALS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1215
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1216
        rpair (i - 1) gls
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1217
        |> uncurry nth
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1218
        |> TPTP_Reconstruct.strip_top_all_vars []
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1219
        |> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1220
        |> Logic.strip_horn
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1221
        |> fst
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1222
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1223
    (*hypothesis clause should be singleton*)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1224
    val _ = \<^assert> (length hypos = 1)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1225
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1226
    val (t, pol) = the_single hypos
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1227
      |> try_dest_Trueprop
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1228
      |> TPTP_Reconstruct.strip_top_All_vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1229
      |> snd
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1230
      |> TPTP_Reconstruct.remove_polarity true
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1231
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1232
    (*literal is negative*)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1233
    val _ = \<^assert> (not pol)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1234
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1235
    val (antes, conc) = imp_strip_horn t
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1236
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1237
    val (ante_type, antes') =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1238
      if length antes = 1 then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1239
        let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1240
          val conjunctive_antes =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1241
            the_single antes
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1242
            |> conjuncts
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1243
        in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1244
          if length conjunctive_antes > 1 then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1245
            (TPTP_Reconstruct.Conjunctive NONE,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1246
             conjunctive_antes)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1247
          else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1248
            (TPTP_Reconstruct.Implicational NONE,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1249
             antes)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1250
        end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1251
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1252
        (TPTP_Reconstruct.Implicational NONE,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1253
         antes)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1254
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1255
    if null antes then NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1256
    else SOME (ante_type, length antes', pol)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1257
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1258
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1259
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1260
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1261
(*Given a certain standard_cnf type, build a metatheorem that would
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1262
  validate it*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1263
fun mk_standard_cnf ctxt kind arity =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1264
  let
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1265
    val _ = \<^assert> (arity > 0)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1266
    val vars =
67404
e128ab544996 proper infix;
wenzelm
parents: 67399
diff changeset
  1267
      1 upto (arity + 1)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1268
      |> map (fn i => Free ("x" ^ Int.toString i, HOLogic.boolT))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1269
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1270
    val consequent = hd vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1271
    val antecedents = tl vars
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1272
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1273
    val conc =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1274
      fold
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1275
       (curry HOLogic.mk_conj)
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1276
       (map (fn var => HOLogic.mk_eq (var, \<^term>\<open>True\<close>)) antecedents)
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1277
       (HOLogic.mk_eq (consequent, \<^term>\<open>False\<close>))
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1278
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1279
    val pre_hyp =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1280
      case kind of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1281
          TPTP_Reconstruct.Conjunctive NONE =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1282
            curry HOLogic.mk_imp
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1283
             (if length antecedents = 1 then the_single antecedents
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1284
              else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1285
                fold (curry HOLogic.mk_conj) (tl antecedents) (hd antecedents))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1286
             (hd vars)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1287
        | TPTP_Reconstruct.Implicational NONE =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1288
            fold (curry HOLogic.mk_imp) antecedents consequent
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1289
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1290
    val hyp = HOLogic.mk_eq (pre_hyp, \<^term>\<open>False\<close>)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1291
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1292
    val t =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1293
      Logic.mk_implies (HOLogic.mk_Trueprop  hyp, HOLogic.mk_Trueprop conc)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1294
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1295
    Goal.prove ctxt [] [] t (fn _ => HEADGOAL (blast_tac ctxt))
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1296
    |> Drule.export_without_context
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1297
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1298
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1299
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1300
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1301
(*Applies a d-tactic, then breaks it up conjunctively.
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1302
  This can be used to transform subgoals as follows:
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1303
     (A \<longrightarrow> B) = False  \<Longrightarrow> R
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1304
              |
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1305
              v
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1306
  \<lbrakk>A = True; B = False\<rbrakk> \<Longrightarrow> R
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1307
*)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1308
fun weak_conj_tac ctxt drule =
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1309
  dresolve_tac ctxt [drule] THEN'
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1310
  (REPEAT_DETERM o eresolve_tac ctxt @{thms conjE})
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1311
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1312
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1313
ML \<open>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1314
fun uncurry_lit_neg_tac ctxt =
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1315
  REPEAT_DETERM o
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1316
    dresolve_tac ctxt [@{lemma "(A \<longrightarrow> B \<longrightarrow> C) = False \<Longrightarrow> (A & B \<longrightarrow> C) = False" by auto}]
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1317
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1318
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1319
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1320
fun standard_cnf_tac ctxt i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1321
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1322
    fun core_tactic i = fn st =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1323
      case standard_cnf_type ctxt i st of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1324
          NONE => no_tac st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1325
        | SOME (kind, arity, _) =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1326
            let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1327
              val rule = mk_standard_cnf ctxt kind arity;
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1328
            in
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1329
              (weak_conj_tac ctxt rule THEN' assume_tac ctxt) i st
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1330
            end
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1331
  in
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1332
    (uncurry_lit_neg_tac ctxt
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1333
     THEN' TPTP_Reconstruct_Library.reassociate_conjs_tac ctxt
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1334
     THEN' core_tactic) i st
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1335
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1336
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1337
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1338
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1339
subsubsection "Emulator prep"
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1340
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1341
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1342
datatype cleanup_feature =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1343
    RemoveHypothesesFromSkolemDefs
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1344
  | RemoveDuplicates
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1345
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1346
datatype loop_feature =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1347
    Close_Branch
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1348
  | ConjI
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1349
  | King_Cong
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1350
  | Break_Hypotheses
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1351
  | Donkey_Cong (*simper_animal + ex_expander_tac*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1352
  | RemoveRedundantQuantifications
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1353
  | Assumption
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1354
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1355
  (*Closely based on Leo2 calculus*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1356
  | Existential_Free
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1357
  | Existential_Var
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1358
  | Universal
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1359
  | Not_pos
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1360
  | Not_neg
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1361
  | Or_pos
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1362
  | Or_neg
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1363
  | Equal_pos
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1364
  | Equal_neg
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1365
  | Extuni_Bool2
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1366
  | Extuni_Bool1
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1367
  | Extuni_Dec
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1368
  | Extuni_Bind
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1369
  | Extuni_Triv
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1370
  | Extuni_FlexRigid
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1371
  | Extuni_Func
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1372
  | Polarity_switch
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1373
  | Forall_special_pos
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1374
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1375
datatype feature =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1376
    ConstsDiff
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1377
  | StripQuantifiers
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1378
  | Flip_Conclusion
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1379
  | Loop of loop_feature list
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1380
  | LoopOnce of loop_feature list
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1381
  | InnerLoopOnce of loop_feature list
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1382
  | CleanUp of cleanup_feature list
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1383
  | AbsorbSkolemDefs
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1384
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1385
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1386
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1387
fun can_feature x l =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1388
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1389
    fun sublist_of_clean_up el =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1390
      case el of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1391
          CleanUp l'' => SOME l''
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1392
        | _ => NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1393
    fun sublist_of_loop el =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1394
      case el of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1395
          Loop l'' => SOME l''
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1396
        | _ => NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1397
    fun sublist_of_loop_once el =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1398
      case el of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1399
          LoopOnce l'' => SOME l''
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1400
        | _ => NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1401
    fun sublist_of_inner_loop_once el =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1402
      case el of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1403
          InnerLoopOnce l'' => SOME l''
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1404
        | _ => NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1405
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1406
    fun check_sublist sought_sublist opt_list =
58412
f65f11f4854c more standard Isabelle/ML operations;
wenzelm
parents: 58411
diff changeset
  1407
      if forall is_none opt_list then false
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1408
      else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1409
        fold_options opt_list
58411
wenzelm
parents: 57773
diff changeset
  1410
        |> flat
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1411
        |> pair sought_sublist
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1412
        |> subset (op =)
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1413
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1414
    case x of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1415
        CleanUp l' =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1416
          map sublist_of_clean_up l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1417
          |> check_sublist l'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1418
      | Loop l' =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1419
          map sublist_of_loop l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1420
          |> check_sublist l'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1421
      | LoopOnce l' =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1422
          map sublist_of_loop_once l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1423
          |> check_sublist l'
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1424
      | InnerLoopOnce l' =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1425
          map sublist_of_inner_loop_once l
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1426
          |> check_sublist l'
67405
e9ab4ad7bd15 uniform use of Standard ML op-infix -- eliminated warnings;
wenzelm
parents: 67404
diff changeset
  1427
      | _ => exists (curry (op =) x) l
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1428
  end;
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1429
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1430
fun loop_can_feature loop_feats l =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1431
  can_feature (Loop loop_feats) l orelse
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1432
  can_feature (LoopOnce loop_feats) l orelse
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1433
  can_feature (InnerLoopOnce loop_feats) l;
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1434
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1435
\<^assert> (can_feature ConstsDiff [StripQuantifiers, ConstsDiff]);
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1436
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1437
\<^assert>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1438
  (can_feature (CleanUp [RemoveHypothesesFromSkolemDefs])
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1439
    [CleanUp [RemoveHypothesesFromSkolemDefs, RemoveDuplicates]]);
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1440
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1441
\<^assert>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1442
  (can_feature (Loop []) [Loop [Existential_Var]]);
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1443
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1444
\<^assert>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1445
  (not (can_feature (Loop []) [InnerLoopOnce [Existential_Var]]));
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1446
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1447
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1448
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1449
exception NO_LOOP_FEATS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1450
fun get_loop_feats (feats : feature list) =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1451
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1452
    val loop_find =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1453
      fold (fn x => fn loop_feats_acc =>
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1454
        if is_some loop_feats_acc then loop_feats_acc
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1455
        else
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1456
          case x of
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1457
              Loop loop_feats => SOME loop_feats
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1458
            | LoopOnce loop_feats => SOME loop_feats
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1459
            | InnerLoopOnce loop_feats => SOME loop_feats
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1460
            | _ => NONE)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1461
       feats
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1462
       NONE
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1463
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1464
    if is_some loop_find then the loop_find
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1465
    else raise NO_LOOP_FEATS
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1466
  end;
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1467
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 68825
diff changeset
  1468
\<^assert>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1469
  (get_loop_feats [Loop [King_Cong, Break_Hypotheses, Existential_Free, Existential_Var, Universal]] =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1470
   [King_Cong, Break_Hypotheses, Existential_Free, Existential_Var, Universal])
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1471
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1472
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1473
(*use as elim rule to remove premises*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1474
lemma insa_prems: "\<lbrakk>Q; P\<rbrakk> \<Longrightarrow> P" by auto
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1475
ML \<open>
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1476
fun cleanup_skolem_defs ctxt feats =
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1477
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1478
    (*remove hypotheses from skolem defs,
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1479
     after testing that they look like skolem defs*)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1480
    val dehypothesise_skolem_defs =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1481
      COND' (SOME #> TERMPRED (fn _ => true) conc_is_skolem_def)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1482
        (REPEAT_DETERM o eresolve_tac ctxt @{thms insa_prems})
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1483
        (K no_tac)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1484
  in
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1485
    if can_feature (CleanUp [RemoveHypothesesFromSkolemDefs]) feats then
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1486
      ALLGOALS (TRY o dehypothesise_skolem_defs)
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1487
    else all_tac
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1488
  end
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1489
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1490
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1491
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1492
fun remove_duplicates_tac feats =
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1493
  (if can_feature (CleanUp [RemoveDuplicates]) feats then
68825
8207c67d9ef4 clarified signature: do not expose internal operation;
wenzelm
parents: 67613
diff changeset
  1494
     distinct_subgoals_tac
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1495
   else all_tac)
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1496
\<close>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1497
63167
0909deb8059b isabelle update_cartouches -c -t;
wenzelm
parents: 62243
diff changeset
  1498
ML \<open>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1499
(*given a goal state, indicates the skolem constants committed-to in it (i.e. appearing in LHS of a skolem definition)*)
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1500
fun which_skolem_concs_used ctxt = fn st =>
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1501
  let
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1502
    val feats = [CleanUp [RemoveHypothesesFromSkolemDefs, RemoveDuplicates]]
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1503
    val scrubup_tac =
60754
02924903a6fd prefer tactics with explicit context;
wenzelm
parents: 60642
diff changeset
  1504
      cleanup_skolem_defs ctxt feats
55596
928b9f677165 reconstruction framework for LEO-II's TPTP proofs;
sultana
parents:
diff changeset
  1505
      THEN remove_duplicates_tac feats